Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(claude): on Windows check the version and help of the copy the turn's PATH finds, by its path

AdityaUmalef174b788725d
diff --git a/server/cli-version-probe.test.ts b/server/cli-version-probe.test.ts
index bfe90fd291..9022adf5d9 100644
--- a/server/cli-version-probe.test.ts
+++ b/server/cli-version-probe.test.ts
@@ -3,6 +3,7 @@ import { tmpdir } from "node:os";
import { delimiter, join } from "node:path";
import { afterEach, expect, it, vi } from "vitest";
import { cliToLaunch, cliVersionProbe } from "./cli-version-probe.ts";
+import { findCliCandidates } from "./env-path.ts";
import { cliVersionReader, type execCli } from "./procs.ts";
afterEach(() => vi.useRealTimers());
@@ -118,3 +119,18 @@ it("launches the checked copy by its path on Windows, where spawn resolves the a
expect(cliToLaunch("claude", undefined, "win32")).toBe("claude"); // nothing found on the turn's PATH: unchanged
for (const platform of ["darwin", "linux"] as const) expect(cliToLaunch("claude", "/opt/homebrew/bin/claude", platform)).toBe("claude"); // POSIX spawn already uses the turn's PATH
});
+
+it("checks the version of the copy the caller's PATH finds, by its path on Windows, so a PATH change cannot swap the copy mid-check", async () => {
+ const root = mkdtempSync(join(tmpdir(), "omb-cli-probe-win-"));
+ try {
+ for (const file of ["claude", "claude.cmd"]) writeFileSync(join(root, file), "");
+ const checked = findCliCandidates("claude", root)[0];
+ const run = vi.fn<typeof execCli>((_cli, _args, _options, callback) => callback(null, "2.1.321"));
+ expect(await cliVersionProbe("claude", run, "win32")({ PATH: root })).toEqual({ version: "2.1.321" });
+ expect(run.mock.calls[0]?.[0]).toBe(checked); // execCli on Windows resolves a bare name with the app's PATH
+ expect(await cliVersionProbe("claude", run, "linux")({ PATH: root })).toEqual({ version: "2.1.321" });
+ expect(run.mock.calls[1]?.[0]).toBe("claude"); // POSIX lookups already use the caller's PATH
+ } finally {
+ rmSync(root, { recursive: true, force: true });
+ }
+});
diff --git a/server/cli-version-probe.ts b/server/cli-version-probe.ts
index 5067fc4f7b..21cd1520e6 100644
--- a/server/cli-version-probe.ts
+++ b/server/cli-version-probe.ts
@@ -8,7 +8,7 @@ export function cliToLaunch(cli: string, checked: string | undefined, platform:
// Shares version checks and retries empty responses. A failed check falls back to the last version only while PATH
// still finds the same copy of the CLI, so a newly found copy is never reported with another copy's version.
-export function cliVersionProbe(cli: string, run: typeof execCli = execCli) {
+export function cliVersionProbe(cli: string, run: typeof execCli = execCli, platform: NodeJS.Platform = process.platform) {
let read = cliVersionReader(cli), readAt: string | undefined;
let pending: { path: string | undefined; probe: Promise<ReturnType<typeof read>> } | undefined; // shared only by callers with the same PATH
return (env: NodeJS.ProcessEnv): Promise<ReturnType<typeof read>> => {
@@ -18,7 +18,7 @@ export function cliVersionProbe(cli: string, run: typeof execCli = execCli) {
const reader = read;
const deadline = Date.now() + CLI_VERSION_TIMEOUT_MS;
const attempt = () => new Promise<{ error: Error | null; stdout: string }>((resolve) => {
- run(cli, ["--version"], { timeout: Math.max(1, deadline - Date.now()), env }, (error, stdout) => resolve({ error, stdout }));
+ run(cliToLaunch(cli, at, platform), ["--version"], { timeout: Math.max(1, deadline - Date.now()), env }, (error, stdout) => resolve({ error, stdout }));
});
const entry: NonNullable<typeof pending> = { path: env.PATH, probe: (async () => {
let result = await attempt();
diff --git a/server/drivers/claude.ts b/server/drivers/claude.ts
index 042b02bd68..3425b298ef 100644
--- a/server/drivers/claude.ts
+++ b/server/drivers/claude.ts
@@ -817,7 +817,7 @@ export const ClaudeDriver: ProviderDriver<ClaudeConfig> = {
const read = {
version,
done: new Promise<string | null>((resolve) => {
- execCli(config.cli, ["--help"], { timeout: 8000, env }, (err, stdout) => resolve(err ? null : stdout));
+ execCli(cliToLaunch(config.cli, findCliCandidates(config.cli, env.PATH ?? "")[0]), ["--help"], { timeout: 8000, env }, (err, stdout) => resolve(err ? null : stdout)); // on Windows the copy this env finds, not the app PATH's
}).then((help) => { // a read another copy's read or a failed re-probe replaced since must not bring back its flags
if (helpRead === read) [cliHasAutocompact, cliHelpVersion, helpRead] = [help === null ? null : !autocompactRefusedBy.has(version) && /^\s*--autocompact\b/m.test(help), version, null];
}),