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

model.test.ts

181 lines5.4 KB

1import { describe, expect, it } from "vite-plus/test";
2import { ProviderDriverKind, ProviderInstanceId, type ModelCapabilities } from "@t3tools/contracts";
3​
4import {
5 buildProviderOptionSelectionsFromDescriptors,
6 createModelCapabilities,
7 createModelSelection,
8 getModelSelectionBooleanOptionValue,
9 getModelSelectionStringOptionValue,
10 getProviderOptionDescriptors,
11 getProviderOptionBooleanSelectionValue,
12 getProviderOptionStringSelectionValue,
13 normalizeCustomModelSlug,
14 normalizeModelSlug,
15 modelSelectionsEqual,
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​
38describe("model slug normalization", () => {
39 it("preserves exact custom slugs instead of expanding provider aliases", () => {
40 const claude = ProviderDriverKind.make("claudeAgent");
41​
42 expect(normalizeModelSlug("opus", claude)).toBe("claude-opus-5");
43 expect(normalizeCustomModelSlug(" opus ")).toBe("opus");
44 });
45});
46​
47const claudeCaps: ModelCapabilities = createModelCapabilities({
48 optionDescriptors: [
49 {
50 id: "effort",
51 label: "Reasoning",
52 type: "select",
53 options: [
54 { id: "medium", label: "Medium" },
55 { id: "high", label: "High", isDefault: true },
56 { id: "ultrathink", label: "Ultrathink" },
57 ],
58 currentValue: "high",
59 promptInjectedValues: ["ultrathink"],
60 },
61 {
62 id: "contextWindow",
63 label: "Context Window",
64 type: "select",
65 options: [
66 { id: "200k", label: "200k" },
67 { id: "1m", label: "1M", isDefault: true },
68 ],
69 currentValue: "1m",
70 },
71 ],
72});
73​
74describe("descriptor helpers", () => {
75 it("applies selection values to capability descriptors", () => {
76 expect(
77 getProviderOptionDescriptors({
78 caps: claudeCaps,
79 selections: [
80 { id: "effort", value: "medium" },
81 { id: "contextWindow", value: "200k" },
82 ],
83 }),
84 ).toEqual([
85 {
86 id: "effort",
87 label: "Reasoning",
88 type: "select",
89 options: [
90 { id: "medium", label: "Medium" },
91 { id: "high", label: "High", isDefault: true },
92 { id: "ultrathink", label: "Ultrathink" },
93 ],
94 currentValue: "medium",
95 promptInjectedValues: ["ultrathink"],
96 },
97 {
98 id: "contextWindow",
99 label: "Context Window",
100 type: "select",
101 options: [
102 { id: "200k", label: "200k" },
103 { id: "1m", label: "1M", isDefault: true },
104 ],
105 currentValue: "200k",
106 },
107 ]);
108 });
109​
110 it("builds wire-format option selections from descriptors", () => {
111 const descriptors = getProviderOptionDescriptors({
112 caps: codexCaps,
113 selections: [
114 { id: "reasoningEffort", value: "high" },
115 { id: "fastMode", value: true },
116 ],
117 });
118​
119 expect(buildProviderOptionSelectionsFromDescriptors(descriptors)).toEqual([
120 { id: "reasoningEffort", value: "high" },
121 { id: "fastMode", value: true },
122 ]);
123 });
124​
125 it("stores option selection arrays in model selections", () => {
126 expect(
127 createModelSelection(ProviderInstanceId.make("codex"), "gpt-5.4", [
128 { id: "reasoningEffort", value: "high" },
129 { id: "fastMode", value: true },
130 ]),
131 ).toEqual({
132 instanceId: "codex",
133 model: "gpt-5.4",
134 options: [
135 { id: "reasoningEffort", value: "high" },
136 { id: "fastMode", value: true },
137 ],
138 });
139 });
140​
141 it("reads typed option selection values", () => {
142 const selection = createModelSelection(ProviderInstanceId.make("codex"), "gpt-5.4", [
143 { id: "reasoningEffort", value: "high" },
144 { id: "fastMode", value: true },
145 ]);
146​
147 expect(getProviderOptionStringSelectionValue(selection.options, "reasoningEffort")).toBe(
148 "high",
149 );
150 expect(getProviderOptionStringSelectionValue(selection.options, "fastMode")).toBeUndefined();
151 expect(getProviderOptionBooleanSelectionValue(selection.options, "fastMode")).toBe(true);
152 expect(
153 getProviderOptionBooleanSelectionValue(selection.options, "reasoningEffort"),
154 ).toBeUndefined();
155 expect(getModelSelectionStringOptionValue(selection, "reasoningEffort")).toBe("high");
156 expect(getModelSelectionBooleanOptionValue(selection, "fastMode")).toBe(true);
157 });
158​
159 it("compares complete model selections independent of option ordering", () => {
160 const left = createModelSelection(ProviderInstanceId.make("codex"), "gpt-5.4", [
161 { id: "reasoningEffort", value: "high" },
162 { id: "fastMode", value: true },
163 ]);
164 const reordered = createModelSelection(ProviderInstanceId.make("codex"), "gpt-5.4", [
165 { id: "fastMode", value: true },
166 { id: "reasoningEffort", value: "high" },
167 ]);
168​
169 expect(modelSelectionsEqual(left, reordered)).toBe(true);
170 expect(
171 modelSelectionsEqual(left, {
172 ...reordered,
173 options: [
174 { id: "fastMode", value: true },
175 { id: "reasoningEffort", value: "medium" },
176 ],
177 }),
178 ).toBe(false);
179 expect(modelSelectionsEqual(left, { ...reordered, model: "gpt-5.5" })).toBe(false);
180 });
181});