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

ProviderModelPicker.test.tsx

179 lines5.6 KB

1import {
2 ANTIGRAVITY_DEFAULT_MODEL,
3 ProviderDriverKind,
4 ProviderInstanceId,
5 type ServerProvider,
6} from "@t3tools/contracts";
7import { renderToStaticMarkup } from "react-dom/server";
8import { describe, expect, it } from "vite-plus/test";
9​
10import { deriveProviderInstanceEntries } from "../../providerInstances";
11import { ProviderModelPicker } from "./ProviderModelPicker";
12import type { ModelEsque } from "./providerIconUtils";
13​
14function providerEntry(instanceId: string, driver: string) {
15 const provider: ServerProvider = {
16 instanceId: ProviderInstanceId.make(instanceId),
17 driver: ProviderDriverKind.make(driver),
18 enabled: true,
19 installed: true,
20 version: null,
21 status: "ready",
22 auth: { status: "authenticated" },
23 checkedAt: "2026-08-28T00:00:00.000Z",
24 models: [],
25 slashCommands: [],
26 skills: [],
27 };
28 return deriveProviderInstanceEntries([provider])[0]!;
30​
31function renderPicker(input: {
32 instanceId: string;
33 driver: string;
34 model: string;
35 options: ReadonlyArray<ModelEsque>;
36 includeEntry?: boolean;
37 triggerLabel?: string;
38}) {
39 const instanceId = ProviderInstanceId.make(input.instanceId);
40 const entry = providerEntry(input.instanceId, input.driver);
41 return renderToStaticMarkup(
42 <ProviderModelPicker
43 activeInstanceId={instanceId}
44 model={input.model}
45 lockedProvider={null}
46 instanceEntries={input.includeEntry === false ? [] : [entry]}
47 modelOptionsByInstance={new Map([[instanceId, input.options]])}
48 onInstanceModelChange={() => {}}
49 {...(input.triggerLabel ? { triggerLabel: input.triggerLabel } : {})}
50 />,
51 );
53​
54describe("ProviderModelPicker", () => {
55 it("shows a neutral aggregate value without a representative model or availability badge", () => {
56 const markup = renderPicker({
57 instanceId: "codex_personal",
58 driver: "codex",
59 model: "gpt-5",
60 options: [{ slug: "gpt-5", name: "GPT 5", isUnavailable: true }],
61 triggerLabel: "Mixed values",
62 });
63 expect(markup).toContain("Mixed values");
64 expect(markup).not.toContain("GPT 5");
65 expect(markup).not.toContain("Unavailable");
66 });
67​
68 it.each(["", ANTIGRAVITY_DEFAULT_MODEL])(
69 "shows a choice prompt before Antigravity has an account catalog for %s",
70 (model) => {
71 const markup = renderPicker({
72 instanceId: "antigravity",
73 driver: "antigravity",
74 model,
75 options: [],
76 });
77​
78 expect(markup).toContain("Choose model");
79 expect(markup).not.toContain(ANTIGRAVITY_DEFAULT_MODEL);
80 },
81 );
82​
83 it.each([{ aliases: [ANTIGRAVITY_DEFAULT_MODEL] }, { isDefault: true }])(
84 "shows the actual default model for an Antigravity marker with %j",
85 (defaultMetadata) => {
86 const markup = renderPicker({
87 instanceId: "google_work",
88 driver: "antigravity",
89 model: ANTIGRAVITY_DEFAULT_MODEL,
90 options: [
91 { slug: "gemini-fast", name: "Gemini Fast" },
92 { slug: "gemini-pro", name: "Gemini Pro", ...defaultMetadata },
93 ],
94 });
95​
96 expect(markup).toContain("Gemini Pro");
97 expect(markup).not.toContain("Gemini Fast");
98 expect(markup).not.toContain(ANTIGRAVITY_DEFAULT_MODEL);
99 },
100 );
101​
102 it.each(["opencode", "antigravity"])(
103 "keeps the selected model label when the %s account catalog does not contain it",
104 (driver) => {
105 const markup = renderPicker({
106 instanceId: "team_runtime",
107 driver,
108 model: "missing-model",
109 options: [{ slug: "fallback", name: "Fallback model" }],
110 });
111​
112 expect(markup).toContain("missing-model");
113 expect(markup).not.toContain("Fallback model");
114 },
115 );
116​
117 it.each(["codex", "claudeAgent", "cursor", "grok"])(
118 "uses the first option label for a missing %s model",
119 (driver) => {
120 const markup = renderPicker({
121 instanceId: `${driver}_work`,
122 driver,
123 model: "missing-model",
124 options: [{ slug: "fallback-model", name: "Fallback model" }],
125 });
126​
127 expect(markup).toContain("Fallback model");
128 expect(markup).not.toContain(">missing-model<");
129 },
130 );
131​
132 it("prefers a matching model for OpenCode", () => {
133 const markup = renderPicker({
134 instanceId: "custom_runtime",
135 driver: "opencode",
136 model: "openrouter/selected",
137 options: [
138 { slug: "openrouter/fallback", name: "Fallback model" },
139 { slug: "openrouter/selected", name: "Selected model" },
140 ],
141 });
142​
143 expect(markup).toContain("Selected model");
144 expect(markup).not.toContain("Fallback model");
145 });
146​
147 it("uses the first option when the active instance entry is missing", () => {
148 const markup = renderPicker({
149 instanceId: "missing_instance",
150 driver: "opencode",
151 model: "missing-model",
152 options: [{ slug: "fallback-model", name: "Fallback model" }],
153 includeEntry: false,
154 });
155​
156 expect(markup).toContain("Fallback model");
157 expect(markup).not.toContain(">missing-model<");
158 });
159​
160 it("keeps instance initials visible in the resting trigger", () => {
161 const activeEntry = providerEntry("codex_personal", "codex");
162 const markup = renderToStaticMarkup(
163 <ProviderModelPicker
164 activeInstanceId={activeEntry.instanceId}
165 model="gpt-5"
166 lockedProvider={null}
167 instanceEntries={[providerEntry("codex", "codex"), activeEntry]}
168 modelOptionsByInstance={new Map()}
169 size="xs"
170 onInstanceModelChange={() => {}}
171 />,
172 );
173​
174 expect(markup).toContain(">CP</span>");
175 expect(markup).toContain("size-4");
176 expect(markup).toContain("h-3");
177 expect(markup).toContain("text-[7px]");
178 });
179});