|
1 | 1 | import { strict as assert } from "node:assert"; |
2 | 2 | import { test } from "node:test"; |
3 | 3 | import { mkdtempSync, mkdirSync, readFileSync, rmSync, existsSync, writeFileSync } from "node:fs"; |
| 4 | +import { spawnSync } from "node:child_process"; |
4 | 5 | import { join, dirname } from "node:path"; |
5 | 6 | import { tmpdir } from "node:os"; |
6 | 7 | import { fileURLToPath } from "node:url"; |
@@ -124,3 +125,35 @@ test("two effects never share a file when one's name is taken by the person, run |
124 | 125 | rmSync(dir, { recursive: true, force: true }); |
125 | 126 | } |
126 | 127 | }); |
| 128 | + |
| 129 | +// The engine owns speed parsing; a fallback before the check would turn 0 or junk into 1. |
| 130 | +function runEngineWith(request, ...args) { |
| 131 | + const dir = mkdtempSync(join(tmpdir(), "audio-speed-range-")); |
| 132 | + try { |
| 133 | + writeFileSync(join(dir, "audio_request.json"), JSON.stringify({ lines: [], ...request })); |
| 134 | + return spawnSync(process.execPath, [join(HERE, "audio.mjs"), "--hyperframes", dir, ...args], { |
| 135 | + encoding: "utf8", |
| 136 | + }); |
| 137 | + } finally { |
| 138 | + rmSync(dir, { recursive: true, force: true }); |
| 139 | + } |
| 140 | +} |
| 141 | + |
| 142 | +for (const [label, request, args, shown] of [ |
| 143 | + ["request speed 5", { speed: 5 }, [], "5"], |
| 144 | + ["request speed 0", { speed: 0 }, [], "0"], |
| 145 | + ["request speed -1", { speed: -1 }, [], "-1"], |
| 146 | + ["request speed text", { speed: "fast" }, [], '"fast"'], |
| 147 | + ["--speed 0", {}, ["--speed", "0"], '"0"'], |
| 148 | + ["--speed text", { speed: 1 }, ["--speed", "abc"], '"abc"'], |
| 149 | +]) { |
| 150 | + test(`${label} stops the engine before any TTS runs`, () => { |
| 151 | + const r = runEngineWith(request, ...args); |
| 152 | + assert.equal(r.status, 1); |
| 153 | + assert.ok(r.stderr.includes(`speed must be above 0 and at most 3, got ${shown}`), r.stderr); |
| 154 | + }); |
| 155 | +} |
| 156 | + |
| 157 | +test("a numeric string speed, as the adapters forward it, passes the check", () => { |
| 158 | + assert.doesNotMatch(runEngineWith({ speed: "0.8" }, "--only", "tts").stderr, /speed must/); |
| 159 | +}); |
0 commit comments