Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2import {
3 ProviderInstanceId,
4 ProviderDriverKind,
5 type ProviderOptionDescriptor,
6} from "@t3tools/contracts";
7import { buildTraitsTriggerDisplay, buildUnavailableModelOptionDescriptors } from "./TraitsPicker";
8
9function selectDescriptor(
10 id: string,
11 options: ReadonlyArray<{ id: string; label: string; isDefault?: boolean }>,
12 currentValue: string,
13): Extract<ProviderOptionDescriptor, { type: "select" }> {
14 return { id, label: id, type: "select", options: [...options], currentValue };
15}
16
17function fastModeDescriptor(
18 currentValue: boolean,
19): Extract<ProviderOptionDescriptor, { type: "boolean" }> {
20 return { id: "fastMode", label: "Fast Mode", type: "boolean", currentValue };
21}
22
23function serviceTierDescriptor(
24 currentValue: "default" | "priority" | "ultrafast" | "flex",
25): Extract<ProviderOptionDescriptor, { type: "select" }> {
26 return {
27 id: "serviceTier",
28 label: "Service Tier",
29 type: "select",
30 options: [
31 { id: "default", label: "Standard", isDefault: true },
32 { id: "priority", label: "Fast" },
33 { id: "ultrafast", label: "Ultrafast" },
34 { id: "flex", label: "Flex" },
35 ],
36 currentValue,
37 };
38}
39
40const EFFORT = selectDescriptor(
41 "reasoningEffort",
42 [
43 { id: "high", label: "High" },
44 { id: "max", label: "Max" },
45 ],
46 "high",
47);
48const CONTEXT_WINDOW = selectDescriptor(
49 "contextWindow",
50 [
51 { id: "200k", label: "200k" },
52 { id: "1m", label: "1M" },
53 ],
54 "1m",
55);
56
57const CODEX = ProviderDriverKind.make("codex");
58
59function display(descriptors: ReadonlyArray<ProviderOptionDescriptor>) {
60 return buildTraitsTriggerDisplay({
61 provider: CODEX,
62 descriptors,
63 primarySelectDescriptorId: "reasoningEffort",
64 ultrathinkPromptControlled: false,
65 });
66}
67
68describe("buildTraitsTriggerDisplay", () => {
69 it("omits fast mode from the label entirely when it is off", () => {
70 expect(display([EFFORT, fastModeDescriptor(false), CONTEXT_WINDOW])).toEqual({
71 label: "High · 1M",
72 });
73 });
74
75 it("pairs fast mode with reasoning before the context window", () => {
76 expect(display([EFFORT, fastModeDescriptor(true), CONTEXT_WINDOW])).toEqual({
77 label: "High Fast · 1M",
78 });
79 expect(display([EFFORT, CONTEXT_WINDOW, fastModeDescriptor(true)])).toEqual({
80 label: "High Fast · 1M",
81 });
82 });
83
84 it.each(["reasoningEffort", "reasoning", "effort", "variant", "thinking"])(
85 "pairs Fast with %s even when context is the primary select",
86 (id) => {
87 for (const speed of [fastModeDescriptor(true), serviceTierDescriptor("priority")]) {
88 expect(
89 buildTraitsTriggerDisplay({
90 provider: CODEX,
91 descriptors: [
92 selectDescriptor("profile", [{ id: "balanced", label: "Balanced" }], "balanced"),
93 CONTEXT_WINDOW,
94 { ...EFFORT, id },
95 speed,
96 ],
97 primarySelectDescriptorId: "profile",
98 ultrathinkPromptControlled: false,
99 }),
100 ).toEqual({ label: "Balanced · 1M · High Fast" });
101 }
102 expect(
103 buildTraitsTriggerDisplay({
104 provider: CODEX,
105 descriptors: [CONTEXT_WINDOW, { ...EFFORT, id }, serviceTierDescriptor("ultrafast")],
106 primarySelectDescriptorId: CONTEXT_WINDOW.id,
107 ultrathinkPromptControlled: false,
108 }),
109 ).toEqual({ label: "1M · High Ultrafast" });
110 },
111 );
112
113 it("pairs Cursor Fast with reasoning rather than the thinking toggle", () => {
114 expect(
115 buildTraitsTriggerDisplay({
116 provider: ProviderDriverKind.make("cursor"),
117 descriptors: [
118 CONTEXT_WINDOW,
119 { ...EFFORT, id: "reasoning_effort" },
120 fastModeDescriptor(true),
121 { id: "thinking", label: "Thinking", type: "boolean", currentValue: true },
122 ],
123 primarySelectDescriptorId: CONTEXT_WINDOW.id,
124 ultrathinkPromptControlled: false,
125 }),
126 ).toEqual({ label: "1M · High Fast · Thinking On" });
127 });
128
129 it.each([true, false])("keeps boolean thinking %s independent of Fast", (currentValue) => {
130 const thinking = {
131 id: "thinking",
132 label: "Thinking",
133 type: "boolean" as const,
134 currentValue,
135 };
136 const label = `Thinking ${currentValue ? "On" : "Off"}`;
137 expect(display([thinking, fastModeDescriptor(true)])).toEqual({ label: `${label} · Fast` });
138 expect(display([thinking, { ...EFFORT, id: "reasoning" }, fastModeDescriptor(true)])).toEqual({
139 label: `${label} · High Fast`,
140 });
141 expect(display([thinking, fastModeDescriptor(false)])).toEqual({ label });
142 });
143
144 it("keeps speed separate when there is no reasoning descriptor", () => {
145 expect(display([CONTEXT_WINDOW, fastModeDescriptor(true)])).toEqual({ label: "1M · Fast" });
146 });
147
148 it.each(["Low", "Medium", "High", "Extra High", "Max", "Ultra"])(
149 "preserves %s reasoning with Fast across harnesses",
150 (label) => {
151 for (const provider of ["codex", "claudeAgent", "cursor"]) {
152 expect(
153 buildTraitsTriggerDisplay({
154 provider: ProviderDriverKind.make(provider),
155 descriptors: [
156 { ...EFFORT, options: [{ id: "effort", label }], currentValue: "effort" },
157 fastModeDescriptor(true),
158 ],
159 primarySelectDescriptorId: EFFORT.id,
160 ultrathinkPromptControlled: false,
161 }),
162 ).toEqual({ label: `${label} Fast` });
163 }
164 },
165 );
166
167 it("treats Codex standard and fast service tiers as fast mode states", () => {
168 expect(display([EFFORT, serviceTierDescriptor("default")])).toEqual({ label: "High" });
169 expect(display([EFFORT, serviceTierDescriptor("priority")])).toEqual({ label: "High Fast" });
170 });
171
172 it("keeps Codex Ultrafast distinct from Fast", () => {
173 expect(display([EFFORT, serviceTierDescriptor("ultrafast")])).toEqual({
174 label: "High Ultrafast",
175 });
176 });
177
178 it("uses Ultrafast without requiring a Fast tier", () => {
179 const descriptor = serviceTierDescriptor("ultrafast");
180 expect(
181 display([
182 EFFORT,
183 { ...descriptor, options: descriptor.options.filter(({ id }) => id !== "priority") },
184 ]),
185 ).toEqual({ label: "High Ultrafast" });
186 });
187
188 it("keeps other Codex service tiers in the label", () => {
189 expect(display([EFFORT, serviceTierDescriptor("flex")])).toEqual({ label: "High · Flex" });
190 });
191
192 it("keeps Standard as text for models without speed tiers", () => {
193 const descriptor = serviceTierDescriptor("default");
194 const nonSpeedDescriptor = {
195 ...descriptor,
196 options: descriptor.options.filter(({ id }) => id === "default" || id === "flex"),
197 };
198 expect(display([EFFORT, nonSpeedDescriptor])).toEqual({ label: "High · Standard" });
199 expect(display([nonSpeedDescriptor])).toEqual({ label: "Standard" });
200 });
201
202 it("keeps the Codex service tier readable when it is the only trait", () => {
203 expect(display([serviceTierDescriptor("default")])).toEqual({ label: "Standard" });
204 expect(display([serviceTierDescriptor("priority")])).toEqual({ label: "Fast" });
205 });
206
207 it("keeps Ultrafast readable when it is the only trait", () => {
208 expect(display([serviceTierDescriptor("ultrafast")])).toEqual({ label: "Ultrafast" });
209 });
210
211 it("keeps non-fastMode booleans as text labels", () => {
212 const thinking: Extract<ProviderOptionDescriptor, { type: "boolean" }> = {
213 id: "thinking",
214 label: "Thinking",
215 type: "boolean",
216 currentValue: true,
217 };
218 expect(display([EFFORT, thinking])).toEqual({ label: "High · Thinking On" });
219 });
220
221 it("falls back to a text label when fast mode is the only trait", () => {
222 expect(display([fastModeDescriptor(true)])).toEqual({ label: "Fast" });
223 expect(display([fastModeDescriptor(false)])).toEqual({ label: "Normal" });
224 });
225
226 it("does not add Fast to a model without a speed option", () => {
227 expect(display([EFFORT, CONTEXT_WINDOW])).toEqual({ label: "High · 1M" });
228 });
229
230 it("stays blank when descriptors resolve to no label and there is no fast mode", () => {
231 const unresolved: Extract<ProviderOptionDescriptor, { type: "select" }> = {
232 id: "effort",
233 label: "effort",
234 type: "select",
235 options: [
236 { id: "low", label: "Low" },
237 { id: "high", label: "High" },
238 ],
239 };
240 expect(display([unresolved])).toEqual({ label: "" });
241 });
242
243 it("still renders prompt-controlled ultrathink with Fast", () => {
244 expect(
245 buildTraitsTriggerDisplay({
246 provider: CODEX,
247 descriptors: [EFFORT, fastModeDescriptor(true)],
248 primarySelectDescriptorId: "reasoningEffort",
249 ultrathinkPromptControlled: true,
250 }),
251 ).toEqual({ label: "Ultrathink Fast" });
252 });
253});
254
255describe("buildUnavailableModelOptionDescriptors", () => {
256 it("shows only saved values without inventing alternatives", () => {
257 expect(
258 buildUnavailableModelOptionDescriptors([
259 { id: "variant", value: "max" },
260 { id: "agent", value: "build" },
261 { id: "fastMode", value: true },
262 ]),
263 ).toEqual([
264 {
265 id: "variant",
266 label: "Reasoning",
267 type: "select",
268 options: [{ id: "max", label: "max" }],
269 currentValue: "max",
270 },
271 {
272 id: "agent",
273 label: "Agent",
274 type: "select",
275 options: [{ id: "build", label: "build" }],
276 currentValue: "build",
277 },
278 {
279 id: "fastMode",
280 label: "Fast Mode",
281 type: "boolean",
282 currentValue: true,
283 },
284 ]);
285 });
286});
287
288it("shows Unknown until a matching provider report provides Default", () => {
289 const selection = {
290 instanceId: ProviderInstanceId.make("opencode"),
291 model: "ling",
292 options: [],
293 };
294 const input = {
295 provider: ProviderDriverKind.make("opencode"),
296 descriptors: [
297 selectDescriptor(
298 "variant",
299 [
300 { id: "none", label: "None" },
301 { id: "thinking", label: "Thinking" },
302 ],
303 "",
304 ),
305 ],
306 primarySelectDescriptorId: "variant",
307 ultrathinkPromptControlled: false,
308 modelSelection: selection,
309 };
310 expect(buildTraitsTriggerDisplay(input).label).toBe("Unknown");
311 expect(
312 buildTraitsTriggerDisplay({
313 ...input,
314 reportedModelSelection: { ...selection, options: [{ id: "variant", value: "default" }] },
315 }).label,
316 ).toBe("Default");
317});