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

ProviderModelPicker.test.tsx

102 lines3.2 KB

1import { ProviderDriverKind, ProviderInstanceId, type ServerProvider } from "@t3tools/contracts";
2import { renderToStaticMarkup } from "react-dom/server";
3import { describe, expect, it } from "vite-plus/test";
4​
5import { deriveProviderInstanceEntries } from "../../providerInstances";
6import { ProviderModelPicker } from "./ProviderModelPicker";
7import type { ModelEsque } from "./providerIconUtils";
8​
9function providerEntry(instanceId: string, driver: string) {
10 const provider: ServerProvider = {
11 instanceId: ProviderInstanceId.make(instanceId),
12 driver: ProviderDriverKind.make(driver),
13 enabled: true,
14 installed: true,
15 version: null,
16 status: "ready",
17 auth: { status: "authenticated" },
18 checkedAt: "2026-08-28T00:00:00.000Z",
19 models: [],
20 slashCommands: [],
21 skills: [],
22 };
23 return deriveProviderInstanceEntries([provider])[0]!;
25​
26function renderPicker(input: {
27 instanceId: string;
28 driver: string;
29 model: string;
30 options: ReadonlyArray<ModelEsque>;
31 includeEntry?: boolean;
32}) {
33 const instanceId = ProviderInstanceId.make(input.instanceId);
34 const entry = providerEntry(input.instanceId, input.driver);
35 return renderToStaticMarkup(
36 <ProviderModelPicker
37 activeInstanceId={instanceId}
38 model={input.model}
39 lockedProvider={null}
40 instanceEntries={input.includeEntry === false ? [] : [entry]}
41 modelOptionsByInstance={new Map([[instanceId, input.options]])}
42 onInstanceModelChange={() => {}}
43 />,
44 );
46​
47describe("ProviderModelPicker", () => {
48 it("shows a missing model slug for a custom OpenCode instance", () => {
49 const markup = renderPicker({
50 instanceId: "team_runtime",
51 driver: "opencode",
52 model: "openrouter/missing-model",
53 options: [{ slug: "openrouter/fallback", name: "Fallback model" }],
54 });
55​
56 expect(markup).toContain("openrouter/missing-model");
57 expect(markup).not.toContain("Fallback model");
58 });
59​
60 it.each(["codex", "claudeAgent", "cursor", "grok"])(
61 "uses the first option label for a missing %s model",
62 (driver) => {
63 const markup = renderPicker({
64 instanceId: `${driver}_work`,
65 driver,
66 model: "missing-model",
67 options: [{ slug: "fallback-model", name: "Fallback model" }],
68 });
69​
70 expect(markup).toContain("Fallback model");
71 expect(markup).not.toContain(">missing-model<");
72 },
73 );
74​
75 it("prefers a matching model for OpenCode", () => {
76 const markup = renderPicker({
77 instanceId: "custom_runtime",
78 driver: "opencode",
79 model: "openrouter/selected",
80 options: [
81 { slug: "openrouter/fallback", name: "Fallback model" },
82 { slug: "openrouter/selected", name: "Selected model" },
83 ],
84 });
85​
86 expect(markup).toContain("Selected model");
87 expect(markup).not.toContain("Fallback model");
88 });
89​
90 it("uses the first option when the active instance entry is missing", () => {
91 const markup = renderPicker({
92 instanceId: "missing_instance",
93 driver: "opencode",
94 model: "missing-model",
95 options: [{ slug: "fallback-model", name: "Fallback model" }],
96 includeEntry: false,
97 });
98​
99 expect(markup).toContain("Fallback model");
100 expect(markup).not.toContain(">missing-model<");
101 });
102});