Open History to see the last commit
1import { assert, it } from "@effect/vitest";
2
3import {
4 applyPreferredCodexDefaultModel,
5 codexCustomEndpoint,
6 codexRoutesSpendNativeQuota,
7 mapCodexModelCapabilities,
8} from "./CodexProvider.ts";
9
10it("maps current Codex model capability fields", () => {
11 const capabilities = mapCodexModelCapabilities({
12 additionalSpeedTiers: [],
13 defaultReasoningEffort: "super-high",
14 description: "Test model",
15 displayName: "GPT Test",
16 hidden: false,
17 id: "gpt-test",
18 isDefault: true,
19 model: "gpt-test",
20 availableAccessPrograms: { cyber: ["standard", "daybreakBlue"] },
21 defaultServiceTier: "flex",
22 serviceTiers: [
23 {
24 id: "priority",
25 name: "Fast",
26 description: "Lower latency responses.",
27 },
28 {
29 id: "flex",
30 name: "Flex",
31 description: "Lower-cost asynchronous routing.",
32 },
33 ],
34 supportedReasoningEfforts: [
35 {
36 description: "Maximum reasoning",
37 reasoningEffort: "super-high",
38 },
39 ],
40 });
41
42 assert.deepStrictEqual(capabilities.optionDescriptors, [
43 {
44 id: "reasoningEffort",
45 label: "Reasoning",
46 type: "select",
47 options: [{ id: "super-high", label: "super-high", isDefault: true }],
48 currentValue: "super-high",
49 },
50 {
51 id: "serviceTier",
52 label: "Service Tier",
53 type: "select",
54 options: [
55 { id: "default", label: "Standard" },
56 {
57 id: "priority",
58 label: "Fast",
59 description: "Lower latency responses.",
60 },
61 {
62 id: "flex",
63 label: "Flex",
64 description: "Lower-cost asynchronous routing.",
65 isDefault: true,
66 },
67 ],
68 currentValue: "flex",
69 },
70 {
71 id: "cyberAccessProgram",
72 label: "Cyber Access",
73 type: "select",
74 options: [
75 { id: "standard", label: "Standard", isDefault: true },
76 { id: "daybreakBlue", label: "Daybreak Blue" },
77 ],
78 currentValue: "standard",
79 },
80 ]);
81});
82
83it("uses standard routing when the catalog has no default service tier", () => {
84 const capabilities = mapCodexModelCapabilities({
85 additionalSpeedTiers: ["fast"],
86 defaultReasoningEffort: "medium",
87 defaultServiceTier: null,
88 description: "Test model",
89 displayName: "GPT Test",
90 hidden: false,
91 id: "gpt-test",
92 isDefault: true,
93 model: "gpt-test",
94 serviceTiers: [
95 {
96 id: "priority",
97 name: "Fast",
98 description: "1.5x speed, increased usage",
99 },
100 {
101 id: "ultrafast",
102 name: "Ultrafast",
103 description: "The fastest available responses for latency-sensitive work.",
104 },
105 ],
106 supportedReasoningEfforts: [],
107 });
108
109 assert.deepStrictEqual(capabilities.optionDescriptors, [
110 {
111 id: "serviceTier",
112 label: "Service Tier",
113 type: "select",
114 options: [
115 { id: "default", label: "Standard", isDefault: true },
116 {
117 id: "priority",
118 label: "Fast",
119 description: "1.5x speed, increased usage",
120 },
121 {
122 id: "ultrafast",
123 label: "Ultrafast",
124 description: "Even faster, more expensive",
125 },
126 ],
127 currentValue: "default",
128 },
129 ]);
130});
131
132it("marks the most preferred available model as default", () => {
133 const models = applyPreferredCodexDefaultModel([
134 { slug: "gpt-5.6-terra", name: "GPT-5.6-Terra", isCustom: false, capabilities: null },
135 { slug: "gpt-5.4", name: "GPT-5.4", isCustom: false, isDefault: true, capabilities: null },
136 ]);
137
138 assert.deepStrictEqual(
139 models.map((model) => ({ slug: model.slug, isDefault: model.isDefault })),
140 [
141 { slug: "gpt-5.6-terra", isDefault: true },
142 { slug: "gpt-5.4", isDefault: undefined },
143 ],
144 );
145});
146
147it("ranks qualified Codex models while preserving their wire ids", () => {
148 const models = applyPreferredCodexDefaultModel([
149 {
150 slug: "openai.gpt-5.6-luna",
151 name: "Luna",
152 isCustom: false,
153 isDefault: true,
154 capabilities: null,
155 },
156 { slug: "openai.gpt-5.6-sol", name: "Sol", isCustom: false, capabilities: null },
157 ]);
158 assert.deepStrictEqual(
159 models.filter((model) => model.isDefault).map((model) => model.slug),
160 ["openai.gpt-5.6-sol"],
161 );
162});
163
164it("ignores custom models that shadow a preferred slug", () => {
165 const models = applyPreferredCodexDefaultModel([
166 { slug: "gpt-5.6-sol", name: "gpt-5.6-sol", isCustom: true, capabilities: null },
167 { slug: "gpt-5.4", name: "GPT-5.4", isCustom: false, isDefault: true, capabilities: null },
168 ]);
169
170 assert.deepStrictEqual(models.find((model) => model.isDefault)?.slug, "gpt-5.4");
171});
172
173it("reports native quota only for an OpenAI login on a native route", () => {
174 const chatgpt = { type: "chatgpt", email: "a@example.com", planType: "pro" } as const;
175 const hub = {
176 model_provider: "hub",
177 model_providers: { hub: { base_url: "https://hub.example.com/v1" } },
178 };
179 const cases = [
180 ["default route", chatgpt, true, {}, true],
181 ["openai base url", chatgpt, true, { openai_base_url: "https://chatgpt.com/x" }, true],
182 ["openai proxy url", chatgpt, true, { openai_base_url: "https://proxy.example.com" }, false],
183 ["custom provider", chatgpt, true, hub, false],
184 ["unknown provider id", chatgpt, true, { model_provider: "missing" }, false],
185 ["unreadable config", chatgpt, true, null, false],
186 ["login not required", chatgpt, false, {}, false],
187 ["api key", { type: "apiKey" }, true, {}, false],
188 ] as const;
189 for (const [name, account, requiresOpenaiAuth, config, expected] of cases) {
190 assert.strictEqual(
191 codexRoutesSpendNativeQuota({ account, requiresOpenaiAuth }, config),
192 expected,
193 name,
194 );
195 }
196 // The custom endpoint is what a usage-limit hub is matched against.
197 assert.strictEqual(codexCustomEndpoint(hub), "https://hub.example.com");
198 assert.strictEqual(
199 codexCustomEndpoint({ openai_base_url: "http://127.0.0.1:8317/v1" }),
200 "http://127.0.0.1:8317",
201 );
202 assert.strictEqual(codexCustomEndpoint({ openai_base_url: "https://chatgpt.com/x" }), undefined);
203 assert.strictEqual(codexCustomEndpoint({}), undefined);
204});