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

ModelPickerContent.test.ts

215 lines6.3 KB

1import {
2 ANTIGRAVITY_DEFAULT_MODEL,
3 ProviderDriverKind,
4 ProviderInstanceId,
5 type ServerProvider,
6} from "@t3tools/contracts";
7import { describe, expect, it } from "vite-plus/test";
8​
9import { deriveProviderInstanceEntries } from "../../providerInstances";
10import {
11 resolveModelPickerSelectedModel,
12 shouldIncludeModelPickerOption,
13 shouldOfferModelPickerSetup,
14} from "./ModelPickerContent";
15​
16function entry(status: ServerProvider["status"], driver = "opencode") {
17 return deriveProviderInstanceEntries([
18 {
19 instanceId: ProviderInstanceId.make(`${driver}_work`),
20 driver: ProviderDriverKind.make(driver),
21 enabled: true,
22 installed: true,
23 version: null,
24 status,
25 auth: { status: "authenticated" },
26 checkedAt: "2026-08-28T00:00:00.000Z",
27 models: [],
28 slashCommands: [],
29 skills: [],
30 },
31 ])[0]!;
33​
34describe("shouldIncludeModelPickerOption", () => {
35 it.each(["ready", "error"] as const)(
36 "never offers the internal Antigravity default marker as a model when %s",
37 (status) => {
38 const providerEntry = entry(status, "antigravity");
39 expect(
40 shouldIncludeModelPickerOption({
41 entry: providerEntry,
42 option: {
43 slug: ANTIGRAVITY_DEFAULT_MODEL,
44 name: ANTIGRAVITY_DEFAULT_MODEL,
45 isUnavailable: true,
46 },
47 activeInstanceId: providerEntry.instanceId,
48 activeModel: ANTIGRAVITY_DEFAULT_MODEL,
49 }),
50 ).toBe(false);
51 },
52 );
53​
54 it.each([
55 ["opencode", "error"],
56 ["opencode", "warning"],
57 ["antigravity", "error"],
58 ["antigravity", "warning"],
59 ] as const)(
60 "keeps only the active synthetic %s row when the provider status is %s",
61 (driver, status) => {
62 const providerEntry = entry(status, driver);
63 const activeInstanceId = providerEntry.instanceId;
64 const activeModel = "missing-model";
65​
66 expect(
67 shouldIncludeModelPickerOption({
68 entry: providerEntry,
69 option: {
70 slug: activeModel,
71 name: activeModel,
72 isUnavailable: true,
73 },
74 activeInstanceId,
75 activeModel,
76 }),
77 ).toBe(true);
78 expect(
79 shouldIncludeModelPickerOption({
80 entry: providerEntry,
81 option: { slug: "stale/model", name: "Stale model" },
82 activeInstanceId,
83 activeModel,
84 }),
85 ).toBe(false);
86 expect(
87 shouldIncludeModelPickerOption({
88 entry: providerEntry,
89 option: {
90 slug: "other/missing",
91 name: "Other missing",
92 isUnavailable: true,
93 },
94 activeInstanceId,
95 activeModel,
96 }),
97 ).toBe(false);
98 expect(
99 shouldIncludeModelPickerOption({
100 entry: providerEntry,
101 option: { slug: activeModel, name: activeModel, isUnavailable: true },
102 activeInstanceId: ProviderInstanceId.make(`${driver}_personal`),
103 activeModel,
104 }),
105 ).toBe(false);
106 },
107 );
108});
109​
110describe("resolveModelPickerSelectedModel", () => {
111 it("follows the catalog default for the marker but keeps an explicit native model", () => {
112 const driverKind = ProviderDriverKind.make("antigravity");
113 const previousOptions = [
114 { slug: "gemini-fast", name: "Gemini Fast", aliases: [ANTIGRAVITY_DEFAULT_MODEL] },
115 { slug: "gemini-pro", name: "Gemini Pro" },
116 ];
117 const nextOptions = [
118 { slug: "gemini-fast", name: "Gemini Fast" },
119 { slug: "gemini-pro", name: "Gemini Pro", aliases: [ANTIGRAVITY_DEFAULT_MODEL] },
120 ];
121​
122 expect(
123 resolveModelPickerSelectedModel({
124 driverKind,
125 model: ANTIGRAVITY_DEFAULT_MODEL,
126 options: previousOptions,
127 })?.slug,
128 ).toBe("gemini-fast");
129 expect(
130 resolveModelPickerSelectedModel({
131 driverKind,
132 model: ANTIGRAVITY_DEFAULT_MODEL,
133 options: nextOptions,
134 })?.slug,
135 ).toBe("gemini-pro");
136 expect(
137 resolveModelPickerSelectedModel({
138 driverKind,
139 model: "gemini-fast",
140 options: nextOptions,
141 })?.slug,
142 ).toBe("gemini-fast");
143 });
144​
145 it("does not guess the default from the first model in a catalog", () => {
146 expect(
147 resolveModelPickerSelectedModel({
148 driverKind: ProviderDriverKind.make("antigravity"),
149 model: ANTIGRAVITY_DEFAULT_MODEL,
150 options: [{ slug: "gemini-fast", name: "Gemini Fast" }],
151 }),
152 ).toBeUndefined();
153 });
154});
155​
156describe("shouldOfferModelPickerSetup", () => {
157 const availableModel = { slug: "gemini-3.1-pro", name: "Gemini 3.1 Pro" };
158​
159 it("offers setup before an Antigravity account has models", () => {
160 expect(shouldOfferModelPickerSetup(entry("error", "antigravity"), [])).toBe(true);
161 });
162​
163 it("offers setup after sign-out even if a model remains cached", () => {
164 const providerEntry = entry("ready", "antigravity");
165 expect(
166 shouldOfferModelPickerSetup(
167 {
168 ...providerEntry,
169 snapshot: { ...providerEntry.snapshot, auth: { status: "unauthenticated" } },
170 },
171 [availableModel],
172 ),
173 ).toBe(true);
174 });
175​
176 it("offers setup when the only model is an unavailable saved selection", () => {
177 expect(
178 shouldOfferModelPickerSetup(entry("ready", "antigravity"), [
179 { ...availableModel, isUnavailable: true },
180 ]),
181 ).toBe(true);
182 });
183​
184 it("does not offer setup for a ready account with available models", () => {
185 expect(shouldOfferModelPickerSetup(entry("ready", "antigravity"), [availableModel])).toBe(
186 false,
187 );
188 });
189​
190 it("does not restore a disabled provider while its status snapshot is stale", () => {
191 expect(
192 shouldOfferModelPickerSetup({ ...entry("error", "antigravity"), enabled: false }, []),
193 ).toBe(false);
194 });
195​
196 it("keeps providers without integrated setup on their existing path", () => {
197 expect(shouldOfferModelPickerSetup(entry("error", "codex"), [])).toBe(false);
198 });
199​
200 it("uses the environment's setup capability for other drivers", () => {
201 const providerEntry = entry("error", "custom_driver");
202 expect(
203 shouldOfferModelPickerSetup(
204 {
205 ...providerEntry,
206 snapshot: {
207 ...providerEntry.snapshot,
208 setup: { canAuthenticate: true, canInstall: false },
209 },
210 },
211 [],
212 ),
213 ).toBe(true);
214 });
215});