test(cli): cover the npm cancel signal and decode timeout, and fix a doubled period

The Parakeet failure line printed "failed.. To repair" when the decoder's
own message ended in a period. Tests now also pin that Ctrl-C reaches the
npm install and that the decode timeout scales with the audio length.
This commit is contained in:
Miguel Ángel
2026-09-27 01:43:50 -04:00
parent cfd129d9c3
commit de0e992075
3 changed files with 24 additions and 5 deletions
+19 -3
View File
@@ -7,10 +7,11 @@ import { CliRuntimeError, consumeCommandResult } from "../utils/commandResult.js
// Make the whisper core report "unavailable" so we exercise the soft-skip path.
const transcribeMock = vi.fn();
let audioSeconds = 1;
vi.mock("../whisper/transcribe.js", () => ({
transcribe: transcribeMock,
prepareWav: (input: string) => input,
getPreparedWavDurationSeconds: () => 1,
getPreparedWavDurationSeconds: () => audioSeconds,
}));
// Engine selection: which runners look installed, and the sherpa decode child it spawns.
@@ -207,12 +208,12 @@ describe("transcribe command", () => {
});
it("an explicit --engine parakeet fails with the Parakeet error instead of falling back", async () => {
crashChild("SIGABRT", "Protobuf parsing failed\n");
crashChild("SIGABRT", "Protobuf parsing failed.\n");
Object.assign(runners, { sherpa: true, mlx: false });
const { exitCode, out } = await transcribeFails("parakeet");
expect(exitCode).toBe(1);
expect(out.error).toMatch(
/^Parakeet failed: .*Protobuf.*hyperframes models install parakeet$/,
/^Parakeet failed: .*Protobuf parsing failed\. To repair it, run: hyperframes models install parakeet$/,
);
expect(transcribeMock).not.toHaveBeenCalled();
});
@@ -236,6 +237,21 @@ describe("transcribe command", () => {
expect(transcribeMock).not.toHaveBeenCalled();
});
it("gives the decode at least 30 minutes, and twice the audio length", async () => {
Object.assign(runners, { sherpa: true, mlx: false });
for (const [seconds, timeout] of [
[60, 1_800_000],
[3600, 7_200_000],
]) {
audioSeconds = seconds!;
const { dir, input } = dummyAudio();
dirs.push(dir);
await transcribeCmd.run!({ args: { input, json: true, engine: "auto" } } as never);
expect(execFileMock.mock.calls.at(-1)?.[2]).toMatchObject({ timeout });
}
audioSeconds = 1;
});
it("succeeds with 0 words when the audio has no speech", async () => {
execFileMock.mockImplementation((_cmd, _args, _opts, done) => {
done(null, `HYPERFRAMES_PARAKEET_RESULT:${JSON.stringify([])}\n`, "");
+2 -1
View File
@@ -341,7 +341,8 @@ async function transcribeAudio(
result = await run(runner);
} catch (err) {
if (runner !== "sherpa" || err instanceof DecodeCancelled) throw err;
const parakeetError = `Parakeet failed: ${normalizeErrorMessage(err)}. To repair it, run: hyperframes models install parakeet`;
const reason = normalizeErrorMessage(err).replace(/\.+$/, "");
const parakeetError = `Parakeet failed: ${reason}. To repair it, run: hyperframes models install parakeet`;
if (!parakeetFallsBack(engine)) throw new Error(parakeetError);
runner = pickRunner(engine, () => false);
spin?.clear();
+3 -1
View File
@@ -45,7 +45,9 @@ describe("installSherpaRuntime", () => {
const run = vi.fn(async (_args: string[]) => {
throw new Error("stop before touching the cache");
});
await installSherpaRuntime({ run }).catch(() => undefined);
const cancel = new AbortController();
await installSherpaRuntime({ run, signal: cancel.signal }).catch(() => undefined);
expect((run.mock.calls[0] as unknown[] | undefined)?.[1]).toBe(cancel.signal);
const args = run.mock.calls[0]?.[0] as string[] | undefined;
expect(args).toContain("sherpa-onnx-node@1.13.8");
expect(args).toContain(sherpaPlatformPackage());