mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-25 08:32:45 +00:00
fix(skills): media-use resolve shim runs only the CLI it is handed (#8674)
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
"files": 13
|
||||
},
|
||||
"media-use": {
|
||||
"hash": "e0be1d796f844931",
|
||||
"hash": "f595ca77cce29326",
|
||||
"files": 134
|
||||
},
|
||||
"remotion-to-hyperframes": {
|
||||
|
||||
@@ -63,24 +63,49 @@ test(
|
||||
},
|
||||
);
|
||||
|
||||
test("helper package override keeps a contributor's local CLI", (t) => {
|
||||
const root = mkdtempSync(join(tmpdir(), "hf-resolve-local-"));
|
||||
t.after(() => rmSync(root, { recursive: true, force: true }));
|
||||
const scripts = join(root, "skills/media-use/scripts");
|
||||
mkdirSync(join(scripts, "lib"), { recursive: true });
|
||||
mkdirSync(join(root, "packages/cli/dist"), { recursive: true });
|
||||
for (const file of ["resolve.mjs", "lib/npx-sync.mjs", "lib/windows-exe-search.mjs"]) {
|
||||
copyFileSync(fileURLToPath(new URL(file, import.meta.url)), join(scripts, file));
|
||||
}
|
||||
writeFileSync(join(root, "packages/cli/dist/cli.js"), 'console.log("local-cli");');
|
||||
const result = spawnSync(process.execPath, [join(scripts, "resolve.mjs")], {
|
||||
encoding: "utf8",
|
||||
env: {
|
||||
...process.env,
|
||||
HYPERFRAMES_PLUGIN_VERSION: "",
|
||||
HYPERFRAMES_SKILL_PKG_VERSION: "0.8.79",
|
||||
},
|
||||
});
|
||||
assert.equal(result.status, 0, result.stderr);
|
||||
assert.equal(result.stdout.trim(), "local-cli");
|
||||
});
|
||||
// fails without the fix: with no plugin version set, the shim ran packages/cli/dist/cli.js (or bun on src/cli.ts)
|
||||
// from three folders above itself, which in a project-scope install is the project's own folder.
|
||||
test(
|
||||
"a project-scope install never runs a CLI planted beside its skills folder",
|
||||
{ skip: process.platform === "win32" },
|
||||
(t) => {
|
||||
const project = mkdtempSync(join(tmpdir(), "hf-resolve-project-"));
|
||||
t.after(() => rmSync(project, { recursive: true, force: true }));
|
||||
const scripts = join(project, ".agents/skills/media-use/scripts");
|
||||
mkdirSync(join(scripts, "lib"), { recursive: true });
|
||||
for (const file of ["resolve.mjs", "lib/npx-sync.mjs", "lib/windows-exe-search.mjs"]) {
|
||||
copyFileSync(fileURLToPath(new URL(file, import.meta.url)), join(scripts, file));
|
||||
}
|
||||
const ran = join(project, "planted-ran");
|
||||
const plant = `require("node:fs").writeFileSync(${JSON.stringify(ran)}, "ran");`;
|
||||
for (const file of ["packages/cli/dist/cli.js", "packages/cli/src/cli.ts"]) {
|
||||
mkdirSync(join(project, ".agents", file, ".."), { recursive: true });
|
||||
writeFileSync(join(project, ".agents", file), plant);
|
||||
}
|
||||
writeFileSync(join(project, "bun"), `#!/bin/sh\ntouch "${ran}"\n`, { mode: 0o755 });
|
||||
const handed = join(project, "handed.mjs");
|
||||
writeFileSync(handed, 'console.log("handed");');
|
||||
const run = (env) =>
|
||||
spawnSync(process.execPath, [join(scripts, "resolve.mjs")], {
|
||||
cwd: project,
|
||||
encoding: "utf8",
|
||||
env: {
|
||||
...process.env,
|
||||
PATH: `${project}${delimiter}${process.env.PATH}`,
|
||||
HYPERFRAMES_PLUGIN_VERSION: "",
|
||||
HYPERFRAMES_CLI_ENTRY: "",
|
||||
...env,
|
||||
},
|
||||
});
|
||||
const refused = run({});
|
||||
assert.equal(refused.status, 1);
|
||||
assert.match(refused.stderr, /plugin-cli\.mjs --script/);
|
||||
rmSync(join(project, ".agents/packages/cli/dist/cli.js"));
|
||||
assert.equal(run({}).status, 1);
|
||||
assert.equal(existsSync(ran), false);
|
||||
const chosen = run({ HYPERFRAMES_CLI_ENTRY: handed });
|
||||
assert.equal(chosen.status, 0, chosen.stderr);
|
||||
assert.equal(chosen.stdout.trim(), "handed");
|
||||
assert.equal(existsSync(ran), false);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -1,36 +1,19 @@
|
||||
#!/usr/bin/env node
|
||||
import "./lib/windows-exe-search.mjs";
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { existsSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { resolveNpxInvocation } from "./lib/npx-sync.mjs";
|
||||
|
||||
// Installed plugins have no monorepo packages/ tree. The plugin launcher passes the
|
||||
// release version and hands itself over as the CLI, so this legacy shim runs the pinned CLI.
|
||||
if (process.env.HYPERFRAMES_PLUGIN_VERSION) {
|
||||
try {
|
||||
const invocation = resolveNpxInvocation(
|
||||
["hyperframes", "media-use", "resolve", ...process.argv.slice(2)],
|
||||
{ stdio: "inherit" },
|
||||
);
|
||||
const result = spawnSync(invocation.cmd, invocation.args, invocation.opts);
|
||||
if (result.error) console.error(result.error.message);
|
||||
process.exit(result.status ?? 1);
|
||||
} catch (error) {
|
||||
console.error(error.message);
|
||||
process.exit(1);
|
||||
}
|
||||
// Legacy shim: runs only the CLI the plugin launcher (or the person, by HYPERFRAMES_CLI_ENTRY) hands over. It never
|
||||
// runs a packages/cli found beside its own folder: in a project-scope install that folder is the project's.
|
||||
try {
|
||||
const invocation = resolveNpxInvocation(
|
||||
["hyperframes", "media-use", "resolve", ...process.argv.slice(2)],
|
||||
{ stdio: "inherit" },
|
||||
);
|
||||
const result = spawnSync(invocation.cmd, invocation.args, invocation.opts);
|
||||
if (result.error) console.error(result.error.message);
|
||||
process.exit(result.status ?? 1);
|
||||
} catch (error) {
|
||||
console.error(error.message);
|
||||
process.exit(1);
|
||||
}
|
||||
const root = join(fileURLToPath(new URL("../../../", import.meta.url)));
|
||||
const dist = join(root, "packages/cli/dist/cli.js");
|
||||
const result = existsSync(dist)
|
||||
? spawnSync(process.execPath, [dist, "media-use", "resolve", ...process.argv.slice(2)], {
|
||||
stdio: "inherit",
|
||||
})
|
||||
: spawnSync(
|
||||
"bun",
|
||||
[join(root, "packages/cli/src/cli.ts"), "media-use", "resolve", ...process.argv.slice(2)],
|
||||
{ stdio: "inherit" },
|
||||
);
|
||||
process.exit(result.status ?? 1);
|
||||
|
||||
Reference in New Issue
Block a user