Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2import { ProviderInstanceId, type ModelCapabilities } from "@t3tools/contracts";
3
4import {
5 applyClaudePromptEffortPrefix,
6 buildExplicitProviderOptionSelectionsFromDescriptors,
7 buildProviderOptionSelectionsFromDescriptors,
8 createModelCapabilities,
9 createModelSelection,
10 getProviderOptionCurrentLabel,
11 getProviderOptionDescriptors,
12 readCustomModelEntries,
13 modelSelectionsEqual,
14} from "./model.ts";
15
16const codexCaps: ModelCapabilities = createModelCapabilities({
17 optionDescriptors: [
18 {
19 id: "reasoningEffort",
20 label: "Reasoning",
21 type: "select",
22 options: [
23 { id: "xhigh", label: "Extra High" },
24 { id: "high", label: "High", isDefault: true },
25 ],
26 currentValue: "high",
27 },
28 {
29 id: "fastMode",
30 label: "Fast Mode",
31 type: "boolean",
32 },
33 ],
34});
35
36describe("descriptor helpers", () => {
37 it("builds dispatch options only from explicit selections", () => {
38 const descriptors = getProviderOptionDescriptors({
39 caps: codexCaps,
40 selections: [{ id: "fastMode", value: true }],
41 });
42
43 expect(buildExplicitProviderOptionSelectionsFromDescriptors(descriptors, undefined)).toBe(
44 undefined,
45 );
46 expect(
47 buildExplicitProviderOptionSelectionsFromDescriptors(descriptors, [
48 { id: "fastMode", value: true },
49 ]),
50 ).toEqual([{ id: "fastMode", value: true }]);
51 });
52
53 it("compares complete model selections independent of option ordering", () => {
54 const left = createModelSelection(ProviderInstanceId.make("codex"), "gpt-5.4", [
55 { id: "reasoningEffort", value: "high" },
56 { id: "fastMode", value: true },
57 ]);
58 const reordered = createModelSelection(ProviderInstanceId.make("codex"), "gpt-5.4", [
59 { id: "fastMode", value: true },
60 { id: "reasoningEffort", value: "high" },
61 ]);
62
63 expect(modelSelectionsEqual(left, reordered)).toBe(true);
64 expect(
65 modelSelectionsEqual(left, {
66 ...reordered,
67 options: [
68 { id: "fastMode", value: true },
69 { id: "reasoningEffort", value: "medium" },
70 ],
71 }),
72 ).toBe(false);
73 expect(modelSelectionsEqual(left, { ...reordered, model: "gpt-5.5" })).toBe(false);
74 });
75});
76
77describe("applyClaudePromptEffortPrefix", () => {
78 it("keeps slash commands intact when ultrathink is selected", () => {
79 expect(applyClaudePromptEffortPrefix("/compact", "ultrathink")).toBe("/compact");
80 expect(applyClaudePromptEffortPrefix(" /compact keep recent errors ", "ultrathink")).toBe(
81 "/compact keep recent errors",
82 );
83 expect(applyClaudePromptEffortPrefix(" /review src/model.ts ", "ultrathink")).toBe(
84 "/review src/model.ts",
85 );
86 expect(applyClaudePromptEffortPrefix("/security-review", "ultrathink")).toBe(
87 "/security-review",
88 );
89 expect(applyClaudePromptEffortPrefix("/plugin:skill run", "ultrathink")).toBe(
90 "/plugin:skill run",
91 );
92 expect(applyClaudePromptEffortPrefix("/deploy.prod to staging", "ultrathink")).toBe(
93 "/deploy.prod to staging",
94 );
95 });
96
97 it("still adds the ultrathink prefix to ordinary prompts", () => {
98 expect(applyClaudePromptEffortPrefix("Investigate this failure", "ultrathink")).toBe(
99 "Ultrathink:\nInvestigate this failure",
100 );
101 expect(applyClaudePromptEffortPrefix("/home/theo/app.ts crashed on load", "ultrathink")).toBe(
102 "Ultrathink:\n/home/theo/app.ts crashed on load",
103 );
104 });
105});
106
107describe("readCustomModelEntries", () => {
108 const capabilities: ModelCapabilities = {
109 optionDescriptors: [
110 {
111 id: "effort",
112 label: "Reasoning",
113 type: "select",
114 options: [{ id: "high", label: "High", isDefault: true }],
115 currentValue: "high",
116 },
117 ],
118 };
119
120 it("resolves bare slugs and entries, trimming and deduplicating on slug", () => {
121 expect(
122 readCustomModelEntries([
123 " bare ",
124 { slug: "named", name: " Named ", capabilities },
125 "bare",
126 { slug: "named", name: "Second" },
127 "",
128 { name: "no slug" },
129 42,
130 ]),
131 ).toEqual([
132 { slug: "bare", name: "bare", capabilities: null },
133 { slug: "named", name: "Named", capabilities },
134 ]);
135 });
136
137 it("drops unparseable capabilities but keeps the entry", () => {
138 expect(
139 readCustomModelEntries([{ slug: "x", capabilities: { optionDescriptors: "nope" } }]),
140 ).toEqual([{ slug: "x", name: "x", capabilities: null }]);
141 expect(readCustomModelEntries("not a list")).toEqual([]);
142 });
143});
144
145describe("provider-reported option display", () => {
146 const selection = createModelSelection(ProviderInstanceId.make("opencode"), "ling");
147 const reported = { ...selection, options: [{ id: "variant", value: "default" }] };
148 const descriptor = {
149 id: "variant",
150 label: "Reasoning",
151 type: "select" as const,
152 options: [
153 { id: "none", label: "None" },
154 { id: "thinking", label: "Thinking" },
155 ],
156 };
157
158 it("shows explicit reports without adding a choice or a dispatch option", () => {
159 expect(getProviderOptionCurrentLabel(descriptor, selection, reported)).toBe("Default");
160 expect(
161 getProviderOptionCurrentLabel(descriptor, selection, {
162 ...reported,
163 options: [{ id: "variant", value: "thinking" }],
164 }),
165 ).toBe("Thinking");
166 expect(
167 getProviderOptionCurrentLabel(
168 { ...descriptor, currentValue: "none" },
169 { ...selection, options: [{ id: "variant", value: "none" }] },
170 reported,
171 ),
172 ).toBe("None");
173 expect(descriptor.options.map((option) => option.id)).toEqual(["none", "thinking"]);
174 expect(buildProviderOptionSelectionsFromDescriptors([descriptor])).toBeUndefined();
175 expect(getProviderOptionCurrentLabel(descriptor, selection)).toBe("Unknown");
176 const effortDescriptor = { ...descriptor, id: "effort", currentValue: "default" };
177 expect(getProviderOptionCurrentLabel(effortDescriptor, selection)).toBeUndefined();
178 expect(
179 getProviderOptionCurrentLabel(effortDescriptor, selection, {
180 ...reported,
181 model: "other",
182 options: [{ id: "effort", value: "default" }],
183 }),
184 ).toBeUndefined();
185 expect(
186 getProviderOptionCurrentLabel(effortDescriptor, selection, {
187 ...reported,
188 options: [{ id: "effort", value: "default" }],
189 }),
190 ).toBe("Default");
191 expect(
192 getProviderOptionCurrentLabel({ ...descriptor, currentValue: "thinking" }, selection),
193 ).toBe("Unknown");
194 });
195
196 it.each([
197 { ...selection, model: "other" },
198 { ...selection, instanceId: ProviderInstanceId.make("other") },
199 { ...selection, options: [{ id: "variant", value: "none" }] },
200 ])("ignores reports after changing the model, instance, or option: %j", (selected) => {
201 expect(getProviderOptionCurrentLabel(descriptor, selected, reported)).toBe("Unknown");
202 });
203});