Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2import { ProviderDriverKind, ProviderInstanceId, type ModelCapabilities } from "@t3tools/contracts";
3
4import {
5 applyClaudePromptEffortPrefix,
6 buildExplicitProviderOptionSelectionsFromDescriptors,
7 buildProviderOptionSelectionsFromDescriptors,
8 createModelCapabilities,
9 createModelSelection,
10 getModelSelectionBooleanOptionValue,
11 getModelSelectionStringOptionValue,
12 getProviderOptionDescriptors,
13 readCustomModelEntries,
14 toCustomModelSetting,
15 getProviderOptionBooleanSelectionValue,
16 getProviderOptionStringSelectionValue,
17 normalizeCustomModelSlug,
18 normalizeModelSlug,
19 modelSelectionsEqual,
20} from "./model.ts";
21
22const codexCaps: ModelCapabilities = createModelCapabilities({
23 optionDescriptors: [
24 {
25 id: "reasoningEffort",
26 label: "Reasoning",
27 type: "select",
28 options: [
29 { id: "xhigh", label: "Extra High" },
30 { id: "high", label: "High", isDefault: true },
31 ],
32 currentValue: "high",
33 },
34 {
35 id: "fastMode",
36 label: "Fast Mode",
37 type: "boolean",
38 },
39 ],
40});
41
42describe("model slug normalization", () => {
43 it("preserves exact custom slugs instead of expanding provider aliases", () => {
44 // Claude aliases now resolve through the model catalog (#9084), so the
45 // provider alias table passes unknown slugs through unchanged.
46 const claude = ProviderDriverKind.make("claudeAgent");
47
48 expect(normalizeModelSlug("opus", claude)).toBe("opus");
49 expect(normalizeCustomModelSlug(" opus ")).toBe("opus");
50 });
51});
52
53const claudeCaps: ModelCapabilities = createModelCapabilities({
54 optionDescriptors: [
55 {
56 id: "effort",
57 label: "Reasoning",
58 type: "select",
59 options: [
60 { id: "medium", label: "Medium" },
61 { id: "high", label: "High", isDefault: true },
62 { id: "ultrathink", label: "Ultrathink" },
63 ],
64 currentValue: "high",
65 promptInjectedValues: ["ultrathink"],
66 },
67 {
68 id: "contextWindow",
69 label: "Context Window",
70 type: "select",
71 options: [
72 { id: "200k", label: "200k" },
73 { id: "1m", label: "1M", isDefault: true },
74 ],
75 currentValue: "1m",
76 },
77 ],
78});
79
80describe("descriptor helpers", () => {
81 it("applies selection values to capability descriptors", () => {
82 expect(
83 getProviderOptionDescriptors({
84 caps: claudeCaps,
85 selections: [
86 { id: "effort", value: "medium" },
87 { id: "contextWindow", value: "200k" },
88 ],
89 }),
90 ).toEqual([
91 {
92 id: "effort",
93 label: "Reasoning",
94 type: "select",
95 options: [
96 { id: "medium", label: "Medium" },
97 { id: "high", label: "High", isDefault: true },
98 { id: "ultrathink", label: "Ultrathink" },
99 ],
100 currentValue: "medium",
101 promptInjectedValues: ["ultrathink"],
102 },
103 {
104 id: "contextWindow",
105 label: "Context Window",
106 type: "select",
107 options: [
108 { id: "200k", label: "200k" },
109 { id: "1m", label: "1M", isDefault: true },
110 ],
111 currentValue: "200k",
112 },
113 ]);
114 });
115
116 it("builds wire-format option selections from descriptors", () => {
117 const descriptors = getProviderOptionDescriptors({
118 caps: codexCaps,
119 selections: [
120 { id: "reasoningEffort", value: "high" },
121 { id: "fastMode", value: true },
122 ],
123 });
124
125 expect(buildProviderOptionSelectionsFromDescriptors(descriptors)).toEqual([
126 { id: "reasoningEffort", value: "high" },
127 { id: "fastMode", value: true },
128 ]);
129 });
130
131 it("builds dispatch options only from explicit selections", () => {
132 const descriptors = getProviderOptionDescriptors({
133 caps: codexCaps,
134 selections: [{ id: "fastMode", value: true }],
135 });
136
137 expect(buildExplicitProviderOptionSelectionsFromDescriptors(descriptors, undefined)).toBe(
138 undefined,
139 );
140 expect(
141 buildExplicitProviderOptionSelectionsFromDescriptors(descriptors, [
142 { id: "fastMode", value: true },
143 ]),
144 ).toEqual([{ id: "fastMode", value: true }]);
145 });
146
147 it("stores option selection arrays in model selections", () => {
148 expect(
149 createModelSelection(ProviderInstanceId.make("codex"), "gpt-5.4", [
150 { id: "reasoningEffort", value: "high" },
151 { id: "fastMode", value: true },
152 ]),
153 ).toEqual({
154 instanceId: "codex",
155 model: "gpt-5.4",
156 options: [
157 { id: "reasoningEffort", value: "high" },
158 { id: "fastMode", value: true },
159 ],
160 });
161 });
162
163 it("reads typed option selection values", () => {
164 const selection = createModelSelection(ProviderInstanceId.make("codex"), "gpt-5.4", [
165 { id: "reasoningEffort", value: "high" },
166 { id: "fastMode", value: true },
167 ]);
168
169 expect(getProviderOptionStringSelectionValue(selection.options, "reasoningEffort")).toBe(
170 "high",
171 );
172 expect(getProviderOptionStringSelectionValue(selection.options, "fastMode")).toBeUndefined();
173 expect(getProviderOptionBooleanSelectionValue(selection.options, "fastMode")).toBe(true);
174 expect(
175 getProviderOptionBooleanSelectionValue(selection.options, "reasoningEffort"),
176 ).toBeUndefined();
177 expect(getModelSelectionStringOptionValue(selection, "reasoningEffort")).toBe("high");
178 expect(getModelSelectionBooleanOptionValue(selection, "fastMode")).toBe(true);
179 });
180
181 it("compares complete model selections independent of option ordering", () => {
182 const left = createModelSelection(ProviderInstanceId.make("codex"), "gpt-5.4", [
183 { id: "reasoningEffort", value: "high" },
184 { id: "fastMode", value: true },
185 ]);
186 const reordered = createModelSelection(ProviderInstanceId.make("codex"), "gpt-5.4", [
187 { id: "fastMode", value: true },
188 { id: "reasoningEffort", value: "high" },
189 ]);
190
191 expect(modelSelectionsEqual(left, reordered)).toBe(true);
192 expect(
193 modelSelectionsEqual(left, {
194 ...reordered,
195 options: [
196 { id: "fastMode", value: true },
197 { id: "reasoningEffort", value: "medium" },
198 ],
199 }),
200 ).toBe(false);
201 expect(modelSelectionsEqual(left, { ...reordered, model: "gpt-5.5" })).toBe(false);
202 });
203});
204
205describe("applyClaudePromptEffortPrefix", () => {
206 it("keeps slash commands intact when ultrathink is selected", () => {
207 expect(applyClaudePromptEffortPrefix("/compact", "ultrathink")).toBe("/compact");
208 expect(applyClaudePromptEffortPrefix(" /compact keep recent errors ", "ultrathink")).toBe(
209 "/compact keep recent errors",
210 );
211 expect(applyClaudePromptEffortPrefix(" /review src/model.ts ", "ultrathink")).toBe(
212 "/review src/model.ts",
213 );
214 expect(applyClaudePromptEffortPrefix("/security-review", "ultrathink")).toBe(
215 "/security-review",
216 );
217 expect(applyClaudePromptEffortPrefix("/plugin:skill run", "ultrathink")).toBe(
218 "/plugin:skill run",
219 );
220 expect(applyClaudePromptEffortPrefix("/deploy.prod to staging", "ultrathink")).toBe(
221 "/deploy.prod to staging",
222 );
223 });
224
225 it("still adds the ultrathink prefix to ordinary prompts", () => {
226 expect(applyClaudePromptEffortPrefix("Investigate this failure", "ultrathink")).toBe(
227 "Ultrathink:\nInvestigate this failure",
228 );
229 expect(applyClaudePromptEffortPrefix("/home/theo/app.ts crashed on load", "ultrathink")).toBe(
230 "Ultrathink:\n/home/theo/app.ts crashed on load",
231 );
232 });
233});
234
235describe("readCustomModelEntries", () => {
236 const capabilities: ModelCapabilities = {
237 optionDescriptors: [
238 {
239 id: "effort",
240 label: "Reasoning",
241 type: "select",
242 options: [{ id: "high", label: "High", isDefault: true }],
243 currentValue: "high",
244 },
245 ],
246 };
247
248 it("resolves bare slugs and entries, trimming and deduplicating on slug", () => {
249 expect(
250 readCustomModelEntries([
251 " bare ",
252 { slug: "named", name: " Named ", capabilities },
253 "bare",
254 { slug: "named", name: "Second" },
255 "",
256 { name: "no slug" },
257 42,
258 ]),
259 ).toEqual([
260 { slug: "bare", name: "bare", capabilities: null },
261 { slug: "named", name: "Named", capabilities },
262 ]);
263 });
264
265 it("drops unparseable capabilities but keeps the entry", () => {
266 expect(
267 readCustomModelEntries([{ slug: "x", capabilities: { optionDescriptors: "nope" } }]),
268 ).toEqual([{ slug: "x", name: "x", capabilities: null }]);
269 expect(readCustomModelEntries("not a list")).toEqual([]);
270 });
271
272 it("writes the compact stored shape back", () => {
273 expect(toCustomModelSetting({ slug: "x", name: "x", capabilities: null })).toBe("x");
274 expect(
275 toCustomModelSetting({ slug: "x", name: "x", capabilities: { optionDescriptors: [] } }),
276 ).toBe("x");
277 expect(toCustomModelSetting({ slug: "x", name: "X", capabilities })).toEqual({
278 slug: "x",
279 name: "X",
280 capabilities,
281 });
282 });
283});