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

providerStatus.test.ts

278 lines8.5 KB

1import { ProviderDriverKind, ProviderInstanceId, type ServerProvider } from "@t3tools/contracts";
2import { describe, expect, it } from "vite-plus/test";
3​
4import {
5 getProviderReinstallCommand,
6 getProviderSummary,
7 getProviderVersionAdvisoryPresentation,
8 getProviderStatusKey,
9} from "./providerStatus";
10​
11const provider: ServerProvider = {
12 instanceId: ProviderInstanceId.make("codex"),
13 driver: ProviderDriverKind.make("codex"),
14 enabled: true,
15 installed: true,
16 version: "1.0.0",
17 status: "ready",
18 auth: { status: "authenticated", label: "ChatGPT" },
19 checkedAt: "2026-08-23T00:00:00.000Z",
20 models: [],
21 slashCommands: [],
22 skills: [],
23};
24​
25describe("getProviderSummary", () => {
26 it("does not hide a provider error behind a previous authenticated state", () => {
27 expect(
28 getProviderSummary({
29 ...provider,
30 status: "error",
31 message: "The provider process failed to start.",
32 }),
33 ).toEqual({
34 headline: "Unavailable",
35 detail: "The provider process failed to start.",
36 });
37 });
38​
39 it("keeps authentication failures actionable when their provider status is error", () => {
40 expect(
41 getProviderSummary({
42 ...provider,
43 status: "error",
44 auth: { status: "unauthenticated" },
45 message: "Run codex login.",
46 }),
47 ).toEqual({
48 headline: "Not authenticated",
49 detail: "Run codex login.",
50 });
51 });
52});
53​
54describe("Antigravity with unchecked sign-in", () => {
55 const unchecked: ServerProvider = {
56 ...provider,
57 instanceId: ProviderInstanceId.make("antigravity"),
58 driver: ProviderDriverKind.make("antigravity"),
59 status: "warning",
60 auth: { status: "unknown" },
61 message: "Antigravity is installed. Google account access is not checked yet.",
62 };
63​
64 it("presents an unchecked Google sign-in neutrally without claiming authentication is required", () => {
65 for (const auth of [unchecked.auth, { status: "unknown", type: "oauth-personal" }] as const) {
66 const candidate = { ...unchecked, auth };
67 expect.soft(getProviderSummary(candidate)).toEqual({
68 headline: "Installed · Sign-in not checked",
69 detail: unchecked.message,
70 });
71 expect(getProviderStatusKey(candidate)).toBe("neutral");
72 }
73 });
74​
75 // regression: #18623 neutral unchecked-sign-in display must not mask real warnings
76 it("preserves actionable warnings, failures and disabled states outside unchecked Google sign-in", () => {
77 const cases = [
78 {
79 name: "confirmed sign-out",
80 change: { auth: { status: "unauthenticated" } },
81 headline: "Not authenticated",
82 status: "warning",
83 },
84 {
85 name: "warning despite known authentication",
86 change: { auth: { status: "authenticated" } },
87 headline: "Needs attention",
88 status: "warning",
89 },
90 {
91 name: "probe failure",
92 change: { status: "error" },
93 headline: "Unavailable",
94 status: "error",
95 },
96 {
97 name: "missing CLI",
98 change: { installed: false },
99 headline: "Not found",
100 status: "warning",
101 },
102 {
103 name: "API key authentication",
104 change: { auth: { status: "unknown", type: "gemini-api-key" } },
105 headline: "Needs attention",
106 status: "warning",
107 },
108 {
109 name: "Agent Platform authentication",
110 change: { auth: { status: "unknown", type: "agent-platform" } },
111 headline: "Needs attention",
112 status: "warning",
113 },
114 {
115 name: "another provider",
116 change: { driver: provider.driver },
117 headline: "Needs attention",
118 status: "warning",
119 },
120 {
121 name: "disabled provider",
122 change: { enabled: false },
123 headline: "Disabled",
124 status: "disabled",
125 },
126 ] as const;
127 for (const { name, change, headline, status } of cases) {
128 const candidate = { ...unchecked, ...change };
129 expect.soft(getProviderSummary(candidate).headline, name).toBe(headline);
130 expect.soft(getProviderStatusKey(candidate), name).toBe(status);
131 }
132 });
133});
134​
135it("does not suggest copying a command that installs an incompatible latest version", () => {
136 const advisory = {
137 status: "behind_latest" as const,
138 currentVersion: "1.0.0",
139 latestVersion: "2.0.0",
140 updateCommand: "npm install -g fixture@latest",
141 canUpdate: true,
142 checkedAt: provider.checkedAt,
143 message: null,
144 };
145 const compatibility = {
146 status: "supported" as const,
147 latestVersionStatus: "broken" as const,
148 message: null,
149 recommendedRange: null,
150 recommendedVersion: null,
151 };
152 expect(getProviderVersionAdvisoryPresentation(advisory, compatibility)).toBeNull();
153 expect(
154 getProviderVersionAdvisoryPresentation(advisory, { ...compatibility, status: "broken" }, false),
155 ).toBeNull();
156 expect(
157 getProviderVersionAdvisoryPresentation(advisory, {
158 ...compatibility,
159 latestVersionStatus: "supported",
160 }),
161 ).not.toBeNull();
162});
163​
164it("does not offer an update that cannot change a limited-support version", () => {
165 // OpenCode 1.18.35 is the newest `opencode-ai`; the recommended 2.x ships as another package.
166 const advisory = {
167 status: "current" as const,
168 currentVersion: "1.18.35",
169 latestVersion: "1.18.35",
170 updateCommand: "npm install -g opencode-ai@latest",
171 canUpdate: true,
172 checkedAt: provider.checkedAt,
173 message: null,
174 };
175 const compatibility = {
176 status: "graceful" as const,
177 latestVersionStatus: "graceful" as const,
178 message: null,
179 recommendedRange: ">=2.0.18",
180 recommendedVersion: null,
181 };
182 expect(getProviderVersionAdvisoryPresentation(advisory, compatibility)).toEqual({
183 title: "Limited support",
184 detail: "Use >=2.0.18 for full support.",
185 updateCommand: null,
186 emphasis: "normal",
187 targetVersion: null,
188 });
189 expect(
190 getProviderVersionAdvisoryPresentation(
191 { ...advisory, status: "behind_latest", currentVersion: "1.18.34" },
192 compatibility,
193 )?.updateCommand,
194 ).toBe(advisory.updateCommand);
195});
196​
197it("shows compatibility in the version popover even when the installed version is current", () => {
198 const advisory = {
199 status: "current" as const,
200 currentVersion: "2.0.0",
201 latestVersion: "2.0.0",
202 updateCommand: "npm install -g fixture@latest",
203 canUpdate: true,
204 checkedAt: provider.checkedAt,
205 message: null,
206 };
207 const compatibility = {
208 status: "broken" as const,
209 latestVersionStatus: "broken" as const,
210 message: "This version drops turns. Use 1.9.0.",
211 recommendedRange: null,
212 recommendedVersion: "1.9.0",
213 };
214 expect(getProviderVersionAdvisoryPresentation(advisory, compatibility)).toEqual({
215 title: "Known broken version",
216 detail: compatibility.message,
217 updateCommand: null,
218 emphasis: "strong",
219 targetVersion: "1.9.0",
220 });
221 expect(
222 getProviderVersionAdvisoryPresentation(undefined, {
223 ...compatibility,
224 status: "graceful",
225 recommendedVersion: null,
226 recommendedRange: ">=2.1.0",
227 message: null,
228 }),
229 ).toEqual({
230 title: "Limited support",
231 detail: "Use >=2.1.0 for full support.",
232 updateCommand: null,
233 emphasis: "normal",
234 targetVersion: null,
235 });
236});
237​
238it("offers a reinstall only for an install that lost its platform package", () => {
239 const broken: ServerProvider = {
240 ...provider,
241 version: null,
242 status: "error",
243 message:
244 "Codex app-server provider probe failed: Error: Missing optional dependency @openai/codex-linux-x64.",
245 versionAdvisory: {
246 status: "unknown",
247 currentVersion: null,
248 latestVersion: null,
249 updateCommand: "npm install -g @openai/codex@latest",
250 canUpdate: true,
251 checkedAt: provider.checkedAt,
252 message: null,
253 },
254 };
255 expect(getProviderReinstallCommand(broken)).toBe("npm install -g @openai/codex@latest");
256 expect(getProviderReinstallCommand({ ...broken, message: "spawn codex EACCES" })).toBeNull();
257 expect(getProviderReinstallCommand({ ...broken, version: "0.167.2" })).toBeNull();
258 expect(
259 getProviderReinstallCommand({
260 ...broken,
261 versionAdvisory: { ...broken.versionAdvisory!, canUpdate: false },
262 }),
263 ).toBeNull();
264 for (const latestVersionStatus of ["broken", "unsupported"] as const) {
265 expect(
266 getProviderReinstallCommand({
267 ...broken,
268 compatibilityAdvisory: {
269 status: "unknown",
270 latestVersionStatus,
271 recommendedRange: null,
272 recommendedVersion: null,
273 message: null,
274 },
275 }),
276 ).toBeNull();
277 }
278});