Skip to content

Commit 5a45911

Browse files
committed
fix(skills): report a host audio entry with no path and a broken sidecar instead of crashing
1 parent 2788f3b commit 5a45911

11 files changed

Lines changed: 98 additions & 56 deletions

File tree

‎skills-manifest.json‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"files": 144
77
},
88
"faceless-explainer": {
9-
"hash": "e19f2c26ed4035ad",
9+
"hash": "36f434caf058f16e",
1010
"files": 28
1111
},
1212
"figma": {
@@ -54,7 +54,7 @@
5454
"files": 1
5555
},
5656
"media-use": {
57-
"hash": "ccbb20429e1a3bd0",
57+
"hash": "b07cf8ba10a8ac7b",
5858
"files": 109
5959
},
6060
"motion-graphics": {
@@ -66,11 +66,11 @@
6666
"files": 169
6767
},
6868
"pr-to-video": {
69-
"hash": "d8ed14e963551ef8",
69+
"hash": "72d3b73ea8a440c9",
7070
"files": 34
7171
},
7272
"product-launch-video": {
73-
"hash": "d8928eeb87da0fe6",
73+
"hash": "92a85e48bb7d95c2",
7474
"files": 35
7575
},
7676
"remotion-to-hyperframes": {

‎skills/faceless-explainer/scripts/audio.mjs‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,12 @@ function runGenerate(argv) {
157157
// No narration and no looked-up music: the host's entries and any sounds fetch-sfx already found; a stale
158158
// voice or bed in the engine's sidecar goes.
159159
const neutral = neutralPath(outPath);
160-
const looked = existsSync(neutral) ? (JSON.parse(readFileSync(neutral, "utf8")).sfx ?? []) : [];
160+
let looked = [];
161+
try {
162+
looked = JSON.parse(readFileSync(neutral, "utf8")).sfx ?? [];
163+
} catch (err) {
164+
if (err.code !== "ENOENT") die(`${neutral} does not parse: ${err.message}`);
165+
}
161166
const kept = { voices: [], bgm: null, bgm_pending: false, sfx: looked };
162167
writeFileSync(neutral, JSON.stringify(kept));
163168
const meta = keepHostAudio(toProductLaunchMeta(kept), host);
@@ -227,8 +232,7 @@ function previousHostAudio(outPath, hyperframesDir, die) {
227232
if (err.code !== "ENOENT") die(`${outPath} does not parse: ${err.message}`);
228233
}
229234
const host = hostAudio(previous, (path) => existsSync(join(hyperframesDir, path)));
230-
for (const path of host.dropped)
231-
console.warn(`⚠ audio: host audio ${path} is not on disk — dropped`);
235+
for (const why of host.dropped) console.warn(`⚠ audio: host audio dropped: ${why}`);
232236
return host;
233237
}
234238

‎skills/faceless-explainer/scripts/audio.test.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ test("generate keeps a host bed when there is no narration and music: none", ()
252252
});
253253

