Setting the file. One moment.
Sfx Test · Media Use · heygen-com/hyperframes · Skills Docs
ContentsBack to the top of the page ⋯
scripts/11 files
(opens in a new tab)
audio/scripts/lib/ sfx.test.mjs
JavaScript · 69 lines · 3 KB
9 // without the actual mp3s. The old code copied only when the source existed but
10 // pushed the sfx entry unconditionally — producing a dangling reference that
11 // silently dropped downstream ("not on disk"). These tests lock in the loud
12 // behavior: a present file is copied + referenced; a missing file yields an
13 // anomaly and NO dangling entry.
14
15 async function withDirs ( fn ) {
16 const root = mkdtempSync ( join ( tmpdir (), "hf-sfx-" ));
17 const libDir = join (root, "lib" );
18 const projDir = join (root, "proj" );
19 mkdirSync (libDir, { recursive: true });
20 mkdirSync (projDir, { recursive: true });
21 try {
22 // `await` is load-bearing: without it the finally cleanup runs before the
23 // async test body resolves, deleting the temp dir mid-assertion.
24 return await fn ({ libDir, projDir });
25 } finally {
26 rmSync (root, { recursive: true , force: true });
27 }
28 }
29
30 test ( "offline: copies and references a present bundled file" , async () => {
31 await withDirs ( async ({ libDir , projDir }) => {
32 writeFileSync (
33 join (libDir, "manifest.json" ),
34 JSON . stringify ({ whoosh: { file: "whoosh.mp3" , duration: 0.8 } }),
35 );
36 writeFileSync ( join (libDir, "whoosh.mp3" ), "ID3-fake-bytes" );
37 const { sfx , anomalies } = await resolveSfx ({
38 cues: [{ id: "s1" , name: "whoosh" }],
39 heygenOK: false ,
40 hyperframesDir: projDir,
41 sfxLibDir: libDir,
42 });
43 assert. equal (sfx. length , 1 );
44 assert. equal (sfx[ 0 ].file, "assets/sfx/whoosh.mp3" );
45 assert. equal (sfx[ 0 ].source, "local" );
46 assert. ok ( existsSync ( join (projDir, "assets/sfx/whoosh.mp3" )), "mp3 copied into project" );
47 assert. equal (anomalies. length , 0 );
48 });
49 });
50
51 test ( "offline: a matched-but-missing bundled file yields an anomaly and NO dangling entry" , async () => {
52 await withDirs ( async ({ libDir , projDir }) => {
53 // Manifest names whoosh.mp3, but the mp3 was never shipped (the reported bug).
54 writeFileSync (
55 join (libDir, "manifest.json" ),
56 JSON . stringify ({ whoosh: { file: "whoosh.mp3" , duration: 0.8 } }),
57 );
58 const { sfx , anomalies } = await resolveSfx ({
59 cues: [{ id: "s1" , name: "whoosh" }],
60 heygenOK: false ,
61 hyperframesDir: projDir,
62 sfxLibDir: libDir,
63 });
64 assert. equal (sfx. length , 0 , "no dangling entry for a file that was never copied" );
65 assert. equal (anomalies. length , 1 );
66 assert. match (anomalies[ 0 ], /missing from the offline library/ );
67 assert. ok ( ! existsSync ( join (projDir, "assets/sfx/whoosh.mp3" )), "nothing copied" );
68 });
69 });