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 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]!;
29}
30
31function renderPicker(input: {
32 instanceId: string;
33 driver: string;
34 model: string;
35 options: ReadonlyArray<ModelEsque>;
36 includeEntry?: boolean;
37}) {
38 const instanceId = ProviderInstanceId.make(input.instanceId);
39 const entry = providerEntry(input.instanceId, input.driver);
40 return renderToStaticMarkup(
41 <ProviderModelPicker
42 activeInstanceId={instanceId}
43 model={input.model}
44 lockedProvider={null}
45 instanceEntries={input.includeEntry === false ? [] : [entry]}
46 modelOptionsByInstance={new Map([[instanceId, input.options]])}
47 onInstanceModelChange={() => {}}
48 />,
49 );
50}
51
52describe("ProviderModelPicker", () => {
53 it.each(["", ANTIGRAVITY_DEFAULT_MODEL])(
54 "shows a choice prompt before Antigravity has an account catalog for %s",
55 (model) => {
56 const markup = renderPicker({
57 instanceId: "antigravity",
58 driver: "antigravity",
59 model,
60 options: [],
61 });
62
63 expect(markup).toContain("Choose model");
64 expect(markup).not.toContain(ANTIGRAVITY_DEFAULT_MODEL);
65 },
66 );
67
68 it.each([{ aliases: [ANTIGRAVITY_DEFAULT_MODEL] }, { isDefault: true }])(
69 "shows the actual default model for an Antigravity marker with %j",
70 (defaultMetadata) => {
71 const markup = renderPicker({
72 instanceId: "google_work",
73 driver: "antigravity",
74 model: ANTIGRAVITY_DEFAULT_MODEL,
75 options: [
76 { slug: "gemini-fast", name: "Gemini Fast" },
77 { slug: "gemini-pro", name: "Gemini Pro", ...defaultMetadata },
78 ],
79 });
80
81 expect(markup).toContain("Gemini Pro");
82 expect(markup).not.toContain("Gemini Fast");
83 expect(markup).not.toContain(ANTIGRAVITY_DEFAULT_MODEL);
84 },
85 );
86
87 it.each(["opencode", "antigravity"])(
88 "keeps the selected model label when the %s account catalog does not contain it",
89 (driver) => {
90 const markup = renderPicker({
91 instanceId: "team_runtime",
92 driver,
93 model: "missing-model",
94 options: [{ slug: "fallback", name: "Fallback model" }],
95 });
96
97 expect(markup).toContain("missing-model");
98 expect(markup).not.toContain("Fallback model");
99 },
100 );
101
102 it.each(["codex", "claudeAgent", "cursor", "grok"])(
103 "uses the first option label for a missing %s model",
104 (driver) => {
105 const markup = renderPicker({
106 instanceId: `${driver}_work`,
107 driver,
108 model: "missing-model",
109 options: [{ slug: "fallback-model", name: "Fallback model" }],
110 });
111
112 expect(markup).toContain("Fallback model");
113 expect(markup).not.toContain(">missing-model<");
114 },
115 );
116
117 it("prefers a matching model for OpenCode", () => {
118 const markup = renderPicker({
119 instanceId: "custom_runtime",
120 driver: "opencode",
121 model: "openrouter/selected",
122 options: [
123 { slug: "openrouter/fallback", name: "Fallback model" },
124 { slug: "openrouter/selected", name: "Selected model" },
125 ],
126 });
127
128 expect(markup).toContain("Selected model");
129 expect(markup).not.toContain("Fallback model");
130 });
131
132 it("uses the first option when the active instance entry is missing", () => {
133 const markup = renderPicker({
134 instanceId: "missing_instance",
135 driver: "opencode",
136 model: "missing-model",
137 options: [{ slug: "fallback-model", name: "Fallback model" }],
138 includeEntry: false,
139 });
140
141 expect(markup).toContain("Fallback model");
142 expect(markup).not.toContain(">missing-model<");
143 });
144
145 it("keeps instance initials visible in the resting trigger", () => {
146 const activeEntry = providerEntry("codex_personal", "codex");
147 const markup = renderToStaticMarkup(
148 <ProviderModelPicker
149 activeInstanceId={activeEntry.instanceId}
150 model="gpt-5"
151 lockedProvider={null}
152 instanceEntries={[providerEntry("codex", "codex"), activeEntry]}
153 modelOptionsByInstance={new Map()}
154 size="xs"
155 onInstanceModelChange={() => {}}
156 />,
157 );
158
159 expect(markup).toContain(">CP</span>");
160 expect(markup).toContain("size-4");
161 expect(markup).toContain("h-3");
162 expect(markup).toContain("text-[7px]");
163 });
164});