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

providerStatus.test.ts

275 lines8.3 KB

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