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

ProviderStatusBanner.test.ts

72 lines2.3 KB

1import { describe, expect, it } from "vite-plus/test";
2import { ProviderDriverKind, ProviderInstanceId, type ServerProvider } from "@t3tools/contracts";
3import {
4 getProviderStatusBannerKey,
5 getProviderStatusMessage,
6 shouldShowProviderStatusBanner,
7} from "./ProviderStatusBanner";
8​
9const provider: ServerProvider = {
10 instanceId: ProviderInstanceId.make("codex-work"),
11 driver: ProviderDriverKind.make("codex"),
12 enabled: true,
13 installed: true,
14 version: "1.0.0",
15 status: "ready",
16 auth: { status: "authenticated" },
17 checkedAt: "2026-09-22T00:00:00Z",
18 models: [],
19 skills: [],
20 slashCommands: [],
21 compatibilityAdvisory: {
22 status: "unsupported",
23 message: "Unsupported version. Use 2.0.0.",
24 recommendedVersion: "2.0.0",
25 recommendedRange: null,
26 },
27};
28​
29describe("compatibility banners", () => {
30 it("shows and dismisses a warning on a healthy provider, then clears it after policy relaxation", () => {
31 expect(shouldShowProviderStatusBanner(provider, null)).toBe(true);
32 expect(shouldShowProviderStatusBanner(provider, getProviderStatusBannerKey(provider))).toBe(
33 false,
34 );
35 expect(
36 shouldShowProviderStatusBanner(
37 { ...provider, version: "1.0.1" },
38 getProviderStatusBannerKey(provider),
39 ),
40 ).toBe(true);
41 const relaxed: ServerProvider = {
42 ...provider,
43 compatibilityAdvisory: {
44 ...provider.compatibilityAdvisory!,
45 status: "supported",
46 message: null,
47 },
48 };
49 expect(getProviderStatusBannerKey(relaxed)).toBeNull();
50 expect(getProviderStatusBannerKey({ ...provider, status: "disabled" })).toBeNull();
51 expect(
52 getProviderStatusBannerKey({
53 ...provider,
54 compatibilityAdvisory: { ...provider.compatibilityAdvisory!, status: "graceful" },
55 }),
56 ).toBeNull();
57 });
58​
59 it("keeps authentication failures ahead of compatibility warnings even without a probe message", () => {
60 const unauthenticated: ServerProvider = {
61 ...provider,
62 status: "error",
63 auth: { status: "unauthenticated" },
64 };
65 expect(getProviderStatusMessage(unauthenticated)).toBe(
66 "Sign in via the CLI to authenticate again.",
67 );
68 expect(getProviderStatusMessage({ ...unauthenticated, message: "Credentials expired" })).toBe(
69 "Credentials expired",
70 );
71 });
72});