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

ProviderModelPicker.browser.tsx

1,226 lines37.6 KB

1import { ProviderDriverKind, ProviderInstanceId, type ServerProvider } from "@t3tools/contracts";
2import { EnvironmentId } from "@t3tools/contracts";
3import { createModelCapabilities } from "@t3tools/shared/model";
4import { page, userEvent } from "vitest/browser";
5import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
6import { render } from "vitest-browser-react";
7​
8import { ProviderModelPicker } from "./ProviderModelPicker";
9import { getCustomModelOptionsByInstance } from "../../modelSelection";
10import {
11 deriveProviderInstanceEntries,
12 sortProviderInstanceEntries,
13} from "../../providerInstances";
14import type { ModelEsque } from "./providerIconUtils";
15import {
16 DEFAULT_CLIENT_SETTINGS,
17 DEFAULT_UNIFIED_SETTINGS,
18 type UnifiedSettings,
19} from "@t3tools/contracts/settings";
20import { __resetLocalApiForTests } from "../../localApi";
21​
22// Mock the environments/runtime module to provide a mock primary environment connection
23vi.mock("../../environments/runtime", () => {
24 const primaryConnection = {
25 kind: "primary" as const,
26 knownEnvironment: {
27 id: "environment-local",
28 label: "Local environment",
29 source: "manual" as const,
30 environmentId: EnvironmentId.make("environment-local"),
31 target: {
32 httpBaseUrl: "http://localhost:3000",
33 wsBaseUrl: "ws://localhost:3000",
34 },
35 },
36 environmentId: EnvironmentId.make("environment-local"),
37 client: {
38 server: {
39 getConfig: vi.fn(),
40 updateSettings: vi.fn(),
41 },
42 },
43 ensureBootstrapped: async () => undefined,
44 reconnect: async () => undefined,
45 dispose: async () => undefined,
46 };
47​
48 return {
49 getEnvironmentHttpBaseUrl: () => "http://localhost:3000",
50 getSavedEnvironmentRecord: () => null,
51 getSavedEnvironmentRuntimeState: () => null,
52 hasSavedEnvironmentRegistryHydrated: () => true,
53 listSavedEnvironmentRecords: () => [],
54 resetSavedEnvironmentRegistryStoreForTests: vi.fn(),
55 resetSavedEnvironmentRuntimeStoreForTests: vi.fn(),
56 resolveEnvironmentHttpUrl: (_environmentId: unknown, path: string) =>
57 new URL(path, "http://localhost:3000").toString(),
58 waitForSavedEnvironmentRegistryHydration: async () => undefined,
59 addSavedEnvironment: vi.fn(),
60 disconnectSavedEnvironment: vi.fn(),
61 ensureEnvironmentConnectionBootstrapped: async () => undefined,
62 getPrimaryEnvironmentConnection: () => primaryConnection,
63 readEnvironmentConnection: () => primaryConnection,
64 reconnectSavedEnvironment: vi.fn(),
65 removeSavedEnvironment: vi.fn(),
66 requireEnvironmentConnection: () => primaryConnection,
67 resetEnvironmentServiceForTests: vi.fn(),
68 startEnvironmentConnectionService: vi.fn(),
69 subscribeEnvironmentConnections: () => () => {},
70 useSavedEnvironmentRegistryStore: (
71 selector: (state: { byId: Record<string, never> }) => unknown,
72 ) => selector({ byId: {} }),
73 useSavedEnvironmentRuntimeStore: (
74 selector: (state: { byId: Record<string, never> }) => unknown,
75 ) => selector({ byId: {} }),
76 };
77});
78​
79function selectDescriptor(
80 id: string,
81 label: string,
82 options: ReadonlyArray<{ id: string; label: string; isDefault?: boolean }>,
83) {
84 return {
85 id,
86 label,
87 type: "select" as const,
88 options: [...options],
89 ...(options.find((option) => option.isDefault)?.id
90 ? { currentValue: options.find((option) => option.isDefault)?.id }
91 : {}),
92 };
94​
95function booleanDescriptor(id: string, label: string) {
96 return {
97 id,
98 label,
99 type: "boolean" as const,
100 };
102​
103const TEST_PROVIDERS: ReadonlyArray<ServerProvider> = [
104 {
105 driver: ProviderDriverKind.make("codex"),
106 instanceId: ProviderInstanceId.make("codex"),
107 displayName: "Codex",
108 enabled: true,
109 installed: true,
110 version: "0.116.0",
111 status: "ready",
112 auth: { status: "authenticated" },
113 checkedAt: new Date().toISOString(),
114 slashCommands: [],
115 skills: [],
116 models: [
117 {
118 slug: "gpt-5-codex",
119 name: "GPT-5 Codex",
120 isCustom: false,
121 capabilities: createModelCapabilities({
122 optionDescriptors: [
123 selectDescriptor("reasoningEffort", "Reasoning", [
124 { id: "low", label: "low" },
125 { id: "medium", label: "medium", isDefault: true },
126 { id: "high", label: "high" },
127 ]),
128 booleanDescriptor("fastMode", "Fast Mode"),
129 ],
130 }),
131 },
132 {
133 slug: "gpt-5.3-codex",
134 name: "GPT-5.3 Codex",
135 isCustom: false,
136 capabilities: createModelCapabilities({
137 optionDescriptors: [
138 selectDescriptor("reasoningEffort", "Reasoning", [
139 { id: "low", label: "low" },
140 { id: "medium", label: "medium", isDefault: true },
141 { id: "high", label: "high" },
142 ]),
143 booleanDescriptor("fastMode", "Fast Mode"),
144 ],
145 }),
146 },
147 ],
148 },
149 {
150 driver: ProviderDriverKind.make("claudeAgent"),
151 instanceId: ProviderInstanceId.make("claudeAgent"),
152 displayName: "Claude",
153 enabled: true,
154 installed: true,
155 version: "1.0.0",
156 status: "ready",
157 auth: { status: "authenticated" },
158 checkedAt: new Date().toISOString(),
159 slashCommands: [],
160 skills: [],
161 models: [
162 {
163 slug: "claude-opus-4-6",
164 name: "Claude Opus 4.6",
165 isCustom: false,
166 capabilities: createModelCapabilities({
167 optionDescriptors: [
168 selectDescriptor("effort", "Reasoning", [
169 { id: "low", label: "low" },
170 { id: "medium", label: "medium", isDefault: true },
171 { id: "high", label: "high" },
172 { id: "max", label: "max" },
173 ]),
174 booleanDescriptor("thinking", "Thinking"),
175 ],
176 }),
177 },
178 {
179 slug: "claude-sonnet-4-6",
180 name: "Claude Sonnet 4.6",
181 isCustom: false,
182 capabilities: createModelCapabilities({
183 optionDescriptors: [
184 selectDescriptor("effort", "Reasoning", [
185 { id: "low", label: "low" },
186 { id: "medium", label: "medium", isDefault: true },
187 { id: "high", label: "high" },
188 { id: "max", label: "max" },
189 ]),
190 booleanDescriptor("thinking", "Thinking"),
191 ],
192 }),
193 },
194 {
195 slug: "claude-haiku-4-5",
196 name: "Claude Haiku 4.5",
197 isCustom: false,
198 capabilities: createModelCapabilities({
199 optionDescriptors: [
200 selectDescriptor("effort", "Reasoning", [
201 { id: "low", label: "low" },
202 { id: "medium", label: "medium", isDefault: true },
203 { id: "high", label: "high" },
204 ]),
205 booleanDescriptor("thinking", "Thinking"),
206 ],
207 }),
208 },
209 ],
210 },
211];
212​
213const CODEX_INSTANCE_ID = ProviderInstanceId.make("codex");
214const CLAUDE_INSTANCE_ID = ProviderInstanceId.make("claudeAgent");
215const OPENCODE_INSTANCE_ID = ProviderInstanceId.make("opencode");
216​
217function buildCodexProvider(models: ServerProvider["models"]): ServerProvider {
218 return {
219 driver: ProviderDriverKind.make("codex"),
220 instanceId: ProviderInstanceId.make("codex"),
221 displayName: "Codex",
222 enabled: true,
223 installed: true,
224 version: "0.116.0",
225 status: "ready",
226 auth: { status: "authenticated" },
227 checkedAt: new Date().toISOString(),
228 models,
229 slashCommands: [],
230 skills: [],
231 };
233​
234function buildOpenCodeProvider(models: ServerProvider["models"]): ServerProvider {
235 return {
236 driver: ProviderDriverKind.make("opencode"),
237 instanceId: ProviderInstanceId.make("opencode"),
238 enabled: true,
239 installed: true,
240 version: "1.0.0",
241 status: "ready",
242 auth: { status: "authenticated" },
243 checkedAt: new Date().toISOString(),
244 models,
245 slashCommands: [],
246 skills: [],
247 };
249​
250async function mountPicker(props: {
251 activeInstanceId?: ProviderInstanceId;
252 model: string;
253 lockedProvider: ProviderDriverKind | null;
254 lockedContinuationGroupKey?: string | null;
255 providers?: ReadonlyArray<ServerProvider>;
256 settings?: UnifiedSettings;
257 triggerVariant?: "ghost" | "outline";
258}) {
259 const host = document.createElement("div");
260 document.body.append(host);
261 const onInstanceModelChange = vi.fn();
262 const providers = props.providers ?? TEST_PROVIDERS;
263 const instanceEntries = sortProviderInstanceEntries(deriveProviderInstanceEntries(providers));
264 const activeInstanceId = props.activeInstanceId ?? CODEX_INSTANCE_ID;
265 const modelOptionsByInstance = getCustomModelOptionsByInstance(
266 props.settings ?? DEFAULT_UNIFIED_SETTINGS,
267 providers,
268 activeInstanceId,
269 props.model,
270 );
271 const screen = await render(
272 <ProviderModelPicker
273 activeInstanceId={activeInstanceId}
274 model={props.model}
275 lockedProvider={props.lockedProvider}
276 lockedContinuationGroupKey={props.lockedContinuationGroupKey ?? null}
277 instanceEntries={instanceEntries}
278 modelOptionsByInstance={modelOptionsByInstance}
279 triggerVariant={props.triggerVariant}
280 onInstanceModelChange={onInstanceModelChange}
281 />,
282 { container: host },
283 );
284​
285 return {
286 onInstanceModelChange,
287 // Back-compat alias used by callers that still assert on the old callback
288 // name. Delegates to the instance-aware mock so existing expectations work.
289 get onProviderModelChange() {
290 return onInstanceModelChange;
291 },
292 cleanup: async () => {
293 await screen.unmount();
294 host.remove();
295 },
296 };
298​
299function getModelPickerListElement() {
300 const modelPickerList = document.querySelector<HTMLElement>(".model-picker-list");
301 expect(modelPickerList).not.toBeNull();
302 return modelPickerList!;
304​
305function getModelPickerListText() {
306 return getModelPickerListElement().textContent ?? "";
308​
309function getVisibleModelNames() {
310 return Array.from(getModelPickerListElement().querySelectorAll<HTMLDivElement>("div.font-medium"))
311 .map((element) => element.textContent?.replace(/New$/u, "").trim() ?? "")
312 .filter((text) => text.length > 0);
314​
315function getSidebarProviderOrder() {
316 return Array.from(document.querySelectorAll<HTMLElement>("[data-model-picker-provider]")).map(
317 (element) => element.dataset.modelPickerProvider ?? "",
318 );
320​
321describe("ProviderModelPicker", () => {
322 beforeEach(async () => {
323 // Reset test environment before each test
324 await __resetLocalApiForTests();
325 });
326​
327 afterEach(async () => {
328 document.body.innerHTML = "";
329 await __resetLocalApiForTests();
330 });
331​
332 it("shows provider sidebar in unlocked mode", async () => {
333 const mounted = await mountPicker({
334 activeInstanceId: CLAUDE_INSTANCE_ID,
335 model: "claude-opus-4-6",
336 lockedProvider: null,
337 });
338​
339 try {
340 await page.getByRole("button").click();
341​
342 await vi.waitFor(() => {
343 const text = document.body.textContent ?? "";
344 expect(text).not.toContain("Codex");
345 expect(text).toContain("Claude");
346 expect(text).toContain("Claude Opus 4.6");
347 });
348 } finally {
349 await mounted.cleanup();
350 }
351 });
352​
353 it("shows favorites first in the provider sidebar", async () => {
354 const mounted = await mountPicker({
355 activeInstanceId: CLAUDE_INSTANCE_ID,
356 model: "claude-opus-4-6",
357 lockedProvider: null,
358 });
359​
360 try {
361 await page.getByRole("button").click();
362​
363 await vi.waitFor(() => {
364 expect(getSidebarProviderOrder().slice(0, 3)).toEqual([
365 "favorites",
366 "codex",
367 "claudeAgent",
368 ]);
369 });
370 } finally {
371 await mounted.cleanup();
372 }
373 });
374​
375 it("filters models by selected provider in sidebar", async () => {
376 const mounted = await mountPicker({
377 activeInstanceId: CLAUDE_INSTANCE_ID,
378 model: "claude-opus-4-6",
379 lockedProvider: null,
380 });
381​
382 try {
383 await page.getByRole("button").click();
384​
385 // Start with Claude models visible
386 await vi.waitFor(() => {
387 const text = document.body.textContent ?? "";
388 expect(text).not.toContain("GPT-5 Codex");
389 expect(text).toContain("Claude Opus 4.6");
390 });
391​
392 // Click on Codex provider in sidebar
393 await vi.waitFor(() => {
394 expect(document.querySelector('[data-model-picker-provider="codex"]')).not.toBeNull();
395 });
396 await page.getByRole("button", { name: "Codex", exact: true }).click();
397​
398 // Now should only show Codex models
399 await vi.waitFor(() => {
400 const listText = getModelPickerListText();
401 expect(listText).toContain("GPT-5 Codex");
402 expect(listText).not.toContain("Claude Opus 4.6");
403 });
404 } finally {
405 await mounted.cleanup();
406 }
407 });
408​
409 it("uses client model visibility and ordering preferences", async () => {
410 const mounted = await mountPicker({
411 activeInstanceId: CLAUDE_INSTANCE_ID,
412 model: "claude-opus-4-6",
413 lockedProvider: null,
414 settings: {
415 ...DEFAULT_UNIFIED_SETTINGS,
416 providerModelPreferences: {
417 [CLAUDE_INSTANCE_ID]: {
418 hiddenModels: ["claude-opus-4-6"],
419 modelOrder: ["claude-haiku-4-5", "claude-sonnet-4-6"],
420 },
421 },
422 },
423 });
424​
425 try {
426 await page.getByRole("button").click();
427​
428 await vi.waitFor(() => {
429 expect(getVisibleModelNames()).toEqual(["Claude Haiku 4.5", "Claude Sonnet 4.6"]);
430 expect(getModelPickerListText()).not.toContain("Claude Opus 4.6");
431 });
432 } finally {
433 await mounted.cleanup();
434 }
435 });
436​
437 it("focuses the search input after selecting a sidebar provider", async () => {
438 const mounted = await mountPicker({
439 activeInstanceId: CLAUDE_INSTANCE_ID,
440 model: "claude-opus-4-6",
441 lockedProvider: null,
442 });
443​
444 try {
445 await page.getByRole("button").click();
446​
447 await vi.waitFor(() => {
448 expect(document.querySelector('[data-model-picker-provider="codex"]')).not.toBeNull();
449 });
450 await page.getByRole("button", { name: "Codex", exact: true }).click();
451​
452 await vi.waitFor(() => {
453 const searchInput = document.querySelector<HTMLInputElement>(
454 'input[placeholder="Search models..."]',
455 );
456 expect(searchInput).not.toBeNull();
457 expect(document.activeElement).toBe(searchInput);
458 });
459 } finally {
460 await mounted.cleanup();
461 }
462 });
463​
464 it("shows locked provider header and only its models in locked mode", async () => {
465 localStorage.setItem(
466 "t3code:client-settings:v1",
467 JSON.stringify({
468 ...DEFAULT_CLIENT_SETTINGS,
469 favorites: [
470 { provider: "codex", model: "gpt-5-codex" },
471 { provider: "claudeAgent", model: "claude-sonnet-4-6" },
472 ],
473 }),
474 );
475​
476 const mounted = await mountPicker({
477 activeInstanceId: CLAUDE_INSTANCE_ID,
478 model: "claude-opus-4-6",
479 lockedProvider: ProviderDriverKind.make("claudeAgent"),
480 });
481​
482 try {
483 await page.getByRole("button").click();
484​
485 await vi.waitFor(() => {
486 const text = document.body.textContent ?? "";
487 // Should show locked provider label
488 expect(text).toContain("Claude");
489 expect(getVisibleModelNames()).toEqual([
490 "Claude Sonnet 4.6",
491 "Claude Opus 4.6",
492 "Claude Haiku 4.5",
493 ]);
494 });
495 } finally {
496 localStorage.removeItem("t3code:client-settings:v1");
497 await mounted.cleanup();
498 }
499 });
500​
501 it("keeps an instance sidebar in locked mode when that provider has multiple instances", async () => {
502 const defaultCodexModels: ServerProvider["models"] = [
503 {
504 slug: "gpt-work",
505 name: "GPT Work",
506 isCustom: false,
507 capabilities: createModelCapabilities({ optionDescriptors: [] }),
508 },
509 ];
510 const personalCodexModels: ServerProvider["models"] = [
511 {
512 slug: "gpt-personal",
513 name: "GPT Personal",
514 isCustom: false,
515 capabilities: createModelCapabilities({ optionDescriptors: [] }),
516 },
517 ];
518 const isolatedCodexModels: ServerProvider["models"] = [
519 {
520 slug: "gpt-isolated",
521 name: "GPT Isolated",
522 isCustom: false,
523 capabilities: createModelCapabilities({ optionDescriptors: [] }),
524 },
525 ];
526 const providers: ReadonlyArray<ServerProvider> = [
527 {
528 ...buildCodexProvider(defaultCodexModels),
529 instanceId: "codex" as ProviderInstanceId,
530 displayName: "Codex Work",
531 accentColor: "#2563eb",
532 continuation: { groupKey: "codex:home:/Users/julius/.codex" },
533 },
534 {
535 ...buildCodexProvider(personalCodexModels),
536 instanceId: "codex_personal" as ProviderInstanceId,
537 displayName: "Codex Personal",
538 accentColor: "#dc2626",
539 continuation: { groupKey: "codex:home:/Users/julius/.codex" },
540 },
541 {
542 ...buildCodexProvider(isolatedCodexModels),
543 instanceId: "codex_isolated" as ProviderInstanceId,
544 displayName: "Codex Isolated",
545 accentColor: "#16a34a",
546 continuation: { groupKey: "codex:home:/Users/julius/.codex_isolated" },
547 },
548 TEST_PROVIDERS[1]!,
549 ];
550 const mounted = await mountPicker({
551 activeInstanceId: "codex" as ProviderInstanceId,
552 model: "gpt-work",
553 lockedProvider: ProviderDriverKind.make("codex"),
554 lockedContinuationGroupKey: "codex:home:/Users/julius/.codex",
555 providers,
556 });
557​
558 try {
559 await page.getByRole("button").click();
560​
561 await vi.waitFor(() => {
562 expect(getSidebarProviderOrder()).toEqual(["codex", "codex_personal"]);
563 expect(getModelPickerListText()).not.toContain("Codex Isolated");
564 expect(
565 document.querySelector<HTMLElement>('[data-model-picker-provider="codex_personal"]')
566 ?.dataset.providerAccentColor,
567 ).toBe("#dc2626");
568 expect(getModelPickerListText()).toContain("Codex Work");
569 expect(getVisibleModelNames()).toEqual(["GPT Work"]);
570 });
571​
572 await page.getByRole("button", { name: "Codex Personal" }).click();
573​
574 await vi.waitFor(() => {
575 expect(getModelPickerListText()).toContain("Codex Personal");
576 expect(getVisibleModelNames()).toEqual(["GPT Personal"]);
577 });
578 } finally {
579 await mounted.cleanup();
580 }
581 });
582​
583 it("falls back to the active provider's first model when props.model belongs to another provider (#1982)", async () => {
584 const host = document.createElement("div");
585 document.body.append(host);
586 const onInstanceModelChange = vi.fn();
587 const modelOptionsByInstance = new Map<ProviderInstanceId, ReadonlyArray<ModelEsque>>([
588 [
589 "claudeAgent" as ProviderInstanceId,
590 [
591 { slug: "claude-opus-4-6", name: "Claude Opus 4.6" },
592 { slug: "claude-sonnet-4-6", name: "Claude Sonnet 4.6" },
593 ],
594 ],
595 ["codex" as ProviderInstanceId, [{ slug: "gpt-5-codex", name: "GPT-5 Codex" }]],
596 ["cursor" as ProviderInstanceId, []],
597 ["opencode" as ProviderInstanceId, []],
598 ]);
599 const instanceEntries = sortProviderInstanceEntries(
600 deriveProviderInstanceEntries(TEST_PROVIDERS),
601 );
602 const screen = await render(
603 <ProviderModelPicker
604 activeInstanceId={"claudeAgent" as ProviderInstanceId}
605 model="gpt-5-codex"
606 lockedProvider={null}
607 instanceEntries={instanceEntries}
608 modelOptionsByInstance={modelOptionsByInstance}
609 onInstanceModelChange={onInstanceModelChange}
610 />,
611 { container: host },
612 );
613​
614 try {
615 const trigger = document.querySelector<HTMLElement>(
616 '[data-chat-provider-model-picker="true"]',
617 );
618 expect(trigger).not.toBeNull();
619 const label = trigger?.textContent ?? "";
620 expect(label).not.toContain("gpt-5-codex");
621 expect(label).toContain("Claude Opus 4.6");
622 } finally {
623 await screen.unmount();
624 host.remove();
625 }
626 });
627​
628 it("uses the trigger label for locked opencode rows", async () => {
629 const providers: ReadonlyArray<ServerProvider> = [
630 buildOpenCodeProvider([
631 {
632 slug: "github-copilot/claude-opus-4.5",
633 name: "Claude Opus 4.5",
634 subProvider: "GitHub Copilot",
635 shortName: "Opus 4.5",
636 isCustom: false,
637 capabilities: createModelCapabilities({
638 optionDescriptors: [
639 selectDescriptor("reasoningEffort", "Reasoning", [
640 { id: "low", label: "low" },
641 { id: "medium", label: "medium", isDefault: true },
642 { id: "high", label: "high" },
643 ]),
644 ],
645 }),
646 },
647 ]),
648 ];
649 const mounted = await mountPicker({
650 activeInstanceId: OPENCODE_INSTANCE_ID,
651 model: "github-copilot/claude-opus-4.5",
652 lockedProvider: ProviderDriverKind.make("opencode"),
653 providers,
654 });
655​
656 try {
657 await vi.waitFor(() => {
658 const trigger = document.querySelector<HTMLElement>(
659 '[data-chat-provider-model-picker="true"]',
660 );
661 expect(trigger?.textContent).toContain("GitHub Copilot");
662 expect(trigger?.textContent).toContain("Opus 4.5");
663 });
664​
665 await page.getByRole("button").click();
666​
667 await vi.waitFor(() => {
668 expect(getVisibleModelNames()).toEqual(["GitHub Copilot · Opus 4.5"]);
669 });
670 } finally {
671 await mounted.cleanup();
672 }
673 });
674​
675 it("searches models by name in flat list", async () => {
676 const mounted = await mountPicker({
677 activeInstanceId: CLAUDE_INSTANCE_ID,
678 model: "claude-opus-4-6",
679 lockedProvider: null,
680 });
681​
682 try {
683 await page.getByRole("button").click();
684​
685 await vi.waitFor(() => {
686 const text = document.body.textContent ?? "";
687 expect(text).toContain("Claude Opus 4.6");
688 expect(text).not.toContain("GPT-5 Codex");
689 });
690​
691 // Find and type in search box
692 const searchInput = page.getByPlaceholder("Search models...");
693 await searchInput.fill("claude");
694​
695 await vi.waitFor(() => {
696 const text = document.body.textContent ?? "";
697 expect(text).toContain("Claude Opus 4.6");
698 expect(text).not.toContain("GPT-5 Codex");
699 });
700 } finally {
701 await mounted.cleanup();
702 }
703 });
704​
705 it("supports arrow-key navigation in the model picker", async () => {
706 const mounted = await mountPicker({
707 activeInstanceId: CLAUDE_INSTANCE_ID,
708 model: "claude-opus-4-6",
709 lockedProvider: ProviderDriverKind.make("claudeAgent"),
710 });
711​
712 try {
713 await page.getByRole("button").click();
714​
715 const searchInput = page.getByPlaceholder("Search models...");
716 await userEvent.click(searchInput);
717 await userEvent.keyboard("{ArrowDown}");
718 await vi.waitFor(() => {
719 const highlightedItem = document.querySelector<HTMLElement>(
720 '[data-slot="combobox-item"][data-highlighted]',
721 );
722 expect(highlightedItem).not.toBeNull();
723 expect(highlightedItem?.textContent).toContain("Claude Opus 4.6");
724 });
725 await userEvent.keyboard("{ArrowDown}");
726 await vi.waitFor(() => {
727 const highlightedItem = document.querySelector<HTMLElement>(
728 '[data-slot="combobox-item"][data-highlighted]',
729 );
730 expect(highlightedItem).not.toBeNull();
731 expect(highlightedItem?.textContent).toContain("Claude Sonnet 4.6");
732 });
733 await userEvent.keyboard("{Enter}");
734​
735 expect(mounted.onProviderModelChange).toHaveBeenCalledWith(
736 "claudeAgent",
737 "claude-sonnet-4-6",
738 );
739 } finally {
740 await mounted.cleanup();
741 }
742 });
743​
744 it("hides the provider sidebar while searching", async () => {
745 const mounted = await mountPicker({
746 activeInstanceId: CLAUDE_INSTANCE_ID,
747 model: "claude-opus-4-6",
748 lockedProvider: null,
749 });
750​
751 try {
752 await page.getByRole("button").click();
753​
754 await vi.waitFor(() => {
755 expect(getSidebarProviderOrder().length).toBeGreaterThan(0);
756 });
757​
758 await page.getByPlaceholder("Search models...").fill("cla");
759​
760 await vi.waitFor(() => {
761 expect(getSidebarProviderOrder()).toEqual([]);
762 });
763 } finally {
764 await mounted.cleanup();
765 }
766 });
767​
768 it("closes the picker when escape is pressed in search", async () => {
769 const mounted = await mountPicker({
770 activeInstanceId: CLAUDE_INSTANCE_ID,
771 model: "claude-opus-4-6",
772 lockedProvider: null,
773 });
774​
775 try {
776 await page.getByRole("button").click();
777​
778 const searchInput = page.getByPlaceholder("Search models...");
779 await searchInput.click();
780 const searchInputElement = document.querySelector<HTMLInputElement>(
781 'input[placeholder="Search models..."]',
782 );
783 expect(searchInputElement).not.toBeNull();
784 searchInputElement!.dispatchEvent(
785 new KeyboardEvent("keydown", { key: "Escape", bubbles: true }),
786 );
787​
788 await vi.waitFor(() => {
789 expect(document.querySelector(".model-picker-list")).toBeNull();
790 });
791 } finally {
792 await mounted.cleanup();
793 }
794 });
795​
796 it("searches models by provider name", async () => {
797 const mounted = await mountPicker({
798 activeInstanceId: CLAUDE_INSTANCE_ID,
799 model: "claude-opus-4-6",
800 lockedProvider: null,
801 });
802​
803 try {
804 await page.getByRole("button").click();
805​
806 await vi.waitFor(() => {
807 const text = document.body.textContent ?? "";
808 expect(text).toContain("Claude Opus 4.6");
809 expect(text).not.toContain("GPT-5 Codex");
810 });
811​
812 // Search by provider name
813 const searchInput = page.getByPlaceholder("Search models...");
814 await searchInput.fill("codex");
815​
816 await vi.waitFor(() => {
817 const listText = getModelPickerListText();
818 expect(listText).toContain("GPT-5 Codex");
819 expect(listText).not.toContain("Claude Opus 4.6");
820 });
821 } finally {
822 await mounted.cleanup();
823 }
824 });
825​
826 it("matches fuzzy multi-token queries across provider and model text", async () => {
827 const providers: ReadonlyArray<ServerProvider> = [
828 buildCodexProvider([
829 {
830 slug: "gpt-5-codex",
831 name: "GPT-5 Codex",
832 isCustom: false,
833 capabilities: createModelCapabilities({
834 optionDescriptors: [
835 selectDescriptor("reasoningEffort", "Reasoning", [
836 { id: "low", label: "low" },
837 { id: "medium", label: "medium", isDefault: true },
838 { id: "high", label: "high" },
839 ]),
840 booleanDescriptor("fastMode", "Fast Mode"),
841 ],
842 }),
843 },
844 ]),
845 buildOpenCodeProvider([
846 {
847 slug: "github-copilot/claude-opus-4.7",
848 name: "Claude Opus 4.7",
849 subProvider: "GitHub Copilot",
850 isCustom: false,
851 capabilities: createModelCapabilities({
852 optionDescriptors: [
853 selectDescriptor("reasoningEffort", "Reasoning", [
854 { id: "low", label: "low" },
855 { id: "medium", label: "medium", isDefault: true },
856 { id: "high", label: "high" },
857 ]),
858 ],
859 }),
860 },
861 ]),
862 ];
863 const mounted = await mountPicker({
864 activeInstanceId: OPENCODE_INSTANCE_ID,
865 model: "github-copilot/claude-opus-4.7",
866 lockedProvider: null,
867 providers,
868 });
869​
870 try {
871 await page.getByRole("button").click();
872 await page.getByPlaceholder("Search models...").fill("coplt op");
873​
874 await vi.waitFor(() => {
875 const listText = getModelPickerListText();
876 expect(listText).toContain("Claude Opus 4.7");
877 expect(listText).not.toContain("GPT-5 Codex");
878 });
879 } finally {
880 await mounted.cleanup();
881 }
882 });
883​
884 it("renders each search result with its own provider branding", async () => {
885 const providers: ReadonlyArray<ServerProvider> = [
886 buildOpenCodeProvider([
887 {
888 slug: "github-copilot/claude-opus-4.7",
889 name: "Claude Opus 4.7",
890 subProvider: "GitHub Copilot",
891 isCustom: false,
892 capabilities: createModelCapabilities({
893 optionDescriptors: [
894 selectDescriptor("reasoningEffort", "Reasoning", [
895 { id: "low", label: "low" },
896 { id: "medium", label: "medium", isDefault: true },
897 { id: "high", label: "high" },
898 ]),
899 ],
900 }),
901 },
902 ]),
903 {
904 ...TEST_PROVIDERS[1]!,
905 models: [
906 {
907 slug: "claude-opus-4-6",
908 name: "Claude Opus 4.6",
909 isCustom: false,
910 capabilities: createModelCapabilities({
911 optionDescriptors: [
912 selectDescriptor("effort", "Reasoning", [
913 { id: "low", label: "low" },
914 { id: "medium", label: "medium", isDefault: true },
915 { id: "high", label: "high" },
916 { id: "max", label: "max" },
917 ]),
918 booleanDescriptor("thinking", "Thinking"),
919 ],
920 }),
921 },
922 ],
923 },
924 ];
925 const mounted = await mountPicker({
926 activeInstanceId: OPENCODE_INSTANCE_ID,
927 model: "github-copilot/claude-opus-4.7",
928 lockedProvider: null,
929 providers,
930 });
931​
932 try {
933 await page.getByRole("button").click();
934 await page.getByPlaceholder("Search models...").fill("opus");
935​
936 await vi.waitFor(() => {
937 const listText = getModelPickerListText();
938 expect(listText).toContain("OpenCode · GitHub Copilot");
939 expect(listText).toContain("Claude");
940 expect(listText).not.toContain("OpenCodeClaude Opus 4.6");
941 });
942 } finally {
943 await mounted.cleanup();
944 }
945 });
946​
947 it("toggles favorite stars when clicked", async () => {
948 localStorage.removeItem("t3code:client-settings:v1");
949​
950 const mounted = await mountPicker({
951 activeInstanceId: CLAUDE_INSTANCE_ID,
952 model: "claude-opus-4-6",
953 lockedProvider: null,
954 });
955​
956 try {
957 await page.getByRole("button").click();
958​
959 await vi.waitFor(() => {
960 const text = document.body.textContent ?? "";
961 expect(text).toContain("Claude Opus 4.6");
962 });
963​
964 const getFirstStarButton = () => {
965 const starButton = document.querySelector<HTMLButtonElement>(
966 'button[aria-label*="favorites"]',
967 );
968 expect(starButton).not.toBeNull();
969 return starButton!;
970 };
971​
972 const firstStar = getFirstStarButton();
973 const initialAriaLabel = firstStar.getAttribute("aria-label");
974 expect(
975 initialAriaLabel === "Add to favorites" || initialAriaLabel === "Remove from favorites",
976 ).toBe(true);
977​
978 await page.getByRole("button", { name: initialAriaLabel! }).first().click();
979​
980 const expectedAriaLabel =
981 initialAriaLabel === "Add to favorites" ? "Remove from favorites" : "Add to favorites";
982​
983 await vi.waitFor(() => {
984 expect(getFirstStarButton().getAttribute("aria-label")).toBe(expectedAriaLabel);
985 });
986 } finally {
987 await mounted.cleanup();
988 localStorage.removeItem("t3code:client-settings:v1");
989 }
990 });
991​
992 it("does not duplicate favorited models across favorites and all models sections", async () => {
993 localStorage.removeItem("t3code:client-settings:v1");
994​
995 const mounted = await mountPicker({
996 activeInstanceId: CLAUDE_INSTANCE_ID,
997 model: "claude-opus-4-6",
998 lockedProvider: null,
999 });
1000​
1001 try {
1002 await page.getByRole("button").click();
1003​
1004 await vi.waitFor(() => {
1005 const text = document.body.textContent ?? "";
1006 expect(text).toContain("Claude Opus 4.6");
1007 });
1008​
1009 const favoriteButton = page.getByRole("button", {
1010 name: "Add to favorites",
1011 });
1012 await favoriteButton.first().click();
1013​
1014 await vi.waitFor(async () => {
1015 const favoritedModelRows = Array.from(
1016 getModelPickerListElement().querySelectorAll<HTMLDivElement>("div.font-medium"),
1017 ).filter((element) => element.textContent?.trim() === "Claude Opus 4.6");
1018 expect(favoritedModelRows.length).toBe(1);
1019 });
1020 } finally {
1021 await mounted.cleanup();
1022 localStorage.removeItem("t3code:client-settings:v1");
1024 });
1025​
1026 it("shows favorited models first within the selected provider list", async () => {
1027 localStorage.setItem(
1028 "t3code:client-settings:v1",
1029 JSON.stringify({
1030 ...DEFAULT_CLIENT_SETTINGS,
1031 favorites: [{ provider: "codex", model: "gpt-5.3-codex" }],
1032 }),
1033 );
1034​
1035 const mounted = await mountPicker({
1036 model: "gpt-5-codex",
1037 lockedProvider: null,
1038 });
1039​
1040 try {
1041 await page.getByRole("button").click();
1042 await page.getByRole("button", { name: "Codex", exact: true }).click();
1043​
1044 await vi.waitFor(() => {
1045 expect(getVisibleModelNames().slice(0, 2)).toEqual(["GPT-5.3 Codex", "GPT-5 Codex"]);
1046 });
1047 } finally {
1048 await mounted.cleanup();
1049 localStorage.removeItem("t3code:client-settings:v1");
1051 });
1052​
1053 it("dispatches callback with correct provider and model when selected", async () => {
1054 const mounted = await mountPicker({
1055 activeInstanceId: CLAUDE_INSTANCE_ID,
1056 model: "claude-opus-4-6",
1057 lockedProvider: ProviderDriverKind.make("claudeAgent"),
1058 });
1059​
1060 try {
1061 await page.getByRole("button").click();
1062​
1063 await vi.waitFor(() => {
1064 const text = document.body.textContent ?? "";
1065 expect(text).toContain("Claude Sonnet 4.6");
1066 });
1067​
1068 // Click on a model
1069 const modelRow = page.getByText("Claude Sonnet 4.6").first();
1070 await modelRow.click();
1071​
1072 // Verify callback was called with correct values
1073 expect(mounted.onProviderModelChange).toHaveBeenCalledWith(
1074 "claudeAgent",
1075 "claude-sonnet-4-6",
1076 );
1077 } finally {
1078 await mounted.cleanup();
1080 });
1081​
1082 it("only shows codex spark when the server reports it", async () => {
1083 const providersWithoutSpark: ReadonlyArray<ServerProvider> = [
1084 buildCodexProvider([
1086 slug: "gpt-5.3-codex",
1087 name: "GPT-5.3 Codex",
1088 isCustom: false,
1089 capabilities: createModelCapabilities({
1090 optionDescriptors: [
1091 selectDescriptor("reasoningEffort", "Reasoning", [
1092 { id: "low", label: "low" },
1093 { id: "medium", label: "medium", isDefault: true },
1094 { id: "high", label: "high" },
1095 ]),
1096 booleanDescriptor("fastMode", "Fast Mode"),
1097 ],
1098 }),
1099 },
1100 ]),
1101 TEST_PROVIDERS[1]!,
1102 ];
1103 const providersWithSpark: ReadonlyArray<ServerProvider> = [
1104 buildCodexProvider([
1106 slug: "gpt-5.3-codex",
1107 name: "GPT-5.3 Codex",
1108 isCustom: false,
1109 capabilities: createModelCapabilities({
1110 optionDescriptors: [
1111 selectDescriptor("reasoningEffort", "Reasoning", [
1112 { id: "low", label: "low" },
1113 { id: "medium", label: "medium", isDefault: true },
1114 { id: "high", label: "high" },
1115 ]),
1116 booleanDescriptor("fastMode", "Fast Mode"),
1117 ],
1118 }),
1119 },
1121 slug: "gpt-5.3-codex-spark",
1122 name: "GPT-5.3 Codex Spark",
1123 isCustom: false,
1124 capabilities: createModelCapabilities({
1125 optionDescriptors: [
1126 selectDescriptor("reasoningEffort", "Reasoning", [
1127 { id: "low", label: "low" },
1128 { id: "medium", label: "medium", isDefault: true },
1129 { id: "high", label: "high" },
1130 ]),
1131 booleanDescriptor("fastMode", "Fast Mode"),
1132 ],
1133 }),
1134 },
1135 ]),
1136 TEST_PROVIDERS[1]!,
1137 ];
1138​
1139 const hidden = await mountPicker({
1140 model: "gpt-5.3-codex",
1141 lockedProvider: null,
1142 providers: providersWithoutSpark,
1143 });
1144​
1145 try {
1146 await page.getByRole("button").click();
1147​
1148 await vi.waitFor(() => {
1149 const text = document.body.textContent ?? "";
1150 expect(text).toContain("GPT-5.3 Codex");
1151 expect(text).not.toContain("GPT-5.3 Codex Spark");
1152 });
1153 } finally {
1154 await hidden.cleanup();
1156​
1157 const visible = await mountPicker({
1158 model: "gpt-5.3-codex",
1159 lockedProvider: null,
1160 providers: providersWithSpark,
1161 });
1162​
1163 try {
1164 await page.getByRole("button").click();
1165​
1166 await vi.waitFor(() => {
1167 expect(document.body.textContent ?? "").toContain("GPT-5.3 Codex Spark");
1168 });
1169 } finally {
1170 await visible.cleanup();
1172 });
1173​
1174 it("shows disabled providers grayed out in sidebar", async () => {
1175 const disabledProviders = TEST_PROVIDERS.slice();
1176 const claudeIndex = disabledProviders.findIndex(
1177 (provider) => provider.instanceId === ProviderInstanceId.make("claudeAgent"),
1178 );
1179 if (claudeIndex >= 0) {
1180 const claudeProvider = disabledProviders[claudeIndex]!;
1181 disabledProviders[claudeIndex] = {
1182 ...claudeProvider,
1183 enabled: false,
1184 status: "disabled",
1185 };
1187​
1188 const mounted = await mountPicker({
1189 model: "gpt-5-codex",
1190 lockedProvider: null,
1191 providers: disabledProviders,
1192 });
1193​
1194 try {
1195 await page.getByRole("button").click();
1196​
1197 await vi.waitFor(() => {
1198 const text = document.body.textContent ?? "";
1199 expect(text).toContain("GPT-5 Codex");
1200 // Disabled provider should not have its models shown
1201 expect(text).not.toContain("Claude Opus 4.6");
1202 });
1203 } finally {
1204 await mounted.cleanup();
1206 });
1207​
1208 it("accepts outline trigger styling", async () => {
1209 const mounted = await mountPicker({
1210 model: "gpt-5-codex",
1211 lockedProvider: null,
1212 triggerVariant: "outline",
1213 });
1214​
1215 try {
1216 const button = document.querySelector("button");
1217 if (!(button instanceof HTMLButtonElement)) {
1218 throw new Error("Expected picker trigger button to be rendered.");
1220 expect(button.className).toContain("border-input");
1221 expect(button.className).toContain("bg-popover");
1222 } finally {
1223 await mounted.cleanup();
1225 });
1226});