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

modelOptions.test.ts

174 lines5.2 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import { ProviderInstanceId, type ServerConfig } from "@t3tools/contracts";
4​
5import {
6 buildModelOptions,
7 groupByProvider,
8 resolveDefaultableModelSelection,
9 resolveSelectableModelSelection,
10} from "./modelOptions";
11​
12describe("mobile model options", () => {
13 it("groups models by provider and flags legacy entries", () => {
14 const config = {
15 providers: [
16 {
17 instanceId: "codex",
18 driver: "codex",
19 displayName: "Codex",
20 enabled: true,
21 installed: true,
22 auth: { status: "authenticated" },
23 models: [
24 {
25 slug: "gpt-5.6-sol",
26 name: "GPT-5.6 Sol",
27 isCustom: false,
28 capabilities: null,
29 },
30 {
31 slug: "gpt-5.4",
32 name: "GPT-5.4",
33 isCustom: false,
34 isLegacy: true,
35 capabilities: null,
36 },
37 ],
38 },
39 ],
40 } as unknown as ServerConfig;
41​
42 expect(groupByProvider(buildModelOptions(config, null))).toMatchObject([
43 {
44 providerKey: "codex",
45 providerLabel: "Codex",
46 models: [
47 { key: "codex:gpt-5.6-sol", label: "GPT-5.6 Sol", isLegacy: false },
48 { key: "codex:gpt-5.4", label: "GPT-5.4", isLegacy: true },
49 ],
50 },
51 ]);
52 });
53​
54 it("normalizes a legacy fallback selection against current capabilities", () => {
55 const config = {
56 providers: [
57 {
58 instanceId: "codex",
59 driver: "codex",
60 displayName: "Codex",
61 enabled: true,
62 installed: true,
63 auth: { status: "authenticated" },
64 models: [
65 {
66 slug: "gpt-test",
67 name: "GPT Test",
68 isCustom: false,
69 capabilities: {
70 optionDescriptors: [
71 {
72 id: "serviceTier",
73 label: "Service Tier",
74 type: "select",
75 options: [
76 { id: "default", label: "Standard", isDefault: true },
77 { id: "priority", label: "Fast" },
78 ],
79 currentValue: "default",
80 },
81 ],
82 },
83 },
84 ],
85 },
86 ],
87 } as unknown as ServerConfig;
88​
89 const [option] = buildModelOptions(config, {
90 instanceId: ProviderInstanceId.make("codex"),
91 model: "gpt-test",
92 options: [{ id: "fastMode", value: true }],
93 });
94​
95 expect(option?.capabilities?.optionDescriptors?.[0]?.id).toBe("serviceTier");
96 expect(option?.selection.options).toEqual([{ id: "serviceTier", value: "default" }]);
97 });
98​
99 it("rejects stored selections whose provider is not usable", () => {
100 const config = {
101 providers: [
102 {
103 instanceId: "codex",
104 driver: "codex",
105 enabled: true,
106 installed: true,
107 auth: { status: "authenticated" },
108 models: [],
109 },
110 {
111 instanceId: "claudeAgent",
112 driver: "claudeAgent",
113 enabled: false,
114 installed: true,
115 auth: { status: "authenticated" },
116 models: [],
117 },
118 ],
119 } as unknown as ServerConfig;
120​
121 const usable = {
122 instanceId: ProviderInstanceId.make("codex"),
123 model: "gpt-5.6-sol",
124 };
125 const disabled = {
126 instanceId: ProviderInstanceId.make("claudeAgent"),
127 model: "claude-sonnet-5",
128 };
129 const removed = {
130 instanceId: ProviderInstanceId.make("codex_personal"),
131 model: "gpt-5.6-sol",
132 };
133​
134 expect(resolveSelectableModelSelection(config, usable)).toBe(usable);
135 expect(resolveSelectableModelSelection(config, disabled)).toBeNull();
136 expect(resolveSelectableModelSelection(config, removed)).toBeNull();
137 // No config (environment offline) — nothing to validate against.
138 expect(resolveSelectableModelSelection(null, disabled)).toBe(disabled);
139 });
140​
141 it("keeps legacy models out of implicit defaults", () => {
142 const config = {
143 providers: [
144 {
145 instanceId: "codex",
146 driver: "codex",
147 displayName: "Codex",
148 enabled: true,
149 installed: true,
150 auth: { status: "authenticated" },
151 models: [
152 { slug: "gpt-5.6-sol", name: "GPT-5.6 Sol", isCustom: false, capabilities: null },
153 {
154 slug: "gpt-5.4",
155 name: "GPT-5.4",
156 isCustom: false,
157 isLegacy: true,
158 capabilities: null,
159 },
160 ],
161 },
162 ],
163 } as unknown as ServerConfig;
164​
165 const current = { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5.6-sol" };
166 const legacy = { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5.4" };
167​
168 expect(resolveDefaultableModelSelection(config, current)).toBe(current);
169 // A legacy last-used selection falls through to the provider default.
170 expect(resolveDefaultableModelSelection(config, legacy)).toBeNull();
171 // Offline: nothing to validate against, selection passes through.
172 expect(resolveDefaultableModelSelection(null, legacy)).toBe(legacy);
173 });
174});