Skip to content

Commit 89695c5

Browse files
committed
fix(cli): report a broken Parakeet runtime with the repair instead of skipping it
1 parent ace5308 commit 89695c5

2 files changed

Lines changed: 43 additions & 3 deletions

File tree

‎packages/cli/src/whisper/sherpa.test.ts‎

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
import { createHash } from "node:crypto";
2-
import { existsSync, mkdirSync, mkdtempSync, readdirSync, rmSync, writeFileSync } from "node:fs";
2+
import {
3+
existsSync,
4+
mkdirSync,
5+
mkdtempSync,
6+
readdirSync,
7+
rmSync,
8+
truncateSync,
9+
writeFileSync,
10+
} from "node:fs";
311
import { tmpdir } from "node:os";
412
import { basename, dirname, join } from "node:path";
513
import { afterEach, describe, expect, it, vi } from "vitest";
@@ -89,6 +97,35 @@ describe("installSherpaRuntime", () => {
8997
});
9098
});
9199

100+
describe("sherpaParakeetInstalled", () => {
101+
it("counts a runtime missing its native binary, so transcribe reports it instead of skipping it", async () => {
102+
const home = mkdtempSync(join(tmpdir(), "hf-sherpa-home-"));
103+
vi.stubEnv("HOME", home);
104+
vi.resetModules();
105+
try {
106+
const sherpa = await import("./sherpa.js");
107+
const manifest = join(sherpa.SHERPA_RUNTIME_DIR, "node_modules", "sherpa-onnx-node");
108+
mkdirSync(manifest, { recursive: true });
109+
writeFileSync(join(manifest, "package.json"), "{}");
110+
mkdirSync(sherpa.PARAKEET_MODEL_DIR, { recursive: true });
111+
for (const [name, bytes] of [
112+
["encoder.int8.onnx", 652_184_281],
113+
["decoder.int8.onnx", 11_845_275],
114+
["joiner.int8.onnx", 6_355_277],
115+
["tokens.txt", 93_939],
116+
] as const) {
117+
writeFileSync(join(sherpa.PARAKEET_MODEL_DIR, name), "");
118+
truncateSync(join(sherpa.PARAKEET_MODEL_DIR, name), bytes);
119+
}
120+
expect(sherpa.sherpaRuntimeInstalled()).toBe(false);
121+
expect(sherpa.sherpaParakeetInstalled()).toBe(true);
122+
} finally {
123+
vi.unstubAllEnvs();
124+
rmSync(home, { recursive: true, force: true });
125+
}
126+
});
127+
});
128+
92129
describe("ensureParakeetModel", () => {
93130
let dir: string;
94131
afterEach(() => rmSync(dir, { recursive: true, force: true }));

‎packages/cli/src/whisper/sherpa.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,13 @@ export function installSherpaRuntime({
135135
return install(dir, RUNTIME, RUNTIME_VERSION, (args) => run([...args, native], signal));
136136
}
137137

138-
/** Sizes only: hashing 650 MB on every transcribe is too slow, and install already verified them. */
138+
/**
139+
* Model sizes only (install verified the hashes). The runtime counts once its manifest is there, even
140+
* if broken: transcribe must then fail with the repair, not quietly pick whisper.
141+
*/
139142
export function sherpaParakeetInstalled(): boolean {
140143
return (
141-
sherpaRuntimeInstalled() &&
144+
isInstalled(SHERPA_RUNTIME_DIR, RUNTIME) &&
142145
PARAKEET_MODEL_FILES.every(
143146
(f) =>
144147
statSync(join(PARAKEET_MODEL_DIR, f.name), { throwIfNoEntry: false })?.size === f.bytes,

0 commit comments

Comments
 (0)