mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-19 11:26:02 +00:00
fix(media-use): recipe, prefs and SFX lines show control characters as escapes (#8202)
recipe.mjs and prefs.mjs printed recipe.json and preferences.json values raw: names, workflows, approval dates, brief values, confirmed-in project names, and the known-recipe list in an unknown-name error. Both files travel with a project, so an escape sequence in them could rewrite or hide earlier output, set the window title or write the clipboard in terminals that allow it. The SFX provider's empty-search line repeats the intent, and its Openverse fallback line repeats a network error. Each of those lines now goes through terminalText, like the resolve and adopt lines beside them. --json output is unchanged. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
e5283f63b9
commit
36b60d18b4
@@ -1,5 +1,6 @@
|
||||
import { heygenSearch } from "./heygen-search.mjs";
|
||||
import { OpenverseUnavailableError, searchOpenverseSfx } from "./openverse.mjs";
|
||||
import { terminalText } from "./terminal-text.mjs";
|
||||
|
||||
export const OPENVERSE_SFX_PROVIDER = "openverse.audio";
|
||||
|
||||
@@ -24,7 +25,9 @@ export const heygenSfxProvider = {
|
||||
minScore: SFX_MIN_SCORE,
|
||||
onEmpty: () =>
|
||||
console.error(
|
||||
`media-use: HeyGen sound search matched nothing for "${intent}" at min score ${SFX_MIN_SCORE}; trying the next source`,
|
||||
terminalText(
|
||||
`media-use: HeyGen sound search matched nothing for "${intent}" at min score ${SFX_MIN_SCORE}; trying the next source`,
|
||||
),
|
||||
),
|
||||
});
|
||||
if (!results) return null;
|
||||
@@ -50,7 +53,7 @@ export const sfxProvider = {
|
||||
sound = await searchOpenverseSfx(intent);
|
||||
} catch (error) {
|
||||
if (!(error instanceof OpenverseUnavailableError)) throw error;
|
||||
console.error(`media-use: ${error.message}; using the bundled sound effects`);
|
||||
console.error(terminalText(`media-use: ${error.message}; using the bundled sound effects`));
|
||||
return null;
|
||||
}
|
||||
if (!sound) return null;
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
import { strict as assert } from "node:assert";
|
||||
import { chmodSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { delimiter, join } from "node:path";
|
||||
import { test } from "node:test";
|
||||
import { heygenSfxProvider, sfxProvider } from "./sfx-provider.mjs";
|
||||
|
||||
const HOSTILE = "\x1b]52;c;aGk=\x07\x1b[2J";
|
||||
const SHOWN = "\\x1b]52;c;aGk=\\x07\\x1b[2J";
|
||||
|
||||
function captureStderr(t) {
|
||||
const lines = [];
|
||||
t.mock.method(console, "error", (...args) => lines.push(args.join(" ")));
|
||||
return lines;
|
||||
}
|
||||
|
||||
function assertEscaped(lines) {
|
||||
const out = lines.join("\n");
|
||||
assert.ok(out.includes(SHOWN), out);
|
||||
for (const raw of ["\x1b", "\x07"]) assert.ok(!out.includes(raw), JSON.stringify(out));
|
||||
}
|
||||
|
||||
test(
|
||||
"an empty HeyGen sound search repeats the intent with control characters as visible escapes",
|
||||
{
|
||||
skip: process.platform === "win32" && "the fake heygen binary is a shell script",
|
||||
},
|
||||
async (t) => {
|
||||
const bin = mkdtempSync(join(tmpdir(), "sfx-provider-heygen-"));
|
||||
const savedPath = process.env.PATH;
|
||||
try {
|
||||
writeFileSync(join(bin, "heygen"), `#!/bin/sh\necho '{"data":[]}'\n`);
|
||||
chmodSync(join(bin, "heygen"), 0o755);
|
||||
process.env.PATH = `${bin}${delimiter}${savedPath}`;
|
||||
const lines = captureStderr(t);
|
||||
assert.equal(await heygenSfxProvider.search(`whoosh${HOSTILE}`), null);
|
||||
assertEscaped(lines);
|
||||
} finally {
|
||||
process.env.PATH = savedPath;
|
||||
rmSync(bin, { recursive: true, force: true });
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
test("an unreachable Openverse error prints with control characters as visible escapes", async (t) => {
|
||||
t.mock.method(globalThis, "fetch", async () => {
|
||||
throw new Error(`proxy said ${HOSTILE}`);
|
||||
});
|
||||
const lines = captureStderr(t);
|
||||
assert.equal(await sfxProvider.search("whoosh"), null);
|
||||
assertEscaped(lines);
|
||||
});
|
||||
@@ -18,8 +18,8 @@
|
||||
"files": 13
|
||||
},
|
||||
"media-use": {
|
||||
"hash": "6d018bd953cd09b1",
|
||||
"files": 130
|
||||
"hash": "ade4f491789eec78",
|
||||
"files": 131
|
||||
},
|
||||
"remotion-to-hyperframes": {
|
||||
"hash": "27f757cb659e1aaa",
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
import { strict as assert } from "node:assert";
|
||||
import { execFileSync } from "node:child_process";
|
||||
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { test } from "node:test";
|
||||
|
||||
const scriptsDir = new URL(".", import.meta.url).pathname;
|
||||
const HOSTILE = "x\x1b]52;c;aGk=\x07\x1b[2J";
|
||||
const SHOWN = "x\\x1b]52;c;aGk=\\x07\\x1b[2J";
|
||||
|
||||
function run(script, args, home) {
|
||||
return execFileSync(process.execPath, [join(scriptsDir, script), ...args], {
|
||||
encoding: "utf8",
|
||||
stdio: ["ignore", "pipe", "pipe"],
|
||||
env: { ...process.env, HYPERFRAMES_MEDIA_HOME: home },
|
||||
});
|
||||
}
|
||||
|
||||
function assertEscaped(output) {
|
||||
assert.ok(output.includes(SHOWN), output);
|
||||
for (const raw of ["\x1b", "\x07"]) assert.ok(!output.includes(raw), JSON.stringify(output));
|
||||
}
|
||||
|
||||
function withProject(fn) {
|
||||
const root = mkdtempSync(join(tmpdir(), "media-use-memory-output-"));
|
||||
const home = join(root, "home");
|
||||
const project = join(root, "project");
|
||||
mkdirSync(home, { recursive: true });
|
||||
mkdirSync(join(project, ".media/recipes/promo"), { recursive: true });
|
||||
writeFileSync(join(project, "frame.md"), "# Frame spec\n");
|
||||
writeFileSync(
|
||||
join(project, ".media/recipes/promo/recipe.json"),
|
||||
JSON.stringify({
|
||||
name: "promo",
|
||||
version: 1,
|
||||
workflow: `launch-${HOSTILE}`,
|
||||
approved_at: "2026-11-18T00:00:00Z",
|
||||
destination: `feed-${HOSTILE}`,
|
||||
}),
|
||||
);
|
||||
writeFileSync(join(project, ".media/recipes/promo/frame.md"), "# Frame spec\n");
|
||||
writeFileSync(join(project, ".media/recipes/promo/storyboard-skeleton.md"), "## Frame 1\n");
|
||||
writeFileSync(
|
||||
join(project, ".media/preferences.json"),
|
||||
JSON.stringify({
|
||||
version: 1,
|
||||
preferences: {
|
||||
destination: { value: `feed-${HOSTILE}`, confirmed_in: [`proj-${HOSTILE}`] },
|
||||
},
|
||||
}),
|
||||
);
|
||||
try {
|
||||
fn({ project, home });
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true });
|
||||
}
|
||||
}
|
||||
|
||||
test("recipe list and use print recipe.json text with control characters as visible escapes", () => {
|
||||
withProject(({ project, home }) => {
|
||||
assertEscaped(run("recipe.mjs", ["list", "--hyperframes", project], home));
|
||||
const used = run("recipe.mjs", ["use", "--hyperframes", project, "--name", "promo"], home);
|
||||
assertEscaped(used);
|
||||
assert.match(used, /destination: feed-x\\x1b/);
|
||||
});
|
||||
});
|
||||
|
||||
test("recipe --json output keeps the stored value as it is", () => {
|
||||
withProject(({ project, home }) => {
|
||||
const list = JSON.parse(run("recipe.mjs", ["list", "--hyperframes", project, "--json"], home));
|
||||
assert.equal(list[0].workflow, `launch-${HOSTILE}`);
|
||||
});
|
||||
});
|
||||
|
||||
test("prefs get prints remembered values with control characters as visible escapes", () => {
|
||||
withProject(({ project, home }) => {
|
||||
const shown = run("prefs.mjs", ["get", "--hyperframes", project], home);
|
||||
assertEscaped(shown);
|
||||
assert.match(shown, /confirmed in proj-x\\x1b/);
|
||||
});
|
||||
});
|
||||
|
||||
test("prefs record echoes the recorded value with control characters as visible escapes", () => {
|
||||
withProject(({ project, home }) => {
|
||||
const shown = run(
|
||||
"prefs.mjs",
|
||||
["record", "--hyperframes", project, "--key", "aspect", "--value", `16:9${HOSTILE}`],
|
||||
home,
|
||||
);
|
||||
assertEscaped(shown);
|
||||
});
|
||||
});
|
||||
|
||||
test("a failing recipe command prints its error with control characters as visible escapes", () => {
|
||||
withProject(({ project, home }) => {
|
||||
const other = join(project, ".media/recipes/other");
|
||||
mkdirSync(other, { recursive: true });
|
||||
writeFileSync(join(other, "recipe.json"), JSON.stringify({ name: `other-${HOSTILE}` }));
|
||||
assert.throws(
|
||||
() => run("recipe.mjs", ["use", "--hyperframes", project, "--name", "nope"], home),
|
||||
(err) => {
|
||||
assertEscaped(String(err.stderr));
|
||||
return err.status === 1;
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -16,6 +16,7 @@
|
||||
*/
|
||||
import { parseArgs } from "node:util";
|
||||
import { mergedPreferences, recordPreference } from "./lib/prefs-store.mjs";
|
||||
import { terminalText } from "./lib/terminal-text.mjs";
|
||||
|
||||
const { values: args, positionals } = parseArgs({
|
||||
options: {
|
||||
@@ -31,7 +32,7 @@ const { values: args, positionals } = parseArgs({
|
||||
const verb = positionals[0];
|
||||
|
||||
function fail(message) {
|
||||
console.error(message);
|
||||
console.error(terminalText(message));
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
@@ -44,7 +45,9 @@ if (verb === "get") {
|
||||
} else {
|
||||
for (const [key, entry] of Object.entries(merged)) {
|
||||
console.log(
|
||||
`${key} = ${entry.value} (${entry.source}; confirmed in ${entry.confirmed_in.join(", ")})`,
|
||||
terminalText(
|
||||
`${key} = ${entry.value} (${entry.source}; confirmed in ${entry.confirmed_in.join(", ")})`,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -58,7 +61,7 @@ if (verb === "get") {
|
||||
workflow: args.workflow,
|
||||
});
|
||||
const promotion = result.promoted ? "; promoted to user tier" : "";
|
||||
console.log(`recorded ${result.key} = ${result.value} (project${promotion})`);
|
||||
console.log(terminalText(`recorded ${result.key} = ${result.value} (project${promotion})`));
|
||||
} catch (err) {
|
||||
fail(err instanceof Error ? err.message : String(err));
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
*/
|
||||
import { parseArgs } from "node:util";
|
||||
import { freezeRecipe, listRecipes, useRecipe } from "./lib/recipe-store.mjs";
|
||||
import { terminalText } from "./lib/terminal-text.mjs";
|
||||
|
||||
const { values: args, positionals } = parseArgs({
|
||||
options: {
|
||||
@@ -37,7 +38,7 @@ const { values: args, positionals } = parseArgs({
|
||||
const verb = positionals[0];
|
||||
|
||||
function fail(message) {
|
||||
console.error(message);
|
||||
console.error(terminalText(message));
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
@@ -58,10 +59,14 @@ try {
|
||||
if (args.json) console.log(JSON.stringify({ ok: true, ...frozen }));
|
||||
else {
|
||||
console.log(
|
||||
`froze recipe ${frozen.slug} (v${frozen.version}, ${frozen.workflow}) → ${frozen.dir}`,
|
||||
terminalText(
|
||||
`froze recipe ${frozen.slug} (v${frozen.version}, ${frozen.workflow}) → ${frozen.dir}`,
|
||||
),
|
||||
);
|
||||
if (frozen.workflowOverridden)
|
||||
console.log(` (BRIEF.md says "${frozen.workflow}" — the --workflow flag was ignored)`);
|
||||
console.log(
|
||||
terminalText(` (BRIEF.md says "${frozen.workflow}" — the --workflow flag was ignored)`),
|
||||
);
|
||||
if (!frozen.briefSkeleton)
|
||||
console.log(" (no BRIEF.md in the project — brief skeleton skipped)");
|
||||
}
|
||||
@@ -72,7 +77,9 @@ try {
|
||||
else {
|
||||
for (const r of list) {
|
||||
console.log(
|
||||
`${r.name} v${r.version} ${r.workflow} (${r.source}; approved ${String(r.approved_at ?? "?").slice(0, 10)})`,
|
||||
terminalText(
|
||||
`${r.name} v${r.version} ${r.workflow} (${r.source}; approved ${String(r.approved_at ?? "?").slice(0, 10)})`,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -82,13 +89,16 @@ try {
|
||||
if (args.json) console.log(JSON.stringify({ ok: true, ...used }));
|
||||
else {
|
||||
console.log(
|
||||
`using recipe ${used.recipe.name} (v${used.recipe.version}, ${used.recipe.workflow})`,
|
||||
terminalText(
|
||||
`using recipe ${used.recipe.name} (v${used.recipe.version}, ${used.recipe.workflow})`,
|
||||
),
|
||||
);
|
||||
console.log(` frame spec → ${used.frameSpecPath} (copied over)`);
|
||||
console.log(` storyboard skeleton → ${used.skeletonPath}`);
|
||||
if (used.briefSkeletonPath) console.log(` brief skeleton → ${used.briefSkeletonPath}`);
|
||||
console.log(terminalText(` frame spec → ${used.frameSpecPath} (copied over)`));
|
||||
console.log(terminalText(` storyboard skeleton → ${used.skeletonPath}`));
|
||||
if (used.briefSkeletonPath)
|
||||
console.log(terminalText(` brief skeleton → ${used.briefSkeletonPath}`));
|
||||
for (const key of ["destination", "aspect", "language", "voice", "style_preset"]) {
|
||||
if (used.recipe[key]) console.log(` ${key}: ${used.recipe[key]}`);
|
||||
if (used.recipe[key]) console.log(terminalText(` ${key}: ${used.recipe[key]}`));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user