mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-23 11:29:54 +00:00
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:
@@ -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`, "");
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user