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

ProviderModelPicker.browser.tsx

1,088 lines32.1 KB

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