| 1 | import { ProviderDriverKind, ProviderInstanceId, type ServerProvider } from "@t3tools/contracts"; |
| 2 | import { renderToStaticMarkup } from "react-dom/server"; |
| 3 | import { describe, expect, it } from "vite-plus/test"; |
| 4 | |
| 5 | import { |
| 6 | getProviderStatusBannerKey, |
| 7 | getProviderStatusMessage, |
| 8 | ProviderStatusBanner, |
| 9 | shouldShowProviderStatusBanner, |
| 10 | } from "./ProviderStatusBanner"; |
| 11 | |
| 12 | function warningProvider(): ServerProvider { |
| 13 | return { |
| 14 | instanceId: ProviderInstanceId.make("codex"), |
| 15 | driver: ProviderDriverKind.make("codex"), |
| 16 | displayName: "Codex", |
| 17 | enabled: true, |
| 18 | installed: true, |
| 19 | version: "1.0.0", |
| 20 | status: "warning", |
| 21 | auth: { status: "authenticated" }, |
| 22 | checkedAt: "2026-07-23T12:00:00.000Z", |
| 23 | message: "Provider is temporarily degraded.", |
| 24 | models: [], |
| 25 | slashCommands: [], |
| 26 | skills: [], |
| 27 | }; |
| 28 | } |
| 29 | |
| 30 | describe("ProviderStatusBanner", () => { |
| 31 | it("waits for an Antigravity auth result before showing a sign-in warning", () => { |
| 32 | const status: ServerProvider = { |
| 33 | ...warningProvider(), |
| 34 | instanceId: ProviderInstanceId.make("google_work"), |
| 35 | driver: ProviderDriverKind.make("antigravity"), |
| 36 | auth: { status: "unknown" }, |
| 37 | message: "Antigravity is installed. Google account access is not checked yet.", |
| 38 | }; |
| 39 | |
| 40 | expect(shouldShowProviderStatusBanner(status, null)).toBe(false); |
| 41 | expect( |
| 42 | shouldShowProviderStatusBanner( |
| 43 | { |
| 44 | ...status, |
| 45 | auth: { status: "unauthenticated" }, |
| 46 | message: "Sign in with Google to use Antigravity.", |
| 47 | }, |
| 48 | null, |
| 49 | ), |
| 50 | ).toBe(true); |
| 51 | }); |
| 52 | |
| 53 | it("shows Antigravity installation and startup failures before auth is checked", () => { |
| 54 | const status: ServerProvider = { |
| 55 | ...warningProvider(), |
| 56 | driver: ProviderDriverKind.make("antigravity"), |
| 57 | auth: { status: "unknown" }, |
| 58 | }; |
| 59 | |
| 60 | expect(shouldShowProviderStatusBanner({ ...status, installed: false }, null)).toBe(true); |
| 61 | expect(shouldShowProviderStatusBanner({ ...status, status: "error" }, null)).toBe(true); |
| 62 | expect( |
| 63 | shouldShowProviderStatusBanner({ ...status, driver: ProviderDriverKind.make("codex") }, null), |
| 64 | ).toBe(true); |
| 65 | }); |
| 66 | |
| 67 | it("stays hidden after its current warning is dismissed", () => { |
| 68 | const status = warningProvider(); |
| 69 | |
| 70 | expect(shouldShowProviderStatusBanner(status, null)).toBe(true); |
| 71 | expect(shouldShowProviderStatusBanner(status, getProviderStatusBannerKey(status))).toBe(false); |
| 72 | }); |
| 73 | |
| 74 | it("renders an accessible dismiss control for provider warnings", () => { |
| 75 | const markup = renderToStaticMarkup( |
| 76 | <ProviderStatusBanner status={warningProvider()} onDismiss={() => {}} />, |
| 77 | ); |
| 78 | |
| 79 | expect(markup).toContain('role="alert"'); |
| 80 | expect(markup).toContain('aria-label="Dismiss Codex provider warning"'); |
| 81 | }); |
| 82 | |
| 83 | it("labels error dismiss controls with the correct severity", () => { |
| 84 | const markup = renderToStaticMarkup( |
| 85 | <ProviderStatusBanner |
| 86 | status={{ ...warningProvider(), status: "error" }} |
| 87 | onDismiss={() => {}} |
| 88 | />, |
| 89 | ); |
| 90 | |
| 91 | expect(markup).toContain('aria-label="Dismiss Codex provider error"'); |
| 92 | }); |
| 93 | }); |
| 94 | |
| 95 | describe("getProviderStatusMessage", () => { |
| 96 | it("preserves the environment's authentication error", () => { |
| 97 | const message = "SUBSCRIPTION_REQUIRED: This Google account cannot use Antigravity."; |
| 98 | expect( |
| 99 | getProviderStatusMessage({ |
| 100 | ...warningProvider(), |
| 101 | driver: ProviderDriverKind.make("antigravity"), |
| 102 | status: "error", |
| 103 | auth: { status: "unauthenticated" }, |
| 104 | message, |
| 105 | }), |
| 106 | ).toBe(message); |
| 107 | }); |
| 108 | |
| 109 | it("points a signed-out Antigravity account to Google sign-in without a CLI command", () => { |
| 110 | expect( |
| 111 | getProviderStatusMessage({ |
| 112 | ...warningProvider(), |
| 113 | driver: ProviderDriverKind.make("antigravity"), |
| 114 | status: "error", |
| 115 | auth: { status: "unauthenticated" }, |
| 116 | message: "", |
| 117 | }), |
| 118 | ).toBe("Open provider setup to sign in with Google."); |
| 119 | }); |
| 120 | |
| 121 | it("requires installation on the environment before sign-in", () => { |
| 122 | expect( |
| 123 | getProviderStatusMessage({ |
| 124 | ...warningProvider(), |
| 125 | driver: ProviderDriverKind.make("antigravity"), |
| 126 | displayName: "Google work account", |
| 127 | installed: false, |
| 128 | status: "error", |
| 129 | auth: { status: "unauthenticated" }, |
| 130 | message: "", |
| 131 | }), |
| 132 | ).toBe("Open provider setup to install Antigravity on this environment."); |
| 133 | }); |
| 134 | |
| 135 | it("keeps CLI sign-in advice for a provider without integrated setup", () => { |
| 136 | expect( |
| 137 | getProviderStatusMessage({ |
| 138 | ...warningProvider(), |
| 139 | status: "error", |
| 140 | auth: { status: "unauthenticated" }, |
| 141 | message: "", |
| 142 | }), |
| 143 | ).toBe("Sign in via the CLI to authenticate again."); |
| 144 | }); |
| 145 | }); |