fix(server): parse CLI versions with a "v" prefix (#11738)

This commit is contained in:
NikodemNowak authored and GitHub committed 2026-09-14 09:15:45 -07:00
1 parent ae67c5b815
commit 955b787e6b
2 files changed
+31 -1

No files matched your search

@@ -11,6 +11,7 @@ import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process";
import {
isCommandMissingCause,
parseGenericCliVersion,
providerModelsFromSettings,
spawnAndCollect,
} from "./providerSnapshot.ts";
@@ -93,6 +94,29 @@ describe("providerModelsFromSettings", () => {
});
});
describe("parseGenericCliVersion", () => {
it("parses a bare version", () => {
expect(parseGenericCliVersion("1.14.19")).toBe("1.14.19");
});
it("parses a v-prefixed version", () => {
expect(parseGenericCliVersion("opencode v2.0.3")).toBe("2.0.3");
expect(parseGenericCliVersion("v22.19.0")).toBe("22.19.0");
});
it("parses a version embedded in other output", () => {
expect(parseGenericCliVersion("codex-cli 0.53.0 (build abc)")).toBe("0.53.0");
});
it("returns null when no version is present", () => {
expect(parseGenericCliVersion("no version here")).toBeNull();
});
it("ignores versions glued to other word characters", () => {
expect(parseGenericCliVersion("build2.0.3artifact")).toBeNull();
});
});
describe("ProviderCommandNotFoundError", () => {
it("classifies normalized platform failures without parsing messages", () => {
expect(
+7 -1
View File
@@ -107,8 +107,14 @@ export const spawnAndCollect = (binaryPath: string, command: ChildProcess.Comman
return result;
}).pipe(Effect.scoped);
/**
* Return the first semantic version found in CLI output, or null. Accepts a
* leading "v" (for example `opencode v2.0.3`).
*/
export function parseGenericCliVersion(output: string): string | null {
const match = output.match(/\b(\d+\.\d+\.\d+)\b/);
// "opencode v2.0.3"-style output: the optional "v" has to be consumed first,
// since "v2" itself contains no word boundary.
const match = output.match(/\bv?(\d+\.\d+\.\d+)\b/);
return match?.[1] ?? null;
}