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 buildProviderOptionSelectionsFromDescriptors,
7 createModelCapabilities,
8 createModelSelection,
9 getModelSelectionBooleanOptionValue,
10 getModelSelectionStringOptionValue,
11 getProviderOptionDescriptors,
12 getProviderOptionBooleanSelectionValue,
13 getProviderOptionStringSelectionValue,
14 normalizeCustomModelSlug,
15 normalizeModelSlug,
16 modelSelectionsEqual,
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
39describe("model slug normalization", () => {
40 it("preserves exact custom slugs instead of expanding provider aliases", () => {
41 const claude = ProviderDriverKind.make("claudeAgent");
42
43 expect(normalizeModelSlug("opus", claude)).toBe("claude-opus-5");
44 expect(normalizeCustomModelSlug(" opus ")).toBe("opus");
45 });
46});
47
48const claudeCaps: ModelCapabilities = createModelCapabilities({
49 optionDescriptors: [
50 {
51 id: "effort",
52 label: "Reasoning",
53 type: "select",
54 options: [
55 { id: "medium", label: "Medium" },
56 { id: "high", label: "High", isDefault: true },
57 { id: "ultrathink", label: "Ultrathink" },
58 ],
59 currentValue: "high",
60 promptInjectedValues: ["ultrathink"],
61 },
62 {
63 id: "contextWindow",
64 label: "Context Window",
65 type: "select",
66 options: [
67 { id: "200k", label: "200k" },
68 { id: "1m", label: "1M", isDefault: true },
69 ],
70 currentValue: "1m",
71 },
72 ],
73});
74
75describe("descriptor helpers", () => {
76 it("applies selection values to capability descriptors", () => {
77 expect(
78 getProviderOptionDescriptors({
79 caps: claudeCaps,
80 selections: [
81 { id: "effort", value: "medium" },
82 { id: "contextWindow", value: "200k" },
83 ],
84 }),
85 ).toEqual([
86 {
87 id: "effort",
88 label: "Reasoning",
89 type: "select",
90 options: [
91 { id: "medium", label: "Medium" },
92 { id: "high", label: "High", isDefault: true },
93 { id: "ultrathink", label: "Ultrathink" },
94 ],
95 currentValue: "medium",
96 promptInjectedValues: ["ultrathink"],
97 },
98 {
99 id: "contextWindow",
100 label: "Context Window",
101 type: "select",
102 options: [
103 { id: "200k", label: "200k" },
104 { id: "1m", label: "1M", isDefault: true },
105 ],
106 currentValue: "200k",
107 },
108 ]);
109 });
110
111 it("builds wire-format option selections from descriptors", () => {
112 const descriptors = getProviderOptionDescriptors({
113 caps: codexCaps,
114 selections: [
115 { id: "reasoningEffort", value: "high" },
116 { id: "fastMode", value: true },
117 ],
118 });
119
120 expect(buildProviderOptionSelectionsFromDescriptors(descriptors)).toEqual([
121 { id: "reasoningEffort", value: "high" },
122 { id: "fastMode", value: true },
123 ]);
124 });
125
126 it("stores option selection arrays in model selections", () => {
127 expect(
128 createModelSelection(ProviderInstanceId.make("codex"), "gpt-5.4", [
129 { id: "reasoningEffort", value: "high" },
130 { id: "fastMode", value: true },
131 ]),
132 ).toEqual({
133 instanceId: "codex",
134 model: "gpt-5.4",
135 options: [
136 { id: "reasoningEffort", value: "high" },
137 { id: "fastMode", value: true },
138 ],
139 });
140 });
141
142 it("reads typed option selection values", () => {
143 const selection = createModelSelection(ProviderInstanceId.make("codex"), "gpt-5.4", [
144 { id: "reasoningEffort", value: "high" },
145 { id: "fastMode", value: true },
146 ]);
147
148 expect(getProviderOptionStringSelectionValue(selection.options, "reasoningEffort")).toBe(
149 "high",
150 );
151 expect(getProviderOptionStringSelectionValue(selection.options, "fastMode")).toBeUndefined();
152 expect(getProviderOptionBooleanSelectionValue(selection.options, "fastMode")).toBe(true);
153 expect(
154 getProviderOptionBooleanSelectionValue(selection.options, "reasoningEffort"),
155 ).toBeUndefined();
156 expect(getModelSelectionStringOptionValue(selection, "reasoningEffort")).toBe("high");
157 expect(getModelSelectionBooleanOptionValue(selection, "fastMode")).toBe(true);
158 });
159
160 it("compares complete model selections independent of option ordering", () => {
161 const left = createModelSelection(ProviderInstanceId.make("codex"), "gpt-5.4", [
162 { id: "reasoningEffort", value: "high" },
163 { id: "fastMode", value: true },
164 ]);
165 const reordered = createModelSelection(ProviderInstanceId.make("codex"), "gpt-5.4", [
166 { id: "fastMode", value: true },
167 { id: "reasoningEffort", value: "high" },
168 ]);
169
170 expect(modelSelectionsEqual(left, reordered)).toBe(true);
171 expect(
172 modelSelectionsEqual(left, {
173 ...reordered,
174 options: [
175 { id: "fastMode", value: true },
176 { id: "reasoningEffort", value: "medium" },
177 ],
178 }),
179 ).toBe(false);
180 expect(modelSelectionsEqual(left, { ...reordered, model: "gpt-5.5" })).toBe(false);
181 });
182});
183
184describe("applyClaudePromptEffortPrefix", () => {
185 it("keeps slash commands intact when ultrathink is selected", () => {
186 expect(applyClaudePromptEffortPrefix("/compact", "ultrathink")).toBe("/compact");
187 expect(applyClaudePromptEffortPrefix(" /compact keep recent errors ", "ultrathink")).toBe(
188 "/compact keep recent errors",
189 );
190 expect(applyClaudePromptEffortPrefix(" /review src/model.ts ", "ultrathink")).toBe(
191 "/review src/model.ts",
192 );
193 expect(applyClaudePromptEffortPrefix("/security-review", "ultrathink")).toBe(
194 "/security-review",
195 );
196 expect(applyClaudePromptEffortPrefix("/plugin:skill run", "ultrathink")).toBe(
197 "/plugin:skill run",
198 );
199 expect(applyClaudePromptEffortPrefix("/deploy.prod to staging", "ultrathink")).toBe(
200 "/deploy.prod to staging",
201 );
202 });
203
204 it("still adds the ultrathink prefix to ordinary prompts", () => {
205 expect(applyClaudePromptEffortPrefix("Investigate this failure", "ultrathink")).toBe(
206 "Ultrathink:\nInvestigate this failure",
207 );
208 expect(applyClaudePromptEffortPrefix("/home/theo/app.ts crashed on load", "ultrathink")).toBe(
209 "Ultrathink:\n/home/theo/app.ts crashed on load",
210 );
211 });
212});