Open History to see the last commit
1import { ProviderDriverKind, ProviderInstanceId, type ServerProvider } from "@t3tools/contracts";
2import { describe, expect, it } from "vite-plus/test";
3
4import { getProviderSummary, getProviderVersionAdvisoryPresentation } from "./providerStatus";
5
6const provider: ServerProvider = {
7 instanceId: ProviderInstanceId.make("codex"),
8 driver: ProviderDriverKind.make("codex"),
9 enabled: true,
10 installed: true,
11 version: "1.0.0",
12 status: "ready",
13 auth: { status: "authenticated", label: "ChatGPT" },
14 checkedAt: "2026-08-23T00:00:00.000Z",
15 models: [],
16 slashCommands: [],
17 skills: [],
18};
19
20describe("getProviderSummary", () => {
21 it("reports ready providers with unknown authentication as available", () => {
22 expect(getProviderSummary({ ...provider, auth: { status: "unknown" } })).toEqual({
23 headline: "Available",
24 detail: null,
25 });
26 });
27
28 it("does not hide a provider error behind a previous authenticated state", () => {
29 expect(
30 getProviderSummary({
31 ...provider,
32 status: "error",
33 message: "The provider process failed to start.",
34 }),
35 ).toEqual({
36 headline: "Unavailable",
37 detail: "The provider process failed to start.",
38 });
39 });
40
41 it("does not hide a provider warning behind an authenticated state", () => {
42 expect(
43 getProviderSummary({
44 ...provider,
45 status: "warning",
46 message: "The provider version is unsupported.",
47 }),
48 ).toEqual({
49 headline: "Needs attention",
50 detail: "The provider version is unsupported.",
51 });
52 });
53
54 it("keeps authentication failures actionable when their provider status is error", () => {
55 expect(
56 getProviderSummary({
57 ...provider,
58 status: "error",
59 auth: { status: "unauthenticated" },
60 message: "Run codex login.",
61 }),
62 ).toEqual({
63 headline: "Not authenticated",
64 detail: "Run codex login.",
65 });
66 });
67
68 it("treats a disabled provider status as disabled even before its enabled flag updates", () => {
69 expect(getProviderSummary({ ...provider, status: "disabled" }).headline).toBe("Disabled");
70 });
71});
72
73it("does not suggest copying a command that installs an incompatible latest version", () => {
74 const advisory = {
75 status: "behind_latest" as const,
76 currentVersion: "1.0.0",
77 latestVersion: "2.0.0",
78 updateCommand: "npm install -g fixture@latest",
79 canUpdate: true,
80 checkedAt: provider.checkedAt,
81 message: null,
82 };
83 const compatibility = {
84 status: "supported" as const,
85 latestVersionStatus: "broken" as const,
86 message: null,
87 recommendedRange: null,
88 recommendedVersion: null,
89 };
90 expect(getProviderVersionAdvisoryPresentation(advisory, compatibility)).toBeNull();
91 expect(
92 getProviderVersionAdvisoryPresentation(advisory, { ...compatibility, status: "broken" }, false),
93 ).toBeNull();
94 expect(
95 getProviderVersionAdvisoryPresentation(advisory, {
96 ...compatibility,
97 latestVersionStatus: "supported",
98 }),
99 ).not.toBeNull();
100});
101
102it("does not offer an update that cannot change a limited-support version", () => {
103 // OpenCode 1.18.35 is the newest `opencode-ai`; the recommended 2.x ships as another package.
104 const advisory = {
105 status: "current" as const,
106 currentVersion: "1.18.35",
107 latestVersion: "1.18.35",
108 updateCommand: "npm install -g opencode-ai@latest",
109 canUpdate: true,
110 checkedAt: provider.checkedAt,
111 message: null,
112 };
113 const compatibility = {
114 status: "graceful" as const,
115 latestVersionStatus: "graceful" as const,
116 message: null,
117 recommendedRange: ">=2.0.18",
118 recommendedVersion: null,
119 };
120 expect(getProviderVersionAdvisoryPresentation(advisory, compatibility)).toEqual({
121 title: "Limited support",
122 detail: "Use >=2.0.18 for full support.",
123 updateCommand: null,
124 emphasis: "normal",
125 targetVersion: null,
126 });
127 expect(
128 getProviderVersionAdvisoryPresentation(
129 { ...advisory, status: "behind_latest", currentVersion: "1.18.34" },
130 compatibility,
131 )?.updateCommand,
132 ).toBe(advisory.updateCommand);
133});
134
135it("shows compatibility in the version popover even when the installed version is current", () => {
136 const advisory = {
137 status: "current" as const,
138 currentVersion: "2.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: "broken" as const,
147 latestVersionStatus: "broken" as const,
148 message: "This version drops turns. Use 1.9.0.",
149 recommendedRange: null,
150 recommendedVersion: "1.9.0",
151 };
152 expect(getProviderVersionAdvisoryPresentation(advisory, compatibility)).toEqual({
153 title: "Known broken version",
154 detail: compatibility.message,
155 updateCommand: null,
156 emphasis: "strong",
157 targetVersion: "1.9.0",
158 });
159 expect(
160 getProviderVersionAdvisoryPresentation(undefined, {
161 ...compatibility,
162 status: "graceful",
163 recommendedVersion: null,
164 recommendedRange: ">=2.1.0",
165 message: null,
166 }),
167 ).toEqual({
168 title: "Limited support",
169 detail: "Use >=2.1.0 for full support.",
170 updateCommand: null,
171 emphasis: "normal",
172 targetVersion: null,
173 });
174});
175
176describe("provider status copy", () => {
177 it("surfaces an ACP-advertised authentication method", () => {
178 const provider = {
179 enabled: true,
180 installed: true,
181 status: "error",
182 auth: { status: "unauthenticated", type: "agent", label: "Company login" },
183 message: "Complete this authentication method on the server.",
184 } as ServerProvider;
185
186 expect(getProviderSummary(provider)).toEqual({
187 headline: "Not authenticated · Company login",
188 detail: "Complete this authentication method on the server.",
189 });
190 });
191});