Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions packages/cli/src/whisper/manager.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
import { describe, it, expect } from "vitest";
import { WhisperUnavailableError, isWhisperUnavailable } from "./manager.js";
import { chmodSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { afterEach, describe, expect, it } from "vitest";
import { findWhisper, WhisperUnavailableError, isWhisperUnavailable } from "./manager.js";

const originalPath = process.env["PATH"];
const tempDirs: string[] = [];

afterEach(() => {
process.env["PATH"] = originalPath;
for (const dir of tempDirs) rmSync(dir, { recursive: true, force: true });
tempDirs.length = 0;
});

describe("findWhisper", () => {
it.runIf(process.platform !== "win32")(
"does not mistake Python openai-whisper for whisper.cpp",
() => {
const dir = mkdtempSync(join(tmpdir(), "hyperframes-whisper-path-"));
tempDirs.push(dir);
const pythonWhisper = join(dir, "whisper");
writeFileSync(pythonWhisper, "#!/bin/sh\necho 'OpenAI Whisper Python CLI'\n");
chmodSync(pythonWhisper, 0o755);
process.env["PATH"] = `${dir}:/usr/bin:/bin`;

const result = findWhisper();

expect(result?.executablePath).not.toBe(pythonWhisper);
},
);
});

describe("isWhisperUnavailable", () => {
it("recognizes WhisperUnavailableError instances", () => {
Expand Down
9 changes: 5 additions & 4 deletions packages/cli/src/whisper/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ function findFromEnv(): WhisperResult | undefined {
}

function findFromSystem(): WhisperResult | undefined {
for (const name of ["whisper-cli", "whisper"]) {
const path = whichBinary(name);
if (path) return { executablePath: path, source: "system" };
}
// `whisper` is also the executable installed by Python's openai-whisper
// package. It accepts a different flag set from whisper.cpp, so treating it
// as a compatible fallback causes transcription to fail after discovery.
const path = whichBinary("whisper-cli");
if (path) return { executablePath: path, source: "system" };

// Check brew paths directly on macOS
if (platform() === "darwin") {
Expand Down
Loading