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

model.test.ts

146 lines4.2 KB

1import { describe, expect, it } from "vite-plus/test";
2import { ProviderInstanceId, type ModelCapabilities } from "@v12/contracts";
3​
4import {
5 buildProviderOptionSelectionsFromDescriptors,
6 createModelCapabilities,
7 createModelSelection,
8 getModelSelectionBooleanOptionValue,
9 getModelSelectionStringOptionValue,
10 getProviderOptionDescriptors,
11 getProviderOptionBooleanSelectionValue,
12 getProviderOptionStringSelectionValue,
13} from "./model.ts";
14​
15const codexCaps: ModelCapabilities = createModelCapabilities({
16 optionDescriptors: [
17 {
18 id: "reasoningEffort",
19 label: "Reasoning",
20 type: "select",
21 options: [
22 { id: "xhigh", label: "Extra High" },
23 { id: "high", label: "High", isDefault: true },
24 ],
25 currentValue: "high",
26 },
27 {
28 id: "fastMode",
29 label: "Fast Mode",
30 type: "boolean",
31 },
32 ],
33});
34​
35const claudeCaps: ModelCapabilities = createModelCapabilities({
36 optionDescriptors: [
37 {
38 id: "effort",
39 label: "Reasoning",
40 type: "select",
41 options: [
42 { id: "medium", label: "Medium" },
43 { id: "high", label: "High", isDefault: true },
44 { id: "ultrathink", label: "Ultrathink" },
45 ],
46 currentValue: "high",
47 promptInjectedValues: ["ultrathink"],
48 },
49 {
50 id: "contextWindow",
51 label: "Context Window",
52 type: "select",
53 options: [
54 { id: "200k", label: "200k" },
55 { id: "1m", label: "1M", isDefault: true },
56 ],
57 currentValue: "1m",
58 },
59 ],
60});
61​
62describe("descriptor helpers", () => {
63 it("applies selection values to capability descriptors", () => {
64 expect(
65 getProviderOptionDescriptors({
66 caps: claudeCaps,
67 selections: [
68 { id: "effort", value: "medium" },
69 { id: "contextWindow", value: "200k" },
70 ],
71 }),
72 ).toEqual([
73 {
74 id: "effort",
75 label: "Reasoning",
76 type: "select",
77 options: [
78 { id: "medium", label: "Medium" },
79 { id: "high", label: "High", isDefault: true },
80 { id: "ultrathink", label: "Ultrathink" },
81 ],
82 currentValue: "medium",
83 promptInjectedValues: ["ultrathink"],
84 },
85 {
86 id: "contextWindow",
87 label: "Context Window",
88 type: "select",
89 options: [
90 { id: "200k", label: "200k" },
91 { id: "1m", label: "1M", isDefault: true },
92 ],
93 currentValue: "200k",
94 },
95 ]);
96 });
97​
98 it("builds wire-format option selections from descriptors", () => {
99 const descriptors = getProviderOptionDescriptors({
100 caps: codexCaps,
101 selections: [
102 { id: "reasoningEffort", value: "high" },
103 { id: "fastMode", value: true },
104 ],
105 });
106​
107 expect(buildProviderOptionSelectionsFromDescriptors(descriptors)).toEqual([
108 { id: "reasoningEffort", value: "high" },
109 { id: "fastMode", value: true },
110 ]);
111 });
112​
113 it("stores option selection arrays in model selections", () => {
114 expect(
115 createModelSelection(ProviderInstanceId.make("codex"), "gpt-5.4", [
116 { id: "reasoningEffort", value: "high" },
117 { id: "fastMode", value: true },
118 ]),
119 ).toEqual({
120 instanceId: "codex",
121 model: "gpt-5.4",
122 options: [
123 { id: "reasoningEffort", value: "high" },
124 { id: "fastMode", value: true },
125 ],
126 });
127 });
128​
129 it("reads typed option selection values", () => {
130 const selection = createModelSelection(ProviderInstanceId.make("codex"), "gpt-5.4", [
131 { id: "reasoningEffort", value: "high" },
132 { id: "fastMode", value: true },
133 ]);
134​
135 expect(getProviderOptionStringSelectionValue(selection.options, "reasoningEffort")).toBe(
136 "high",
137 );
138 expect(getProviderOptionStringSelectionValue(selection.options, "fastMode")).toBeUndefined();
139 expect(getProviderOptionBooleanSelectionValue(selection.options, "fastMode")).toBe(true);
140 expect(
141 getProviderOptionBooleanSelectionValue(selection.options, "reasoningEffort"),
142 ).toBeUndefined();
143 expect(getModelSelectionStringOptionValue(selection, "reasoningEffort")).toBe("high");
144 expect(getModelSelectionBooleanOptionValue(selection, "fastMode")).toBe(true);
145 });
146});