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

modelOptions.test.ts

94 lines2.9 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import { ProviderInstanceId, type ServerConfig } from "@t3tools/contracts";
4​
5import { buildModelOptions, resolveSelectableModelSelection } from "./modelOptions";
6​
7describe("mobile model options", () => {
8 it("normalizes a legacy fallback selection against current capabilities", () => {
9 const config = {
10 providers: [
11 {
12 instanceId: "codex",
13 driver: "codex",
14 displayName: "Codex",
15 enabled: true,
16 installed: true,
17 auth: { status: "authenticated" },
18 models: [
19 {
20 slug: "gpt-test",
21 name: "GPT Test",
22 isCustom: false,
23 capabilities: {
24 optionDescriptors: [
25 {
26 id: "serviceTier",
27 label: "Service Tier",
28 type: "select",
29 options: [
30 { id: "default", label: "Standard", isDefault: true },
31 { id: "priority", label: "Fast" },
32 ],
33 currentValue: "default",
34 },
35 ],
36 },
37 },
38 ],
39 },
40 ],
41 } as unknown as ServerConfig;
42​
43 const [option] = buildModelOptions(config, {
44 instanceId: ProviderInstanceId.make("codex"),
45 model: "gpt-test",
46 options: [{ id: "fastMode", value: true }],
47 });
48​
49 expect(option?.capabilities?.optionDescriptors?.[0]?.id).toBe("serviceTier");
50 expect(option?.selection.options).toEqual([{ id: "serviceTier", value: "default" }]);
51 });
52​
53 it("rejects stored selections whose provider is not usable", () => {
54 const config = {
55 providers: [
56 {
57 instanceId: "codex",
58 driver: "codex",
59 enabled: true,
60 installed: true,
61 auth: { status: "authenticated" },
62 models: [],
63 },
64 {
65 instanceId: "claudeAgent",
66 driver: "claudeAgent",
67 enabled: false,
68 installed: true,
69 auth: { status: "authenticated" },
70 models: [],
71 },
72 ],
73 } as unknown as ServerConfig;
74​
75 const usable = {
76 instanceId: ProviderInstanceId.make("codex"),
77 model: "gpt-5.6-sol",
78 };
79 const disabled = {
80 instanceId: ProviderInstanceId.make("claudeAgent"),
81 model: "claude-sonnet-5",
82 };
83 const removed = {
84 instanceId: ProviderInstanceId.make("codex_personal"),
85 model: "gpt-5.6-sol",
86 };
87​
88 expect(resolveSelectableModelSelection(config, usable)).toBe(usable);
89 expect(resolveSelectableModelSelection(config, disabled)).toBeNull();
90 expect(resolveSelectableModelSelection(config, removed)).toBeNull();
91 // No config (environment offline) — nothing to validate against.
92 expect(resolveSelectableModelSelection(null, disabled)).toBe(disabled);
93 });
94});