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

model.test.ts

188 lines5.8 KB

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