254254
test("fetch-sfx stops on an audio_meta.json that does not parse, so host entries are not lost", () => {
255-
const { dir, result } = runFetchSfx({ storyboard: FRAME_WITH_SFX("whoosh") });
255+
const { dir } = runFetchSfx({ storyboard: FRAME_WITH_SFX("whoosh") });
256256
writeFileSync(
257257
join(dir, "audio_meta.json"),
258258
'{ "bgm": { "path": "assets/bgm/host.mp3", "source": "host" }, }',

‎skills/faceless-explainer/scripts/lib/host-audio.mjs‎

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
// Audio the host app supplied survives every pass that rebuilds audio_meta.json from the storyboard: an entry
22
// marked "source": "host" whose file exists. A frame the host scored takes no looked-up cue sound.
3-
const isHost = (entry, path, exists) =>
4-
entry?.source === "host" && typeof path === "string" && exists(path);
5-
6-
/** The host's own entries in an earlier audio_meta.json, and the host-marked paths dropped because their file is
7-
* gone; `exists` resolves a path from the project root. A frame written as "1" is frame 1. */
3+
/** The host's own entries in an earlier audio_meta.json, and why any other host-marked entry was dropped; `exists`
4+
* resolves a path from the project root. A frame written as "1" is frame 1. */
85
export function hostAudio(previous, exists) {
9-
const marked = [previous?.bgm?.path, ...(previous?.sfx ?? []).map((s) => s.file)];
10-
const bgm = isHost(previous?.bgm, previous?.bgm?.path, exists) ? previous.bgm : null;
6+
const marked = [[previous?.bgm, "path"], ...(previous?.sfx ?? []).map((s) => [s, "file"])].filter(
7+
([entry]) => entry?.source === "host",
8+
);
9+
const kept = new Set();
10+
const dropped = [];
11+
for (const [entry, key] of marked) {
12+
const path = entry[key];
13+
if (typeof path !== "string") dropped.push(`a host entry has no "${key}"`);
14+
else if (!exists(path)) dropped.push(`${path} is not on disk`);
15+
else kept.add(entry);
16+
}
17+
const bgm = kept.has(previous?.bgm) ? previous.bgm : null;
1118
const sfx = (previous?.sfx ?? [])
12-
.filter((s) => isHost(s, s.file, exists))
19+
.filter((s) => kept.has(s))
1320
.map((s) => ({ ...s, frame: Number(s.frame) }));
14-
const hostMarked = [previous?.bgm, ...(previous?.sfx ?? [])].filter((e) => e?.source === "host");
15-
const dropped = hostMarked.map((e) => e.path ?? e.file).filter((path) => !exists(path));
1621
return { bgm, sfx, frames: new Set(sfx.map((s) => s.frame)), dropped };
1722
}
1823

‎skills/media-use/audio/scripts/lib/host-audio.mjs‎

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
// Audio the host app supplied survives every pass that rebuilds audio_meta.json from the storyboard: an entry
22
// marked "source": "host" whose file exists. A frame the host scored takes no looked-up cue sound.
3-
const isHost = (entry, path, exists) =>
4-
entry?.source === "host" && typeof path === "string" && exists(path);
5-
6-
/** The host's own entries in an earlier audio_meta.json, and the host-marked paths dropped because their file is
7-
* gone; `exists` resolves a path from the project root. A frame written as "1" is frame 1. */
3+
/** The host's own entries in an earlier audio_meta.json, and why any other host-marked entry was dropped; `exists`
4+
* resolves a path from the project root. A frame written as "1" is frame 1. */
85
export function hostAudio(previous, exists) {
9-
const marked = [previous?.bgm?.path, ...(previous?.sfx ?? []).map((s) => s.file)];
10-
const bgm = isHost(previous?.bgm, previous?.bgm?.path, exists) ? previous.bgm : null;
6+
const marked = [[previous?.bgm, "path"], ...(previous?.sfx ?? []).map((s) => [s, "file"])].filter(
7+
([entry]) => entry?.source === "host",
8+
);
9+
const kept = new Set();
10+
const dropped = [];
11+
for (const [entry, key] of marked) {
12+
const path = entry[key];
13+
if (typeof path !== "string") dropped.push(`a host entry has no "${key}"`);
14+
else if (!exists(path)) dropped.push(`${path} is not on disk`);
15+
else kept.add(entry);
16+
}
17+
const bgm = kept.has(previous?.bgm) ? previous.bgm : null;
1118
const sfx = (previous?.sfx ?? [])
12-
.filter((s) => isHost(s, s.file, exists))
19+
.filter((s) => kept.has(s))
1320
.map((s) => ({ ...s, frame: Number(s.frame) }));
14-
const hostMarked = [previous?.bgm, ...(previous?.sfx ?? [])].filter((e) => e?.source === "host");
15-
const dropped = hostMarked.map((e) => e.path ?? e.file).filter((path) => !exists(path));
1621
return { bgm, sfx, frames: new Set(sfx.map((s) => s.frame)), dropped };
1722
}
1823

‎skills/media-use/audio/scripts/lib/host-audio.test.mjs‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,17 @@ test("a frame written as a string is the same frame, and a gone host file is rep
9090
const host = hostAudio(previous, exists);
9191
assert.deepEqual(host.sfx, [hostWhoosh]);
9292
assert.ok(host.frames.has(1));
93-
assert.deepEqual(host.dropped, ["assets/bgm/gone.mp3"]);
93+
assert.deepEqual(host.dropped, ["assets/bgm/gone.mp3 is not on disk"]);
9494
const rebuilt = { bgm: null, voices: [], sfx: [{ frame: 1, file: "assets/sfx/whoosh.mp3" }] };
9595
assert.deepEqual(keepHostAudio(rebuilt, host).sfx, [hostWhoosh]);
9696
});
97+
98+
test("a host entry with no path is reported, not thrown", () => {
99+
const throwsOnNonString = (path) => {
100+
if (typeof path !== "string") throw new TypeError("path must be a string");
101+
return onDisk.has(path);
102+
};
103+
const host = hostAudio({ bgm: { src: "x.mp3", source: "host" }, sfx: [] }, throwsOnNonString);
104+
assert.equal(host.bgm, null);
105+
assert.deepEqual(host.dropped, ['a host entry has no "path"']);
106+
});

‎skills/pr-to-video/scripts/audio.mjs‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,12 @@ function runGenerate(argv) {
157157
// No narration and no looked-up music: the host's entries and any sounds fetch-sfx already found; a stale
158158
// voice or bed in the engine's sidecar goes.
159159
const neutral = neutralPath(outPath);
160-
const looked = existsSync(neutral) ? (JSON.parse(readFileSync(neutral, "utf8")).sfx ?? []) : [];
160+
let looked = [];
161+
try {
162+
looked = JSON.parse(readFileSync(neutral, "utf8")).sfx ?? [];
163+
} catch (err) {
164+
if (err.code !== "ENOENT") die(`${neutral} does not parse: ${err.message}`);
165+
}
161166
const kept = { voices: [], bgm: null, bgm_pending: false, sfx: looked };
162167
writeFileSync(neutral, JSON.stringify(kept));
163168
const meta = keepHostAudio(toProductLaunchMeta(kept), host);
@@ -227,8 +232,7 @@ function previousHostAudio(outPath, hyperframesDir, die) {
227232
if (err.code !== "ENOENT") die(`${outPath} does not parse: ${err.message}`);
228233
}
229234
const host = hostAudio(previous, (path) => existsSync(join(hyperframesDir, path)));
230-
for (const path of host.dropped)
231-
console.warn(`⚠ audio: host audio ${path} is not on disk — dropped`);
235+
for (const why of host.dropped) console.warn(`⚠ audio: host audio dropped: ${why}`);
232236
return host;
233237
}
234238

‎skills/pr-to-video/scripts/lib/host-audio.mjs‎

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
// Audio the host app supplied survives every pass that rebuilds audio_meta.json from the storyboard: an entry
22
// marked "source": "host" whose file exists. A frame the host scored takes no looked-up cue sound.
3-
const isHost = (entry, path, exists) =>
4-
entry?.source === "host" && typeof path === "string" && exists(path);
5-
6-
/** The host's own entries in an earlier audio_meta.json, and the host-marked paths dropped because their file is
7-
* gone; `exists` resolves a path from the project root. A frame written as "1" is frame 1. */
3+
/** The host's own entries in an earlier audio_meta.json, and why any other host-marked entry was dropped; `exists`
4+
* resolves a path from the project root. A frame written as "1" is frame 1. */
85
export function hostAudio(previous, exists) {
9-
const marked = [previous?.bgm?.path, ...(previous?.sfx ?? []).map((s) => s.file)];
10-
const bgm = isHost(previous?.bgm, previous?.bgm?.path, exists) ? previous.bgm : null;
6+
const marked = [[previous?.bgm, "path"], ...(previous?.sfx ?? []).map((s) => [s, "file"])].filter(
7+
([entry]) => entry?.source === "host",
8+
);
9+
const kept = new Set();
10+
const dropped = [];
11+
for (const [entry, key] of marked) {
12+
const path = entry[key];
13+
if (typeof path !== "string") dropped.push(`a host entry has no "${key}"`);
14+
else if (!exists(path)) dropped.push(`${path} is not on disk`);
15+
else kept.add(entry);
16+
}
17+
const bgm = kept.has(previous?.bgm) ? previous.bgm : null;
1118
const sfx = (previous?.sfx ?? [])
12-
.filter((s) => isHost(s, s.file, exists))
19+
.filter((s) => kept.has(s))
1320
.map((s) => ({ ...s, frame: Number(s.frame) }));
14-
const hostMarked = [previous?.bgm, ...(previous?.sfx ?? [])].filter((e) => e?.source === "host");
15-
const dropped = hostMarked.map((e) => e.path ?? e.file).filter((path) => !exists(path));
1621
return { bgm, sfx, frames: new Set(sfx.map((s) => s.frame)), dropped };
1722
}
1823

‎skills/product-launch-video/scripts/audio.mjs‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,12 @@ function runGenerate(argv) {
156156
// No narration and no looked-up music: the host's entries and any sounds fetch-sfx already found; a stale
157157
// voice or bed in the engine's sidecar goes.
158158
const neutral = neutralPath(outPath);
159-
const looked = existsSync(neutral) ? (JSON.parse(readFileSync(neutral, "utf8")).sfx ?? []) : [];
159+
let looked = [];
160+
try {
161+
looked = JSON.parse(readFileSync(neutral, "utf8")).sfx ?? [];
162+
} catch (err) {
163+
if (err.code !== "ENOENT") die(`${neutral} does not parse: ${err.message}`);
164+
}
160165
const kept = { voices: [], bgm: null, bgm_pending: false, sfx: looked };
161166
writeFileSync(neutral, JSON.stringify(kept));
162167
const meta = keepHostAudio(toProductLaunchMeta(kept), host);
@@ -226,8 +231,7 @@ function previousHostAudio(outPath, hyperframesDir, die) {
226231
if (err.code !== "ENOENT") die(`${outPath} does not parse: ${err.message}`);
227232
}
228233
const host = hostAudio(previous, (path) => existsSync(join(hyperframesDir, path)));
229-
for (const path of host.dropped)
230-
console.warn(`⚠ audio: host audio ${path} is not on disk — dropped`);
234+
for (const why of host.dropped) console.warn(`⚠ audio: host audio dropped: ${why}`);
231235
return host;
232236
}
233237

‎skills/product-launch-video/scripts/audio.test.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ test("generate keeps a host bed when there is no narration and music: none", ()
310310
});
311311

312312
test("fetch-sfx stops on an audio_meta.json that does not parse, so host entries are not lost", () => {
313-
const { dir, result } = runFetchSfx({ storyboard: FRAME_WITH_SFX("whoosh") });
313+
const { dir } = runFetchSfx({ storyboard: FRAME_WITH_SFX("whoosh") });
314314
writeFileSync(
315315
join(dir, "audio_meta.json"),
316316
'{ "bgm": { "path": "assets/bgm/host.mp3", "source": "host" }, }',

0 commit comments

Comments
 (0)