openclaw/test/scripts/codex-client-version-contract.test.ts
Ayaan Zaidi cbaa9abada
feat(codex): prefer newer installed Codex for ChatGPT discovery (#168228)
Prefer a validated newer stable same-major Codex CLI on PATH for managed turns, and carry the selected client version into ChatGPT model discovery. Return to the bundled runtime when it catches up or the installed candidate fails qualification/startup.

Bound cold selection, retain shared fallback ownership and explicit/desktop precedence, isolate probe storage, and skip selection for unrelated catalog and auth-only requests.

Production-authenticated ChatGPT discovery and turns remain unproven; same-major post-initialize protocol compatibility is an accepted residual risk.

Co-authored-by: obviyus <22031114+obviyus@users.noreply.github.com>
Co-authored-by: steipete <58493+steipete@users.noreply.github.com>
2026-10-10 18:07:11 +00:00

34 lines
1.4 KiB
TypeScript

// Codex Client Version Contract tests: ChatGPT model discovery reports the
// version of the Codex binary that runs turns (#113615).
import fs from "node:fs";
import { describe, expect, it } from "vitest";
const CODEX_PACKAGE_JSON_URL = new URL("../../extensions/codex/package.json", import.meta.url);
const OPENAI_PROVIDER_URL = new URL("../../extensions/openai/base-url.ts", import.meta.url);
const OPENAI_CODEX_CLIENT_VERSION_PATTERN = /^const OPENAI_CODEX_CLIENT_VERSION = "([^"]+)";$/mu;
function readManagedCodexVersion(): string {
const packageJson = JSON.parse(fs.readFileSync(CODEX_PACKAGE_JSON_URL, "utf8")) as {
dependencies?: Record<string, unknown>;
};
const version = packageJson.dependencies?.["@openai/codex"];
if (typeof version !== "string") {
throw new Error("extensions/codex/package.json must pin @openai/codex exactly");
}
return version;
}
function readOpenAICodexClientVersion(): string {
const providerSource = fs.readFileSync(OPENAI_PROVIDER_URL, "utf8");
const version = OPENAI_CODEX_CLIENT_VERSION_PATTERN.exec(providerSource)?.[1];
if (!version) {
throw new Error("extensions/openai/base-url.ts must declare the Codex client version");
}
return version;
}
describe("Codex client version contract", () => {
it("matches OpenAI model discovery to the managed Codex package", () => {
expect(readOpenAICodexClientVersion()).toBe(readManagedCodexVersion());
});
});