|
1 | 1 | import assert from "node:assert/strict"; |
2 | | -import { mkdtempSync, readFileSync, writeFileSync } from "node:fs"; |
| 2 | +import { existsSync, mkdtempSync, readFileSync, writeFileSync } from "node:fs"; |
3 | 3 | import { tmpdir } from "node:os"; |
4 | 4 | import { join } from "node:path"; |
5 | 5 | import { spawnSync } from "node:child_process"; |
@@ -44,3 +44,77 @@ test("--provider takes precedence over HF_TTS_PROVIDER", () => { |
44 | 44 | "kokoro", |
45 | 45 | ); |
46 | 46 | }); |
| 47 | + |
| 48 | +// ── the canonical fully-silent marker (SKILL.md Step 3.1) ──────────────────── |
| 49 | +// `music: none` in the storyboard's top YAML block + no SCRIPT.md marks the |
| 50 | +// project fully silent: generate must produce nothing (an absent |
| 51 | +// audio_meta.json is what assemble treats as silent) and clear stale meta. |
| 52 | + |
| 53 | +/** Like runAudio, but with a caller-controlled storyboard and no request assertion. */ |
| 54 | +function runAudioRaw({ storyboard, scriptMd = null, preexistingMeta = null }) { |
| 55 | + const dir = mkdtempSync(join(tmpdir(), "product-launch-audio-")); |
| 56 | + const engine = join(dir, "engine.mjs"); |
| 57 | + writeFileSync(join(dir, "STORYBOARD.md"), storyboard); |
| 58 | + if (scriptMd != null) writeFileSync(join(dir, "SCRIPT.md"), scriptMd); |
| 59 | + if (preexistingMeta != null) writeFileSync(join(dir, "audio_meta.json"), preexistingMeta); |
| 60 | + writeFileSync( |
| 61 | + engine, |
| 62 | + `import { readFileSync, writeFileSync } from "node:fs"; |
| 63 | +const argv = process.argv.slice(2); |
| 64 | +const flag = (name) => argv[argv.indexOf(name) + 1]; |
| 65 | +const request = JSON.parse(readFileSync(flag("--request"), "utf8")); |
| 66 | +writeFileSync(new URL("request.json", import.meta.url), JSON.stringify(request)); |
| 67 | +writeFileSync(flag("--out"), JSON.stringify({ voices: [], bgm: null, sfx: [] })); |
| 68 | +`, |
| 69 | + ); |
| 70 | + const result = spawnSync( |
| 71 | + process.execPath, |
| 72 | + [script, "--hyperframes", dir, "--storyboard", join(dir, "STORYBOARD.md")], |
| 73 | + { encoding: "utf8", env: { ...process.env, HF_MEDIA_ENGINE: engine } }, |
| 74 | + ); |
| 75 | + return { dir, result }; |
| 76 | +} |
| 77 | + |
| 78 | +test("music: none + no SCRIPT.md = fully silent: no engine run, no audio_meta.json", () => { |
| 79 | + const { dir, result } = runAudioRaw({ storyboard: "---\nmessage: Test\nmusic: none\n---\n" }); |
| 80 | + |
| 81 | + assert.equal(result.status, 0, result.stderr); |
| 82 | + assert.match(result.stdout, /marked silent/); |
| 83 | + // The engine was never invoked... |
| 84 | + assert.equal(existsSync(join(dir, "request.json")), false); |
| 85 | + // ...and no meta exists (absence ⇒ assemble treats the film as silent). |
| 86 | + assert.equal(existsSync(join(dir, "audio_meta.json")), false); |
| 87 | +}); |
| 88 | + |
| 89 | +test("fully-silent run removes stale audio_meta.json from a previous non-silent run", () => { |
| 90 | + const { dir, result } = runAudioRaw({ |
| 91 | + storyboard: "---\nmessage: Test\nmusic: none\n---\n", |
| 92 | + preexistingMeta: JSON.stringify({ bgm: { path: "old.mp3" }, voices: [], sfx: [] }), |
| 93 | + }); |
| 94 | + |
| 95 | + assert.equal(result.status, 0, result.stderr); |
| 96 | + assert.equal(existsSync(join(dir, "audio_meta.json")), false); |
| 97 | +}); |
| 98 | + |
| 99 | +test("music: none with narration keeps TTS but turns BGM off (not fully silent)", () => { |
| 100 | + const { dir, result } = runAudioRaw({ |
| 101 | + storyboard: "---\nmessage: Test\nmusic: none\n---\n", |
| 102 | + scriptMd: "## Hook (Frame 1)\n\n Spoken line for frame one.\n", |
| 103 | + }); |
| 104 | + |
| 105 | + assert.equal(result.status, 0, result.stderr); |
| 106 | + const request = JSON.parse(readFileSync(join(dir, "request.json"), "utf8")); |
| 107 | + assert.equal(request.bgm.mode, "none"); |
| 108 | + assert.equal(request.lines.length, 1); |
| 109 | +}); |
| 110 | + |
| 111 | +test("a storyboard music mood still retrieves BGM (marker is exact, not fuzzy)", () => { |
| 112 | + const { dir, result } = runAudioRaw({ |
| 113 | + storyboard: "---\nmessage: Test\nmusic: upbeat synthwave with heavy drums\n---\n", |
| 114 | + }); |
| 115 | + |
| 116 | + assert.equal(result.status, 0, result.stderr); |
| 117 | + const request = JSON.parse(readFileSync(join(dir, "request.json"), "utf8")); |
| 118 | + assert.equal(request.bgm.mode, "retrieve"); |
| 119 | + assert.equal(request.bgm.query, "upbeat synthwave with heavy drums"); |
| 120 | +}); |
0 commit comments