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 buildProviderOptionSelectionsFromDescriptors,
6 createModelCapabilities,
7 createModelSelection,
8 getModelSelectionBooleanOptionValue,
9 getModelSelectionStringOptionValue,
10 getProviderOptionDescriptors,
11 getProviderOptionBooleanSelectionValue,
12 getProviderOptionStringSelectionValue,
13 normalizeCustomModelSlug,
14 normalizeModelSlug,
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("stores option selection arrays in model selections", () => {
116 expect(
117 createModelSelection(ProviderInstanceId.make("codex"), "gpt-5.4", [
118 { id: "reasoningEffort", value: "high" },
119 { id: "fastMode", value: true },
120 ]),
121 ).toEqual({
122 instanceId: "codex",
123 model: "gpt-5.4",
124 options: [
125 { id: "reasoningEffort", value: "high" },
126 { id: "fastMode", value: true },
127 ],
128 });
129 });
130
131 it("reads typed option selection values", () => {
132 const selection = createModelSelection(ProviderInstanceId.make("codex"), "gpt-5.4", [
133 { id: "reasoningEffort", value: "high" },
134 { id: "fastMode", value: true },
135 ]);
136
137 expect(getProviderOptionStringSelectionValue(selection.options, "reasoningEffort")).toBe(
138 "high",
139 );
140 expect(getProviderOptionStringSelectionValue(selection.options, "fastMode")).toBeUndefined();
141 expect(getProviderOptionBooleanSelectionValue(selection.options, "fastMode")).toBe(true);
142 expect(
143 getProviderOptionBooleanSelectionValue(selection.options, "reasoningEffort"),
144 ).toBeUndefined();
145 expect(getModelSelectionStringOptionValue(selection, "reasoningEffort")).toBe("high");
146 expect(getModelSelectionBooleanOptionValue(selection, "fastMode")).toBe(true);
147 });
148});
149
150describe("model slug normalization", () => {
151 it("preserves exact custom slugs instead of expanding provider aliases", () => {
152 const claude = ProviderDriverKind.make("claudeAgent");
153
154 expect(normalizeModelSlug("opus", claude)).toBe("claude-opus-5");
155 expect(normalizeCustomModelSlug(" opus ")).toBe("opus");
156 });
157});