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

model.test.ts

246 lines7.5 KB

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