Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

CodexProvider.test.ts

184 lines5.3 KB

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