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