Open History to see the last commit
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 { ModelListRow } from "./ModelListRow";
13import { Combobox } from "../ui/combobox";
14import type { ModelEsque } from "./providerIconUtils";
15
16function providerEntry(instanceId: string, driver: string) {
17 const provider: ServerProvider = {
18 instanceId: ProviderInstanceId.make(instanceId),
19 driver: ProviderDriverKind.make(driver),
20 enabled: true,
21 installed: true,
22 version: null,
23 status: "ready",
24 auth: { status: "authenticated" },
25 checkedAt: "2026-08-28T00:00:00.000Z",
26 models: [],
27 slashCommands: [],
28 skills: [],
29 };
30 return deriveProviderInstanceEntries([provider])[0]!;
31}
32
33function renderPicker(input: {
34 instanceId: string;
35 driver: string;
36 model: string;
37 options: ReadonlyArray<ModelEsque>;
38 includeEntry?: boolean;
39}) {
40 const instanceId = ProviderInstanceId.make(input.instanceId);
41 const entry = providerEntry(input.instanceId, input.driver);
42 return renderToStaticMarkup(
43 <ProviderModelPicker
44 activeInstanceId={instanceId}
45 model={input.model}
46 lockedProvider={null}
47 instanceEntries={input.includeEntry === false ? [] : [entry]}
48 modelOptionsByInstance={new Map([[instanceId, input.options]])}
49 onInstanceModelChange={() => {}}
50 />,
51 );
52}
53
54describe("ProviderModelPicker", () => {
55 it.each(["", ANTIGRAVITY_DEFAULT_MODEL])(
56 "shows a choice prompt before Antigravity has an account catalog for %s",
57 (model) => {
58 const markup = renderPicker({
59 instanceId: "antigravity",
60 driver: "antigravity",
61 model,
62 options: [],
63 });
64
65 expect(markup).toContain("Choose model");
66 expect(markup).not.toContain(ANTIGRAVITY_DEFAULT_MODEL);
67 },
68 );
69
70 it.each([{ aliases: [ANTIGRAVITY_DEFAULT_MODEL] }, { isDefault: true }])(
71 "shows the actual default model for an Antigravity marker with %j",
72 (defaultMetadata) => {
73 const markup = renderPicker({
74 instanceId: "google_work",
75 driver: "antigravity",
76 model: ANTIGRAVITY_DEFAULT_MODEL,
77 options: [
78 { slug: "gemini-fast", name: "Gemini Fast" },
79 { slug: "gemini-pro", name: "Gemini Pro", ...defaultMetadata },
80 ],
81 });
82
83 expect(markup).toContain("Gemini Pro");
84 expect(markup).not.toContain("Gemini Fast");
85 expect(markup).not.toContain(ANTIGRAVITY_DEFAULT_MODEL);
86 },
87 );
88
89 it.each(["opencode", "antigravity"])(
90 "keeps the selected model label when the %s account catalog does not contain it",
91 (driver) => {
92 const markup = renderPicker({
93 instanceId: "team_runtime",
94 driver,
95 model: "missing-model",
96 options: [{ slug: "fallback", name: "Fallback model" }],
97 });
98
99 expect(markup).toContain("missing-model");
100 expect(markup).not.toContain("Fallback model");
101 },
102 );
103
104 it.each(["codex", "claudeAgent", "cursor", "grok", "omp"])(
105 "uses the first option label for a missing %s model",
106 (driver) => {
107 const markup = renderPicker({
108 instanceId: `${driver}_work`,
109 driver,
110 model: "missing-model",
111 options: [{ slug: "fallback-model", name: "Fallback model" }],
112 });
113
114 expect(markup).toContain("Fallback model");
115 expect(markup).not.toContain(">missing-model<");
116 },
117 );
118
119 it("prefers a matching model for OpenCode", () => {
120 const markup = renderPicker({
121 instanceId: "custom_runtime",
122 driver: "opencode",
123 model: "openrouter/selected",
124 options: [
125 { slug: "openrouter/fallback", name: "Fallback model" },
126 { slug: "openrouter/selected", name: "Selected model" },
127 ],
128 });
129
130 expect(markup).toContain("Selected model");
131 expect(markup).not.toContain("Fallback model");
132 });
133
134 it("uses the first option when the active instance entry is missing", () => {
135 const markup = renderPicker({
136 instanceId: "missing_instance",
137 driver: "opencode",
138 model: "missing-model",
139 options: [{ slug: "fallback-model", name: "Fallback model" }],
140 includeEntry: false,
141 });
142
143 expect(markup).toContain("Fallback model");
144 expect(markup).not.toContain(">missing-model<");
145 });
146
147 it("keeps instance initials visible in the resting trigger", () => {
148 const activeEntry = providerEntry("codex_personal", "codex");
149 const markup = renderToStaticMarkup(
150 <ProviderModelPicker
151 activeInstanceId={activeEntry.instanceId}
152 model="gpt-5"
153 lockedProvider={null}
154 instanceEntries={[providerEntry("codex", "codex"), activeEntry]}
155 modelOptionsByInstance={new Map()}
156 size="xs"
157 onInstanceModelChange={() => {}}
158 />,
159 );
160
161 expect(markup).toContain(">CP</span>");
162 expect(markup).toContain("size-4");
163 expect(markup).toContain("h-3");
164 expect(markup).toContain("text-[7px]");
165 });
166
167 it("renders each model row with its provider and upstream label", () => {
168 const markup = renderToStaticMarkup(
169 <Combobox>
170 <ModelListRow
171 index={0}
172 model={{
173 slug: "alibaba-coding-plan/qwen3.8-max-0902",
174 name: "Qwen3.8 Max",
175 subProvider: "Alibaba Coding Plan",
176 }}
177 instanceId={ProviderInstanceId.make("omp")}
178 driverKind={ProviderDriverKind.make("omp")}
179 providerDisplayName="Oh My Pi"
180 isFavorite={false}
181 isSelected={false}
182 showProvider
183 onToggleFavorite={() => {}}
184 />
185 </Combobox>,
186 );
187
188 expect(markup).toContain("Qwen3.8 Max");
189 expect(markup).toContain("Oh My Pi · Alibaba Coding Plan");
190 });
191});