Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2import {
3 EnvironmentId,
4 ProviderDriverKind,
5 ProviderInstanceId,
6 type ServerProvider,
7} from "@t3tools/contracts";
8import * as Cause from "effect/Cause";
9import { AsyncResult } from "effect/reactivity";
10
11import {
12 canOneClickUpdateProviderCandidate,
13 getProviderUpdateRunToastView,
14 getProviderUpdateSidebarPillView,
15 hasOneClickUpdateProviderCandidate,
16 isProviderUpdateCandidate,
17 isProviderSettingsUpdateCandidate,
18 type ProviderUpdateCandidate,
19} from "./ProviderUpdateLaunchNotification.logic";
20
21const checkedAt = "2026-04-23T10:00:00.000Z";
22const sessionStartedAt = "2026-04-23T09:59:00.000Z";
23const laterCheckedAt = "2026-04-23T10:01:00.000Z";
24
25const driver = (value: string) => ProviderDriverKind.make(value);
26const instanceId = (value: string) => ProviderInstanceId.make(value);
27
28function provider(input: {
29 readonly driver: ReturnType<typeof ProviderDriverKind.make>;
30 readonly instanceId?: ReturnType<typeof ProviderInstanceId.make>;
31 readonly enabled?: boolean;
32 readonly version?: string | null;
33 readonly latestVersion?: string | null;
34 readonly canUpdate?: boolean;
35 readonly updateCommand?: string | null;
36 readonly updateState?: ServerProvider["updateState"];
37 readonly advisoryStatus?: NonNullable<ServerProvider["versionAdvisory"]>["status"];
38}): ServerProvider {
39 const result: ServerProvider = {
40 instanceId: input.instanceId ?? instanceId(String(input.driver)),
41 driver: input.driver,
42 enabled: input.enabled ?? true,
43 installed: true,
44 version: input.version ?? "1.0.0",
45 status: "ready",
46 auth: { status: "authenticated" },
47 checkedAt,
48 models: [],
49 slashCommands: [],
50 skills: [],
51 versionAdvisory: {
52 status: input.advisoryStatus ?? "behind_latest",
53 currentVersion: input.version ?? "1.0.0",
54 latestVersion: "latestVersion" in input ? input.latestVersion : "1.1.0",
55 updateCommand: "updateCommand" in input ? input.updateCommand : "npm install -g provider",
56 canUpdate: input.canUpdate ?? true,
57 checkedAt,
58 message: "Update available.",
59 },
60 };
61
62 if (input.updateState) {
63 return { ...result, updateState: input.updateState };
64 }
65
66 return result;
67}
68
69function updateCandidate(input: Parameters<typeof provider>[0]): ProviderUpdateCandidate {
70 return provider(input) as ProviderUpdateCandidate;
71}
72
73describe("provider update launch notification logic", () => {
74 it("disables one-click updates when provider instances disagree on the update command", () => {
75 const candidate = updateCandidate({
76 driver: driver("claudeAgent"),
77 instanceId: instanceId("claude_personal"),
78 latestVersion: "2.1.123",
79 });
80
81 expect(
82 canOneClickUpdateProviderCandidate(candidate, [
83 candidate,
84 provider({
85 driver: driver("claudeAgent"),
86 instanceId: instanceId("claude_work"),
87 latestVersion: "2.1.123",
88 canUpdate: true,
89 updateCommand: "bun add -g @anthropic-ai/claude-code@latest",
90 }),
91 ]),
92 ).toBe(false);
93 });
94
95 it("keeps one-click updates enabled when sibling instances are already current", () => {
96 const candidate = updateCandidate({
97 driver: driver("claudeAgent"),
98 instanceId: instanceId("claude_personal"),
99 latestVersion: "2.1.123",
100 updateCommand: "npm install -g @anthropic-ai/claude-code@latest",
101 });
102
103 expect(
104 hasOneClickUpdateProviderCandidate(candidate, [
105 candidate,
106 provider({
107 driver: driver("claudeAgent"),
108 instanceId: instanceId("claude_work"),
109 version: "2.1.123",
110 latestVersion: "2.1.123",
111 advisoryStatus: "current",
112 canUpdate: false,
113 updateCommand: null,
114 }),
115 ]),
116 ).toBe(true);
117 expect(
118 canOneClickUpdateProviderCandidate(candidate, [
119 candidate,
120 provider({
121 driver: driver("claudeAgent"),
122 instanceId: instanceId("claude_work"),
123 version: "2.1.123",
124 latestVersion: "2.1.123",
125 advisoryStatus: "current",
126 canUpdate: false,
127 updateCommand: null,
128 }),
129 ]),
130 ).toBe(true);
131 });
132
133 it("offers one-click updates for a managed runtime that has no update command", () => {
134 const candidate = updateCandidate({
135 driver: driver("antigravity"),
136 latestVersion: "1.5.18",
137 updateCommand: null,
138 });
139 const manual = updateCandidate({
140 driver: driver("antigravity"),
141 latestVersion: "1.5.18",
142 canUpdate: false,
143 updateCommand: null,
144 });
145
146 expect(canOneClickUpdateProviderCandidate(candidate, [candidate])).toBe(true);
147 expect(canOneClickUpdateProviderCandidate(manual, [manual])).toBe(false);
148 expect(isProviderSettingsUpdateCandidate(candidate)).toBe(true);
149 expect(isProviderSettingsUpdateCandidate(manual)).toBe(false);
150 });
151
152 it("keeps the inline update action available while a provider update is already running", () => {
153 const candidate = updateCandidate({
154 driver: driver("codex"),
155 updateState: {
156 status: "running",
157 startedAt: checkedAt,
158 finishedAt: null,
159 message: "Updating provider.",
160 output: null,
161 },
162 });
163
164 expect(hasOneClickUpdateProviderCandidate(candidate, [candidate])).toBe(true);
165 expect(canOneClickUpdateProviderCandidate(candidate, [candidate])).toBe(false);
166 });
167
168 it("shows the active sidebar pill for an update on a non-default instance", () => {
169 const view = getProviderUpdateSidebarPillView([
170 provider({ driver: driver("claudeAgent") }),
171 provider({
172 driver: driver("claudeAgent"),
173 instanceId: instanceId("claude_work"),
174 updateState: {
175 status: "running",
176 startedAt: checkedAt,
177 finishedAt: null,
178 message: "Updating provider.",
179 output: null,
180 },
181 }),
182 ]);
183
184 expect(view).toMatchObject({
185 key: "loading:claudeAgent:running",
186 tone: "loading",
187 title: "Updating Claude",
188 description: "Claude update in progress.",
189 });
190 });
191
192 it("shows the latest terminal sidebar pill across instances of a driver", () => {
193 const view = getProviderUpdateSidebarPillView(
194 [
195 provider({
196 driver: driver("claudeAgent"),
197 updateState: {
198 status: "failed",
199 startedAt: checkedAt,
200 finishedAt: checkedAt,
201 message: "Update command exited with code 1.",
202 output: null,
203 },
204 }),
205 provider({
206 driver: driver("claudeAgent"),
207 instanceId: instanceId("claude_work"),
208 version: "1.1.0",
209 latestVersion: "1.1.0",
210 advisoryStatus: "current",
211 updateState: {
212 status: "succeeded",
213 startedAt: laterCheckedAt,
214 finishedAt: laterCheckedAt,
215 message: "Provider updated.",
216 output: null,
217 },
218 }),
219 ],
220 { visibleAfterIso: sessionStartedAt },
221 );
222
223 expect(view).toMatchObject({
224 key: "succeeded:claudeAgent:2026-04-23T10:01:00.000Z:Provider updated.",
225 tone: "success",
226 title: "Claude updated: v1.1.0",
227 });
228 });
229
230 it("does not show sidebar terminal states from before the current app session", () => {
231 expect(
232 getProviderUpdateSidebarPillView(
233 [
234 provider({
235 driver: driver("codex"),
236 updateState: {
237 status: "failed",
238 startedAt: checkedAt,
239 finishedAt: checkedAt,
240 message: "command failed",
241 output: "stderr",
242 },
243 }),
244 ],
245 { visibleAfterIso: "2026-04-23T10:00:01.000Z" },
246 ),
247 ).toBeNull();
248 });
249
250 it("shows a newer success before falling back to an older failure", () => {
251 const providers = [
252 provider({
253 driver: driver("claudeAgent"),
254 updateState: {
255 status: "failed",
256 startedAt: checkedAt,
257 finishedAt: checkedAt,
258 message: "Update command exited with code 1.",
259 output: null,
260 },
261 }),
262 provider({
263 driver: driver("codex"),
264 version: "1.2.0",
265 latestVersion: "1.2.0",
266 advisoryStatus: "current",
267 updateState: {
268 status: "succeeded",
269 startedAt: laterCheckedAt,
270 finishedAt: laterCheckedAt,
271 message: "Provider updated.",
272 output: null,
273 },
274 }),
275 ] satisfies ReadonlyArray<ServerProvider>;
276
277 const successView = getProviderUpdateSidebarPillView(providers, {
278 visibleAfterIso: sessionStartedAt,
279 });
280 expect(successView).toMatchObject({
281 key: "succeeded:codex:2026-04-23T10:01:00.000Z:Provider updated.",
282 tone: "success",
283 title: "Codex updated: v1.2.0",
284 });
285
286 const failureView = getProviderUpdateSidebarPillView(providers, {
287 visibleAfterIso: sessionStartedAt,
288 dismissedKeys: new Set(["succeeded:codex:2026-04-23T10:01:00.000Z:Provider updated."]),
289 });
290 expect(failureView).toMatchObject({
291 key: "failed:claudeAgent:2026-04-23T10:00:00.000Z:Update command exited with code 1.",
292 tone: "error",
293 title: "Claude v1.1.0 update failed",
294 });
295 });
296
297 it("does not count an already dismissed success again when another provider updates", () => {
298 const claudeUpdated = provider({
299 driver: driver("claudeAgent"),
300 version: "1.1.0",
301 latestVersion: "1.1.0",
302 advisoryStatus: "current",
303 updateState: {
304 status: "succeeded",
305 startedAt: checkedAt,
306 finishedAt: checkedAt,
307 message: "Provider updated.",
308 output: null,
309 },
310 });
311 const claudeView = getProviderUpdateSidebarPillView([claudeUpdated], {
312 visibleAfterIso: sessionStartedAt,
313 });
314 expect(claudeView).toMatchObject({ title: "Claude updated: v1.1.0" });
315
316 const bothUpdated = [
317 claudeUpdated,
318 provider({
319 driver: driver("codex"),
320 version: "1.2.0",
321 latestVersion: "1.2.0",
322 advisoryStatus: "current",
323 updateState: {
324 status: "succeeded",
325 startedAt: laterCheckedAt,
326 finishedAt: laterCheckedAt,
327 message: "Provider updated.",
328 output: null,
329 },
330 }),
331 ];
332 const codexView = getProviderUpdateSidebarPillView(bothUpdated, {
333 visibleAfterIso: sessionStartedAt,
334 dismissedKeys: new Set(claudeView?.dismissKeys),
335 });
336 expect(codexView).toMatchObject({ tone: "success", title: "Codex updated: v1.2.0" });
337
338 const groupedView = getProviderUpdateSidebarPillView(bothUpdated, {
339 visibleAfterIso: sessionStartedAt,
340 });
341 expect(groupedView).toMatchObject({ title: "2 providers updated" });
342 expect(
343 getProviderUpdateSidebarPillView(bothUpdated, {
344 visibleAfterIso: sessionStartedAt,
345 dismissedKeys: new Set(groupedView?.dismissKeys),
346 }),
347 ).toBeNull();
348 });
349});
350
351it("does not offer incompatible latest versions and restores suggestions after policy relaxation", () => {
352 const installed = provider({ driver: driver("codex") });
353 for (const latestVersionStatus of ["broken", "unsupported", "supported", "unknown"] as const) {
354 const snapshot: ServerProvider = {
355 ...installed,
356 compatibilityAdvisory: {
357 status: "supported",
358 latestVersionStatus,
359 message: null,
360 recommendedRange: null,
361 recommendedVersion: null,
362 },
363 };
364 const expected = latestVersionStatus === "supported" || latestVersionStatus === "unknown";
365 expect(isProviderUpdateCandidate(snapshot)).toBe(expected);
366 expect(isProviderSettingsUpdateCandidate(snapshot)).toBe(expected);
367 }
368});
369
370describe("getProviderUpdateRunToastView", () => {
371 const updateState = (
372 status: "succeeded" | "failed",
373 message: string,
374 ): ServerProvider["updateState"] => ({
375 status,
376 startedAt: checkedAt,
377 finishedAt: laterCheckedAt,
378 message,
379 output: null,
380 });
381 const run = (
382 machineLabel: string,
383 providerDriver: string,
384 result: Parameters<typeof getProviderUpdateRunToastView>[0][number]["result"],
385 ) => ({
386 environmentId: EnvironmentId.make(machineLabel),
387 machineLabel,
388 driver: driver(providerDriver),
389 instanceId: instanceId(providerDriver),
390 result,
391 });
392
393 it("preserves the local server restart instruction after a successful update", () => {
394 const message =
395 "OpenCode CLI updated. Restart the configured local OpenCode server to use the new version.";
396 const updated = {
397 ...provider({
398 driver: driver("opencode"),
399 version: "2.1.2",
400 advisoryStatus: "current",
401 updateState: updateState("succeeded", message),
402 }),
403 installedVersion: "2.2.5",
404 };
405 expect(
406 getProviderUpdateRunToastView([
407 run("Linux", "opencode", AsyncResult.success({ providers: [updated] })),
408 run("Laptop", "opencode", AsyncResult.success({ providers: [updated] })),
409 ]),
410 ).toMatchObject({
411 type: "success",
412 description: `Linux · OpenCode: ${message}\nLaptop · OpenCode: ${message}`,
413 });
414 expect(
415 getProviderUpdateSidebarPillView([updated], {
416 visibleAfterIso: sessionStartedAt,
417 }),
418 ).toMatchObject({ title: "OpenCode updated: v2.2.5", description: message });
419
420 const restarted = { ...updated, version: "2.2.5" };
421 expect(
422 getProviderUpdateRunToastView([
423 run("Linux", "opencode", AsyncResult.success({ providers: [restarted] })),
424 ]),
425 ).toMatchObject({ description: "New sessions will use the updated provider." });
426 });
427
428 it("lists every failed update and ignores interrupted ones", () => {
429 const view = getProviderUpdateRunToastView([
430 run(
431 "Mac Studio",
432 "codex",
433 AsyncResult.success({
434 providers: [
435 provider({
436 driver: driver("codex"),
437 updateState: updateState("succeeded", "Provider updated."),
438 }),
439 ],
440 }),
441 ),
442 run(
443 "Mac Studio",
444 "claudeAgent",
445 AsyncResult.success({
446 providers: [
447 provider({
448 driver: driver("claudeAgent"),
449 updateState: updateState("failed", "npm exited with code 1."),
450 }),
451 ],
452 }),
453 ),
454 run("Laptop", "codex", AsyncResult.failure(Cause.die(new Error("WebSocket closed")))),
455 run("Server", "codex", AsyncResult.failure(Cause.interrupt())),
456 ]);
457
458 expect(view).toEqual({
459 type: "error",
460 title: "2 of 3 provider updates failed",
461 description: "Mac Studio · Claude: npm exited with code 1.\nLaptop · Codex: WebSocket closed",
462 });
463 });
464});