fix(media-use): escape audio engine summary and broken audio_meta.json errors (#8258)

The run summary now escapes the BGM provider and SFX count carried over
from audio_meta.json. A malformed audio_meta.json now stops the engine
through its usual error line, which escapes the file's bytes, instead of
an uncaught exception.
This commit is contained in:
Michael Wang
2026-11-19 22:45:22 +00:00
committed by GitHub
parent 9dd8be3ac4
commit 4a11e46c70
3 changed files with 59 additions and 3 deletions
+1 -1
View File
@@ -18,7 +18,7 @@
"files": 13
},
"media-use": {
"hash": "476ec9020960f6f0",
"hash": "d979128f61f6ab95",
"files": 131
},
"remotion-to-hyperframes": {
+9 -2
View File
@@ -127,7 +127,12 @@ const outRel = relative(hyperframesDir, outPath);
const outInProject = outRel !== ".." && !outRel.startsWith(`..${sep}`) && !isAbsolute(outRel);
if (outInProject && !projectPath(hyperframesDir, outRel))
die(`${outPath} leads outside the project folder; replace it with a regular file`);
const audioMeta = openAudioMeta(outPath);
let audioMeta;
try {
audioMeta = openAudioMeta(outPath);
} catch (e) {
die(`audio_meta.json at ${outPath}: ${e.message}`);
}
const prev = audioMeta.value;
const anomalies = [];
@@ -353,7 +358,9 @@ anomalies.push(...recordInManifest(hyperframesDir, written));
console.log(terminalText(`✓ audio engine → ${outPath}`));
console.log(` heygen: ${heygenOK ? "yes" : "no"} · ran: ${[...only].join(",")}`);
console.log(
` voices: ${voices.length} · bgm: ${bgm ? `${bgmFields.bgm_provider}${bgmFields.bgm_pending ? " (pending)" : ""}` : "none"} · sfx: ${sfx.length}`,
terminalText(
` voices: ${voices.length} · bgm: ${bgm ? `${bgmFields.bgm_provider}${bgmFields.bgm_pending ? " (pending)" : ""}` : "none"} · sfx: ${sfx.length}`,
),
);
console.log(` total voice duration: ${totalDuration}s`);
if (anomalies.length) {
@@ -270,3 +270,52 @@ test("a broken audio_request.json prints its bytes with control characters as es
rmSync(dir, { recursive: true, force: true });
}
});
// With --only, bgm_provider and sfx carry over from audio_meta.json unchanged into the summary.
for (const only of ["tts", "sfx"]) {
test(`--only ${only}: values kept from audio_meta.json print with control characters as escapes`, () => {
const dir = mkdtempSync(join(tmpdir(), "audio-kept-escape-"));
try {
writeFileSync(join(dir, "audio_request.json"), JSON.stringify({ lines: [] }));
const kept = {
bgm: { path: "assets/bgm/track.wav" },
bgm_provider: "p\x1b[2J\x07",
sfx: { length: "n\x1b]0;x\x07" },
};
writeFileSync(join(dir, "audio_meta.json"), JSON.stringify(kept));
const run = spawnSync(
process.execPath,
[join(HERE, "audio.mjs"), "--hyperframes", dir, "--only", only],
{ encoding: "utf8", env: { ...process.env, HOME: dir } },
);
assert.equal(run.status, 0, run.stderr);
const shown = run.stdout + run.stderr;
assert.match(shown, /bgm: p\\x1b\[2J\\x07/);
if (only === "tts") assert.match(shown, /sfx: n\\x1b\]0;x\\x07/);
for (const raw of ["\x1b", "\x07"]) assert.ok(!shown.includes(raw), JSON.stringify(shown));
const meta = JSON.parse(readFileSync(join(dir, "audio_meta.json"), "utf8"));
assert.equal(meta.bgm_provider, kept.bgm_provider);
if (only === "tts") assert.deepEqual(meta.sfx, kept.sfx);
} finally {
rmSync(dir, { recursive: true, force: true });
}
});
}
test("a broken audio_meta.json prints its bytes with control characters as escapes", () => {
const dir = mkdtempSync(join(tmpdir(), "audio-broken-meta-"));
try {
writeFileSync(join(dir, "audio_request.json"), JSON.stringify({ lines: [] }));
writeFileSync(join(dir, "audio_meta.json"), '{"sfx": [ \x1b]0;x \x07 ]}');
const run = spawnSync(
process.execPath,
[join(HERE, "audio.mjs"), "--hyperframes", dir, "--only", "sfx"],
{ encoding: "utf8", env: { ...process.env, HOME: dir } },
);
assert.notEqual(run.status, 0, run.stdout);
assert.match(run.stderr, /audio_meta\.json at .*: .*\\x1b/);
for (const raw of ["\x1b", "\x07"]) assert.ok(!run.stderr.includes(raw), run.stderr);
} finally {
rmSync(dir, { recursive: true, force: true });
}
});