Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2import { ProviderDriverKind, type ProviderOptionDescriptor } from "@t3tools/contracts";
3import { buildTraitsTriggerDisplay, buildUnavailableModelOptionDescriptors } from "./TraitsPicker";
4
5function selectDescriptor(
6 id: string,
7 options: ReadonlyArray<{ id: string; label: string; isDefault?: boolean }>,
8 currentValue: string,
9): Extract<ProviderOptionDescriptor, { type: "select" }> {
10 return { id, label: id, type: "select", options: [...options], currentValue };
11}
12
13function fastModeDescriptor(
14 currentValue: boolean,
15): Extract<ProviderOptionDescriptor, { type: "boolean" }> {
16 return { id: "fastMode", label: "Fast Mode", type: "boolean", currentValue };
17}
18
19function serviceTierDescriptor(
20 currentValue: "default" | "priority" | "ultrafast" | "flex",
21): Extract<ProviderOptionDescriptor, { type: "select" }> {
22 return {
23 id: "serviceTier",
24 label: "Service Tier",
25 type: "select",
26 options: [
27 { id: "default", label: "Standard", isDefault: true },
28 { id: "priority", label: "Fast" },
29 { id: "ultrafast", label: "Ultrafast" },
30 { id: "flex", label: "Flex" },
31 ],
32 currentValue,
33 };
34}
35
36const EFFORT = selectDescriptor(
37 "reasoningEffort",
38 [
39 { id: "high", label: "High" },
40 { id: "max", label: "Max" },
41 ],
42 "high",
43);
44const CONTEXT_WINDOW = selectDescriptor(
45 "contextWindow",
46 [
47 { id: "200k", label: "200k" },
48 { id: "1m", label: "1M" },
49 ],
50 "1m",
51);
52
53const CODEX = ProviderDriverKind.make("codex");
54
55function display(descriptors: ReadonlyArray<ProviderOptionDescriptor>) {
56 return buildTraitsTriggerDisplay({
57 provider: CODEX,
58 descriptors,
59 primarySelectDescriptorId: "reasoningEffort",
60 ultrathinkPromptControlled: false,
61 });
62}
63
64describe("buildTraitsTriggerDisplay", () => {
65 it("omits fast mode from the label entirely when it is off", () => {
66 expect(display([EFFORT, fastModeDescriptor(false), CONTEXT_WINDOW])).toEqual({
67 label: "High · 1M",
68 speedIcon: null,
69 });
70 });
71
72 it("shows the bolt instead of a text label when fast mode is on", () => {
73 expect(display([EFFORT, fastModeDescriptor(true), CONTEXT_WINDOW])).toEqual({
74 label: "High · 1M",
75 speedIcon: "fast",
76 });
77 });
78
79 it("treats Codex standard and fast service tiers as fast mode states", () => {
80 expect(display([EFFORT, serviceTierDescriptor("default")])).toEqual({
81 label: "High",
82 speedIcon: null,
83 });
84 expect(display([EFFORT, serviceTierDescriptor("priority")])).toEqual({
85 label: "High",
86 speedIcon: "fast",
87 });
88 });
89
90 it("uses a distinct double bolt for Codex Ultrafast", () => {
91 expect(display([EFFORT, serviceTierDescriptor("ultrafast")])).toEqual({
92 label: "High",
93 speedIcon: "ultrafast",
94 });
95 });
96
97 it("uses Ultrafast without requiring a Fast tier", () => {
98 const descriptor = serviceTierDescriptor("ultrafast");
99 expect(
100 display([
101 EFFORT,
102 { ...descriptor, options: descriptor.options.filter(({ id }) => id !== "priority") },
103 ]),
104 ).toEqual({
105 label: "High",
106 speedIcon: "ultrafast",
107 });
108 });
109
110 it("keeps other Codex service tiers in the label", () => {
111 expect(display([EFFORT, serviceTierDescriptor("flex")])).toEqual({
112 label: "High · Flex",
113 speedIcon: null,
114 });
115 });
116
117 it("keeps Standard as text for models without speed tiers", () => {
118 const descriptor = serviceTierDescriptor("default");
119 const nonSpeedDescriptor = {
120 ...descriptor,
121 options: descriptor.options.filter(({ id }) => id === "default" || id === "flex"),
122 };
123 expect(display([EFFORT, nonSpeedDescriptor])).toEqual({
124 label: "High · Standard",
125 speedIcon: null,
126 });
127 expect(display([nonSpeedDescriptor])).toEqual({
128 label: "Standard",
129 speedIcon: null,
130 });
131 });
132
133 it("keeps the Codex service tier readable when it is the only trait", () => {
134 expect(display([serviceTierDescriptor("default")])).toEqual({
135 label: "Standard",
136 speedIcon: null,
137 });
138 expect(display([serviceTierDescriptor("priority")])).toEqual({
139 label: "Fast",
140 speedIcon: null,
141 });
142 });
143
144 it("keeps Ultrafast readable when it is the only trait", () => {
145 expect(display([serviceTierDescriptor("ultrafast")])).toEqual({
146 label: "Ultrafast",
147 speedIcon: null,
148 });
149 });
150
151 it("keeps non-fastMode booleans as text labels", () => {
152 const thinking: Extract<ProviderOptionDescriptor, { type: "boolean" }> = {
153 id: "thinking",
154 label: "Thinking",
155 type: "boolean",
156 currentValue: true,
157 };
158 expect(display([EFFORT, thinking])).toEqual({
159 label: "High · Thinking On",
160 speedIcon: null,
161 });
162 });
163
164 it("falls back to a text label when fast mode is the only trait", () => {
165 expect(display([fastModeDescriptor(true)])).toEqual({
166 label: "Fast",
167 speedIcon: null,
168 });
169 expect(display([fastModeDescriptor(false)])).toEqual({
170 label: "Normal",
171 speedIcon: null,
172 });
173 });
174
175 it("stays blank when descriptors resolve to no label and there is no fast mode", () => {
176 // A select with neither a currentValue nor an isDefault option yields no
177 // label. Without a fastMode descriptor present that must stay blank rather
178 // than falling through to a bogus "Normal".
179 const unresolved: Extract<ProviderOptionDescriptor, { type: "select" }> = {
180 id: "effort",
181 label: "effort",
182 type: "select",
183 options: [
184 { id: "low", label: "Low" },
185 { id: "high", label: "High" },
186 ],
187 };
188 expect(display([unresolved])).toEqual({ label: "", speedIcon: null });
189 });
190
191 it("still renders the prompt-controlled ultrathink label alongside the bolt", () => {
192 expect(
193 buildTraitsTriggerDisplay({
194 provider: CODEX,
195 descriptors: [EFFORT, fastModeDescriptor(true)],
196 primarySelectDescriptorId: "reasoningEffort",
197 ultrathinkPromptControlled: true,
198 }),
199 ).toEqual({ label: "Ultrathink", speedIcon: "fast" });
200 });
201});
202
203describe("buildUnavailableModelOptionDescriptors", () => {
204 it("shows only saved values without inventing alternatives", () => {
205 expect(
206 buildUnavailableModelOptionDescriptors([
207 { id: "variant", value: "max" },
208 { id: "agent", value: "build" },
209 { id: "fastMode", value: true },
210 ]),
211 ).toEqual([
212 {
213 id: "variant",
214 label: "Reasoning",
215 type: "select",
216 options: [{ id: "max", label: "max" }],
217 currentValue: "max",
218 },
219 {
220 id: "agent",
221 label: "Agent",
222 type: "select",
223 options: [{ id: "build", label: "build" }],
224 currentValue: "build",
225 },
226 {
227 id: "fastMode",
228 label: "Fast Mode",
229 type: "boolean",
230 currentValue: true,
231 },
232 ]);
233 });
234});