-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix(cli): treat missing whisper-cpp as a skippable prerequisite, not a command failure #1628
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
miguel-heygen
merged 1 commit into
main
from
fix/transcribe-fail-soft-whisper-unavailable
Jun 22, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import { describe, it, expect, vi, beforeEach, afterEach } from "vitest"; | ||
| import { writeFileSync, mkdtempSync, rmSync } from "node:fs"; | ||
| import { join } from "node:path"; | ||
| import { tmpdir } from "node:os"; | ||
| import { WhisperUnavailableError } from "../whisper/manager.js"; | ||
|
|
||
| // Make the whisper core report "unavailable" so we exercise the soft-skip path. | ||
| const transcribeMock = vi.fn(); | ||
| vi.mock("../whisper/transcribe.js", () => ({ transcribe: transcribeMock })); | ||
|
|
||
| const trackTranscribeUnavailable = vi.fn(); | ||
| const trackCommandFailure = vi.fn(); | ||
| vi.mock("../telemetry/events.js", () => ({ | ||
| trackTranscribeUnavailable: (...a: unknown[]) => trackTranscribeUnavailable(...a), | ||
| trackCommandFailure: (...a: unknown[]) => trackCommandFailure(...a), | ||
| })); | ||
|
|
||
| import transcribeCmd from "./transcribe.js"; | ||
|
|
||
| function dummyAudio(): { dir: string; input: string } { | ||
| const dir = mkdtempSync(join(tmpdir(), "hf-transcribe-test-")); | ||
| const input = join(dir, "narration.wav"); | ||
| writeFileSync(input, "not-real-audio"); | ||
| return { dir, input }; | ||
| } | ||
|
|
||
| describe("transcribe — whisper unavailable", () => { | ||
| let dirs: string[] = []; | ||
| let priorExitCode: typeof process.exitCode; | ||
|
|
||
| beforeEach(() => { | ||
| dirs = []; | ||
| priorExitCode = process.exitCode; | ||
| process.exitCode = undefined; | ||
| transcribeMock.mockReset(); | ||
| trackTranscribeUnavailable.mockReset(); | ||
| trackCommandFailure.mockReset(); | ||
| transcribeMock.mockRejectedValue( | ||
| new WhisperUnavailableError("whisper-cpp not found. Install: brew install whisper-cpp"), | ||
| ); | ||
| vi.spyOn(console, "log").mockImplementation(() => {}); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| process.exitCode = priorExitCode; | ||
| for (const d of dirs) rmSync(d, { recursive: true, force: true }); | ||
| vi.restoreAllMocks(); | ||
| }); | ||
|
|
||
| it("explicit run exits non-zero and is NOT reported as a command failure", async () => { | ||
| const { dir, input } = dummyAudio(); | ||
| dirs.push(dir); | ||
| await transcribeCmd.run!({ args: { input, json: true, optional: false } } as never); | ||
|
|
||
| expect(process.exitCode).toBe(1); | ||
| expect(trackTranscribeUnavailable).toHaveBeenCalledWith({ optional: false }); | ||
| expect(trackCommandFailure).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("--optional skips cleanly with exit 0", async () => { | ||
| const { dir, input } = dummyAudio(); | ||
| dirs.push(dir); | ||
| await transcribeCmd.run!({ args: { input, json: true, optional: true } } as never); | ||
|
|
||
| expect(process.exitCode).toBe(0); | ||
| expect(trackTranscribeUnavailable).toHaveBeenCalledWith({ optional: true }); | ||
| expect(trackCommandFailure).not.toHaveBeenCalled(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import { describe, it, expect } from "vitest"; | ||
| import { WhisperUnavailableError, isWhisperUnavailable } from "./manager.js"; | ||
|
|
||
| describe("isWhisperUnavailable", () => { | ||
| it("recognizes WhisperUnavailableError instances", () => { | ||
| const err = new WhisperUnavailableError( | ||
| "whisper-cpp not found. Install: brew install whisper-cpp", | ||
| ); | ||
| expect(isWhisperUnavailable(err)).toBe(true); | ||
| expect(err.code).toBe("WHISPER_UNAVAILABLE"); | ||
| expect(err.name).toBe("WhisperUnavailableError"); | ||
| }); | ||
|
|
||
| it("recognizes a plain Error carrying the WHISPER_UNAVAILABLE code (cross-bundle safety)", () => { | ||
| const err = Object.assign(new Error("nope"), { code: "WHISPER_UNAVAILABLE" }); | ||
| expect(isWhisperUnavailable(err)).toBe(true); | ||
| }); | ||
|
|
||
| it("does NOT classify a genuine transcription failure as unavailable", () => { | ||
| // whisper present but the run crashed — must stay a real command failure. | ||
| expect(isWhisperUnavailable(new Error("Command failed: whisper-cli exited with code 1"))).toBe( | ||
| false, | ||
| ); | ||
| expect(isWhisperUnavailable(new Error("whisper-cpp build failed. Ensure cmake..."))).toBe( | ||
| false, | ||
| ); | ||
| expect(isWhisperUnavailable("whisper-cpp not found")).toBe(false); | ||
| expect(isWhisperUnavailable(undefined)).toBe(false); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.