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 getModelSelectionBooleanOptionValue,
11 getModelSelectionStringOptionValue,
12 getProviderOptionDescriptors,
13 getProviderOptionBooleanSelectionValue,
14 getProviderOptionStringSelectionValue,
15} from "./model.ts";
16
17const codexCaps: ModelCapabilities = createModelCapabilities({
18 optionDescriptors: [
19 {
20 id: "reasoningEffort",
21 label: "Reasoning",
22 type: "select",
23 options: [
24 { id: "xhigh", label: "Extra High" },
25 { id: "high", label: "High", isDefault: true },
26 ],
27 currentValue: "high",
28 },
29 {
30 id: "fastMode",
31 label: "Fast Mode",
32 type: "boolean",
33 },
34 ],
35});
36
37const claudeCaps: ModelCapabilities = createModelCapabilities({
38 optionDescriptors: [
39 {
40 id: "effort",
41 label: "Reasoning",
42 type: "select",
43 options: [
44 { id: "medium", label: "Medium" },
45 { id: "high", label: "High", isDefault: true },
46 { id: "ultrathink", label: "Ultrathink" },
47 ],
48 currentValue: "high",
49 promptInjectedValues: ["ultrathink"],
50 },
51 {
52 id: "contextWindow",
53 label: "Context Window",
54 type: "select",
55 options: [
56 { id: "200k", label: "200k" },
57 { id: "1m", label: "1M", isDefault: true },
58 ],
59 currentValue: "1m",
60 },
61 ],
62});
63
64describe("descriptor helpers", () => {
65 it("applies selection values to capability descriptors", () => {
66 expect(
67 getProviderOptionDescriptors({
68 caps: claudeCaps,
69 selections: [
70 { id: "effort", value: "medium" },
71 { id: "contextWindow", value: "200k" },
72 ],
73 }),
74 ).toEqual([
75 {
76 id: "effort",
77 label: "Reasoning",
78 type: "select",
79 options: [
80 { id: "medium", label: "Medium" },
81 { id: "high", label: "High", isDefault: true },
82 { id: "ultrathink", label: "Ultrathink" },
83 ],
84 currentValue: "medium",
85 promptInjectedValues: ["ultrathink"],
86 },
87 {
88 id: "contextWindow",
89 label: "Context Window",
90 type: "select",
91 options: [
92 { id: "200k", label: "200k" },
93 { id: "1m", label: "1M", isDefault: true },
94 ],
95 currentValue: "200k",
96 },
97 ]);
98 });
99
100 it("builds wire-format option selections from descriptors", () => {
101 const descriptors = getProviderOptionDescriptors({
102 caps: codexCaps,
103 selections: [
104 { id: "reasoningEffort", value: "high" },
105 { id: "fastMode", value: true },
106 ],
107 });
108
109 expect(buildProviderOptionSelectionsFromDescriptors(descriptors)).toEqual([
110 { id: "reasoningEffort", value: "high" },
111 { id: "fastMode", value: true },
112 ]);
113 });
114
115 it("builds dispatch options only from explicit selections", () => {
116 const descriptors = getProviderOptionDescriptors({
117 caps: codexCaps,
118 selections: [{ id: "fastMode", value: true }],
119 });
120
121 expect(buildExplicitProviderOptionSelectionsFromDescriptors(descriptors, undefined)).toBe(
122 undefined,
123 );
124 expect(
125 buildExplicitProviderOptionSelectionsFromDescriptors(descriptors, [
126 { id: "fastMode", value: true },
127 ]),
128 ).toEqual([{ id: "fastMode", value: true }]);
129 });
130
131 it("stores option selection arrays in model selections", () => {
132 expect(
133 createModelSelection(ProviderInstanceId.make("codex"), "gpt-5.4", [
134 { id: "reasoningEffort", value: "high" },
135 { id: "fastMode", value: true },
136 ]),
137 ).toEqual({
138 instanceId: "codex",
139 model: "gpt-5.4",
140 options: [
141 { id: "reasoningEffort", value: "high" },
142 { id: "fastMode", value: true },
143 ],
144 });
145 });
146
147 it("reads typed option selection values", () => {
148 const selection = createModelSelection(ProviderInstanceId.make("codex"), "gpt-5.4", [
149 { id: "reasoningEffort", value: "high" },
150 { id: "fastMode", value: true },
151 ]);
152
153 expect(getProviderOptionStringSelectionValue(selection.options, "reasoningEffort")).toBe(
154 "high",
155 );
156 expect(getProviderOptionStringSelectionValue(selection.options, "fastMode")).toBeUndefined();
157 expect(getProviderOptionBooleanSelectionValue(selection.options, "fastMode")).toBe(true);
158 expect(
159 getProviderOptionBooleanSelectionValue(selection.options, "reasoningEffort"),
160 ).toBeUndefined();
161 expect(getModelSelectionStringOptionValue(selection, "reasoningEffort")).toBe("high");
162 expect(getModelSelectionBooleanOptionValue(selection, "fastMode")).toBe(true);
163 });
164});
165
166describe("applyClaudePromptEffortPrefix", () => {
167 it("keeps slash commands intact when ultrathink is selected", () => {
168 expect(applyClaudePromptEffortPrefix("/compact", "ultrathink")).toBe("/compact");
169 expect(applyClaudePromptEffortPrefix(" /compact keep recent errors ", "ultrathink")).toBe(
170 "/compact keep recent errors",
171 );
172 expect(applyClaudePromptEffortPrefix(" /review src/model.ts ", "ultrathink")).toBe(
173 "/review src/model.ts",
174 );
175 expect(applyClaudePromptEffortPrefix("/security-review", "ultrathink")).toBe(
176 "/security-review",
177 );
178 expect(applyClaudePromptEffortPrefix("/plugin:skill run", "ultrathink")).toBe(
179 "/plugin:skill run",
180 );
181 expect(applyClaudePromptEffortPrefix("/deploy.prod to staging", "ultrathink")).toBe(
182 "/deploy.prod to staging",
183 );
184 });
185
186 it("still adds the ultrathink prefix to ordinary prompts", () => {
187 expect(applyClaudePromptEffortPrefix("Investigate this failure", "ultrathink")).toBe(
188 "Ultrathink:\nInvestigate this failure",
189 );
190 expect(applyClaudePromptEffortPrefix("/home/theo/app.ts crashed on load", "ultrathink")).toBe(
191 "Ultrathink:\n/home/theo/app.ts crashed on load",
192 );
193 });
194});