Setting the file. One moment. Transcribe Test · Media Use · heygen-com/hyperframes · Skills DocsResolve
(opens in a new tab)
scripts/transcribe.test.mjs
JavaScript·112 lines·4 KB
from
"node:url"
;
8
9// The stub stands in for `npx hyperframes transcribe <in> --dir <dir> ...`: it records its args,
10// writes the CLI's flat array and prints the CLI's --json line naming `cliEngine`.
11function runScript(engine, cliEngine) {
12 const root = mkdtempSync(join(tmpdir(), "media-use-transcribe-"));
13 try {
14 const bin = join(root, "bin");
15 mkdirSync(bin);
16 writeFileSync(
17 join(bin, "npx"),
18 `#!/bin/sh\necho "$@" > "${root}/args"\nwhile [ "$1" != "--dir" ]; do shift; done\n` +
19 `echo '[{"text":"a","start":0,"end":1},{"text":"b","start":1,"end":2}]' > "$2/transcript.json"\n` +
20 `echo '{"ok":true,"engine":"${cliEngine}"}'\n`,
21 );
22 chmodSync(join(bin, "npx"), 0o755);
23 const input = join(root, "in.wav");
24 writeFileSync(input, "");
25 const script = fileURLToPath(new URL("./transcribe.mjs", import.meta.url));
26 const env = { ...process.env, PATH: `${bin}:${process.env.PATH}`, HOME: root };
27 delete env.HYPERFRAMES_PARAKEET;
28 const out = execFileSync(
29 process.execPath,
30 [script, "--input", input, "--engine", engine, "--json"],
31 {
32 encoding: "utf8",
33 env: { ...env, HYPERFRAMES_MEDIA_HOME: join(root, "home"), HYPERFRAMES_NO_TELEMETRY: "1" },
34 },
35 );
36 return { result: JSON.parse(out.trim()), args: readFileSync(join(root, "args"), "utf8") };
37 } finally {
38 rmSync(root, { recursive: true, force: true });
39 }
40}
41
42test(
43 "--engine whisper makes the CLI run whisper and reports the flat transcript's word count",
44 { skip: process.platform === "win32" },
45 () => {
46 const { result, args } = runScript("whisper", "whisper");
47 assert.match(args, /--engine whisper --json/);
48 assert.equal(result.words, 2);
49 assert.equal(result.engine, "whisper");
50 },
51);
52
53test(
54 "auto reports the engine the CLI says it ran, Parakeet included",
55 { skip: process.platform === "win32" },
56 () => {
57 const { result, args } = runScript("auto", "parakeet");
58 assert.match(args, /--engine auto --json/);
59 assert.equal(result.engine, "parakeet");
60 },
61);
62
63test(
64 "--engine parakeet without parakeet-mlx asks the CLI for its Parakeet",
65 { skip: process.platform === "win32" },
66 () => {
67 const { result, args } = runScript("parakeet", "parakeet");
68 assert.match(args, /--engine parakeet --json/);
69 assert.equal(result.engine, "parakeet");
70 },
71);
72
73test(
74 "a failed --engine parakeet run reports the reason the CLI printed on stdout",
75 { skip: process.platform === "win32" },
76 () => {
77 const root = mkdtempSync(join(tmpdir(), "media-use-transcribe-"));
78 try {
79 const bin = join(root, "bin");
80 mkdirSync(bin);
81 const reason =
82 "Parakeet is not installed. Install it with: hyperframes models install parakeet";
83 writeFileSync(
84 join(bin, "npx"),
85 `#!/bin/sh\necho '{"ok":false,"error":"${reason}"}'\nexit 1\n`,
86 );
87 chmodSync(join(bin, "npx"), 0o755);
88 const input = join(root, "in.wav");
89 writeFileSync(input, "");
90 const script = fileURLToPath(new URL("./transcribe.mjs", import.meta.url));
91 const res = spawnSync(
92 process.execPath,
93 [script, "--input", input, "--engine", "parakeet", "--json"],
94 {
95 encoding: "utf8",
96 env: {
97 ...process.env,
98 HYPERFRAMES_PARAKEET: "",
99 PATH: `${bin}:${process.env.PATH}`,
100 HOME: root,
101 HYPERFRAMES_MEDIA_HOME: join(root, "home"),
102 HYPERFRAMES_NO_TELEMETRY: "1",
103 },
104 },
105 );
106 assert.equal(res.status, 1);
107 assert.match(JSON.parse(res.stdout.trim()).error, /hyperframes models install parakeet/);
108 } finally {
109 rmSync(root, { recursive: true, force: true });
110 }
111 },
112);