The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | import { ProviderDriverKind, ProviderInstanceId, type ServerProvider } from "@t3tools/contracts"; |
| 3 | import { |
| 4 | dismissProviderStatusBannerForSession, |
| 5 | getProviderStatusBannerKey, |
| 6 | getProviderStatusDismissalKey, |
| 7 | getProviderStatusMessage, |
| 8 | isProviderStatusBannerDismissedForSession, |
| 9 | shouldShowProviderStatusBanner, |
| 10 | } from "./ProviderStatusBanner"; |
| 11 | |
| 12 | const provider: ServerProvider = { |
| 13 | instanceId: ProviderInstanceId.make("codex-work"), |
| 14 | driver: ProviderDriverKind.make("codex"), |
| 15 | enabled: true, |
| 16 | installed: true, |
| 17 | version: "1.0.0", |
| 18 | status: "ready", |
| 19 | auth: { status: "authenticated" }, |
| 20 | checkedAt: "2026-09-22T00:00:00Z", |
| 21 | models: [], |
| 22 | skills: [], |
| 23 | slashCommands: [], |
| 24 | compatibilityAdvisory: { |
| 25 | status: "unsupported", |
| 26 | message: "Unsupported version. Use 2.0.0.", |
| 27 | recommendedVersion: "2.0.0", |
| 28 | recommendedRange: null, |
| 29 | }, |
| 30 | }; |
| 31 | |
| 32 | function shownAfterDismissing(dismissed: ServerProvider, shown: ServerProvider): boolean { |
| 33 | return shouldShowProviderStatusBanner( |
| 34 | shown, |
| 35 | getProviderStatusBannerKey(shown) === getProviderStatusBannerKey(dismissed), |
| 36 | ); |
| 37 | } |
| 38 | |
| 39 | describe("compatibility banners", () => { |
| 40 | it("shows and dismisses a warning on a healthy provider, then clears it after policy relaxation", () => { |
| 41 | expect(shouldShowProviderStatusBanner(provider, false)).toBe(true); |
| 42 | expect(shownAfterDismissing(provider, provider)).toBe(false); |
| 43 | expect(shownAfterDismissing(provider, { ...provider, version: "1.0.1" })).toBe(true); |
| 44 | const relaxed: ServerProvider = { |
| 45 | ...provider, |
| 46 | compatibilityAdvisory: { |
| 47 | ...provider.compatibilityAdvisory!, |
| 48 | status: "supported", |
| 49 | message: null, |
| 50 | }, |
| 51 | }; |
| 52 | expect(getProviderStatusBannerKey(relaxed)).toBeNull(); |
| 53 | expect(getProviderStatusBannerKey({ ...provider, status: "disabled" })).toBeNull(); |
| 54 | expect( |
| 55 | getProviderStatusBannerKey({ |
| 56 | ...provider, |
| 57 | compatibilityAdvisory: { ...provider.compatibilityAdvisory!, status: "graceful" }, |
| 58 | }), |
| 59 | ).toBeNull(); |
| 60 | }); |
| 61 | |
| 62 | it("shows downgrade guidance instead of a broken OpenCode inventory timeout", () => { |
| 63 | const message = "This provider version is known to be incompatible. Use 1.14.19."; |
| 64 | const broken: ServerProvider = { |
| 65 | ...provider, |
| 66 | driver: ProviderDriverKind.make("opencode"), |
| 67 | version: "2.0.3", |
| 68 | status: "error", |
| 69 | auth: { status: "unknown" }, |
| 70 | message: "Failed to load OpenCode provider inventory: Timed out waiting for server start.", |
| 71 | compatibilityAdvisory: { |
| 72 | status: "broken", |
| 73 | message, |
| 74 | recommendedVersion: "1.14.19", |
| 75 | recommendedRange: ">=1.14.19 <2.0.0", |
| 76 | }, |
| 77 | }; |
| 78 | expect(shouldShowProviderStatusBanner(broken, false)).toBe(true); |
| 79 | const timeoutOnly: ServerProvider = { |
| 80 | ...broken, |
| 81 | compatibilityAdvisory: { |
| 82 | ...broken.compatibilityAdvisory!, |
| 83 | status: "supported", |
| 84 | message: null, |
| 85 | }, |
| 86 | }; |
| 87 | expect(shownAfterDismissing(timeoutOnly, broken)).toBe(true); |
| 88 | expect(shownAfterDismissing(broken, broken)).toBe(false); |
| 89 | expect( |
| 90 | shownAfterDismissing(broken, { |
| 91 | ...broken, |
| 92 | compatibilityAdvisory: { ...broken.compatibilityAdvisory!, message: "Use 1.14.20." }, |
| 93 | }), |
| 94 | ).toBe(true); |
| 95 | expect(getProviderStatusMessage(broken)).toBe(message); |
| 96 | expect( |
| 97 | getProviderStatusMessage({ |
| 98 | ...broken, |
| 99 | compatibilityAdvisory: { |
| 100 | ...broken.compatibilityAdvisory!, |
| 101 | status: "supported", |
| 102 | message: null, |
| 103 | }, |
| 104 | }), |
| 105 | ).toBe(broken.message); |
| 106 | expect(getProviderStatusMessage({ ...broken, auth: { status: "unauthenticated" } })).toBe( |
| 107 | broken.message, |
| 108 | ); |
| 109 | }); |
| 110 | }); |
| 111 | |
| 112 | describe("banner dismissal", () => { |
| 113 | const { compatibilityAdvisory: _advisory, ...healthy } = provider; |
| 114 | const failing: ServerProvider = { |
| 115 | ...healthy, |
| 116 | instanceId: ProviderInstanceId.make("codex-dismissal"), |
| 117 | status: "error", |
| 118 | message: "Could not start Codex CLI.", |
| 119 | }; |
| 120 | |
| 121 | it("keeps a dismissed status hidden in other views until the status changes", () => { |
| 122 | const key = getProviderStatusDismissalKey("environment-a", failing); |
| 123 | expect(isProviderStatusBannerDismissedForSession(key)).toBe(false); |
| 124 | |
| 125 | dismissProviderStatusBannerForSession(key); |
| 126 | |
| 127 | expect( |
| 128 | isProviderStatusBannerDismissedForSession( |
| 129 | getProviderStatusDismissalKey("environment-a", failing), |
| 130 | ), |
| 131 | ).toBe(true); |
| 132 | expect( |
| 133 | isProviderStatusBannerDismissedForSession( |
| 134 | getProviderStatusDismissalKey("environment-a", { ...failing, message: "Codex exited." }), |
| 135 | ), |
| 136 | ).toBe(false); |
| 137 | }); |
| 138 | |
| 139 | it("keeps a dismissal to the environment it was taken in", () => { |
| 140 | dismissProviderStatusBannerForSession(getProviderStatusDismissalKey("environment-c", failing)); |
| 141 | |
| 142 | expect( |
| 143 | isProviderStatusBannerDismissedForSession( |
| 144 | getProviderStatusDismissalKey("environment-d", failing), |
| 145 | ), |
| 146 | ).toBe(false); |
| 147 | }); |
| 148 | }); |