Skip to content
Merged
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
24 changes: 24 additions & 0 deletions apps/server/src/provider/providerSnapshot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process";

import {
isCommandMissingCause,
parseGenericCliVersion,
providerModelsFromSettings,
spawnAndCollect,
} from "./providerSnapshot.ts";
Expand Down Expand Up @@ -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(
Expand Down
8 changes: 7 additions & 1 deletion apps/server/src/provider/providerSnapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Loading