Open History to see the last commit
1import { describe, expect, it } from "vitest";
2
3import {
4 MINIMUM_CODEX_CLI_VERSION,
5 compareCodexCliVersions,
6 formatCodexCliUpgradeMessage,
7 isCodexCliVersionSupported,
8 parseCodexCliVersion,
9} from "./codexCliVersion.ts";
10
11describe("parseCodexCliVersion", () => {
12 it("extracts and normalizes supported version strings from CLI output", () => {
13 expect(parseCodexCliVersion("codex 0.37\n")).toBe("0.37.0");
14 expect(parseCodexCliVersion("Codex CLI v0.37.1\nbuild abc123")).toBe("0.37.1");
15 expect(parseCodexCliVersion("version: 0.37.0-beta.2")).toBe("0.37.0-beta.2");
16 });
17
18 it("returns null when CLI output does not contain a valid semver", () => {
19 expect(parseCodexCliVersion("codex version unknown")).toBeNull();
20 expect(parseCodexCliVersion("codex 0.37.0.1")).toBeNull();
21 });
22});
23
24describe("compareCodexCliVersions", () => {
25 it("compares normalized release versions numerically", () => {
26 expect(compareCodexCliVersions("0.37", "0.37.0")).toBe(0);
27 expect(compareCodexCliVersions("0.37.1", "0.37.0")).toBeGreaterThan(0);
28 expect(compareCodexCliVersions("0.36.9", "0.37.0")).toBeLessThan(0);
29 });
30
31 it("orders prerelease versions before the final release", () => {
32 expect(compareCodexCliVersions("0.37.0-beta.1", "0.37.0")).toBeLessThan(0);
33 expect(compareCodexCliVersions("0.37.0-beta.2", "0.37.0-beta.10")).toBeLessThan(0);
34 expect(compareCodexCliVersions("0.37.0-rc.1", "0.37.0-beta.10")).toBeGreaterThan(0);
35 });
36});
37
38describe("isCodexCliVersionSupported", () => {
39 it("uses the minimum supported version threshold", () => {
40 expect(isCodexCliVersionSupported(MINIMUM_CODEX_CLI_VERSION)).toBe(true);
41 expect(isCodexCliVersionSupported("0.37")).toBe(true);
42 expect(isCodexCliVersionSupported("0.36.9")).toBe(false);
43 expect(isCodexCliVersionSupported("0.37.0-beta.1")).toBe(false);
44 });
45});
46
47describe("formatCodexCliUpgradeMessage", () => {
48 it("formats upgrade guidance for detected and unknown versions", () => {
49 expect(formatCodexCliUpgradeMessage("0.36.0")).toBe(
50 "Codex CLI v0.36.0 is too old for T3 Code. Upgrade to v0.37.0 or newer and restart T3 Code.",
51 );
52 expect(formatCodexCliUpgradeMessage(null)).toBe(
53 "The installed Codex CLI version is too old for T3 Code. Upgrade to v0.37.0 or newer and restart T3 Code.",
54 );
55 });
56});