|
| 1 | +import { test } from "node:test"; |
| 2 | +import assert from "node:assert/strict"; |
| 3 | +import { localTtsGenerate } from "./tts-local-provider.mjs"; |
| 4 | + |
| 5 | +// Regression: on Windows, a bare "npx" is npx.cmd, which execFileSync cannot |
| 6 | +// exec — the Kokoro delegation failed with `spawnSync npx ENOENT` instead of |
| 7 | +// synthesizing (or cleanly falling through to the next provider). The spawn |
| 8 | +// must route through node + npx-cli.js on win32, same as the audio engine's |
| 9 | +// TTS spawns (see ../../audio/scripts/lib/tts.spawn.test.mjs). |
| 10 | + |
| 11 | +const envWithNpxCli = { |
| 12 | + npm_execpath: "C:/Program Files/nodejs/node_modules/npm/bin/npm-cli.js", |
| 13 | + npm_node_execpath: "C:/Program Files/nodejs/node.exe", |
| 14 | +}; |
| 15 | +const npxCliPath = "C:/Program Files/nodejs/node_modules/npm/bin/npx-cli.js"; |
| 16 | +const pathExists = (path) => path === npxCliPath; |
| 17 | + |
| 18 | +test("win32: routes the hyperframes tts call through node + npx-cli, never bare npx", async () => { |
| 19 | + const captured = []; |
| 20 | + const fakeExec = (cmd, args, opts) => { |
| 21 | + captured.push({ cmd, args, opts }); |
| 22 | + // Synthesize nothing — the provider then returns null via the |
| 23 | + // missing-output check, which is fine: we only assert the spawn shape. |
| 24 | + }; |
| 25 | + |
| 26 | + await localTtsGenerate( |
| 27 | + "hello there", |
| 28 | + { voice: "am_michael" }, |
| 29 | + "win32", |
| 30 | + fakeExec, |
| 31 | + envWithNpxCli, |
| 32 | + pathExists, |
| 33 | + ); |
| 34 | + |
| 35 | + assert.equal(captured.length, 1); |
| 36 | + assert.equal(captured[0].cmd, envWithNpxCli.npm_node_execpath); |
| 37 | + assert.equal(captured[0].args[0], npxCliPath); |
| 38 | + assert.deepEqual(captured[0].args.slice(1, 4), ["hyperframes", "tts", "hello there"]); |
| 39 | + assert.ok(captured[0].args.includes("--voice")); |
| 40 | + // execFileSync options survive the rerouting (pipes are what let the caller |
| 41 | + // read the "kokoro-onnx not installed" hint back out). |
| 42 | + assert.deepEqual(captured[0].opts.stdio, ["ignore", "pipe", "pipe"]); |
| 43 | +}); |
| 44 | + |
| 45 | +test("win32 without a resolvable npx-cli: falls through to the next provider (null), no spawn", async () => { |
| 46 | + const captured = []; |
| 47 | + const fakeExec = (...call) => captured.push(call); |
| 48 | + |
| 49 | + const result = await localTtsGenerate( |
| 50 | + "hello", |
| 51 | + {}, |
| 52 | + "win32", |
| 53 | + fakeExec, |
| 54 | + {}, // no npm_execpath, and pathExists finds nothing |
| 55 | + () => false, |
| 56 | + ); |
| 57 | + |
| 58 | + assert.equal(result, null); |
| 59 | + assert.equal(captured.length, 0); |
| 60 | +}); |
| 61 | + |
| 62 | +test("non-win32: spawns plain npx unchanged", async () => { |
| 63 | + const captured = []; |
| 64 | + const fakeExec = (cmd, args) => captured.push({ cmd, args }); |
| 65 | + |
| 66 | + await localTtsGenerate("hola", { lang: "es" }, "darwin", fakeExec, {}, () => false); |
| 67 | + |
| 68 | + assert.equal(captured.length, 1); |
| 69 | + assert.equal(captured[0].cmd, "npx"); |
| 70 | + assert.deepEqual(captured[0].args.slice(0, 3), ["hyperframes", "tts", "hola"]); |
| 71 | + assert.ok(captured[0].args.includes("--lang")); |
| 72 | +}); |
0 commit comments