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 { ProviderDriverKind, ProviderInstanceId, type ServerProvider } from "@t3tools/contracts"; |
| 2 | import { describe, expect, it } from "vite-plus/test"; |
| 3 | |
| 4 | import { |
| 5 | getProviderSummary, |
| 6 | getProviderVersionAdvisoryPresentation, |
| 7 | getProviderStatusKey, |
| 8 | } from "./providerStatus"; |
| 9 | |
| 10 | const provider: ServerProvider = { |
| 11 | instanceId: ProviderInstanceId.make("codex"), |
| 12 | driver: ProviderDriverKind.make("codex"), |
| 13 | enabled: true, |
| 14 | installed: true, |
| 15 | version: "1.0.0", |
| 16 | status: "ready", |
| 17 | auth: { status: "authenticated", label: "ChatGPT" }, |
| 18 | checkedAt: "2026-08-23T00:00:00.000Z", |
| 19 | models: [], |
| 20 | slashCommands: [], |
| 21 | skills: [], |
| 22 | }; |
| 23 | |
| 24 | describe("getProviderSummary", () => { |
| 25 | it("does not hide a provider error behind a previous authenticated state", () => { |
| 26 | expect( |
| 27 | getProviderSummary({ |
| 28 | ...provider, |
| 29 | status: "error", |
| 30 | message: "The provider process failed to start.", |
| 31 | }), |
| 32 | ).toEqual({ |
| 33 | headline: "Unavailable", |
| 34 | detail: "The provider process failed to start.", |
| 35 | }); |
| 36 | }); |
| 37 | |
| 38 | it("keeps authentication failures actionable when their provider status is error", () => { |
| 39 | expect( |
| 40 | getProviderSummary({ |
| 41 | ...provider, |
| 42 | status: "error", |
| 43 | auth: { status: "unauthenticated" }, |
| 44 | message: "Run codex login.", |
| 45 | }), |
| 46 | ).toEqual({ |
| 47 | headline: "Not authenticated", |
| 48 | detail: "Run codex login.", |
| 49 | }); |
| 50 | }); |
| 51 | }); |
| 52 | |
| 53 | describe("Antigravity with unchecked sign-in", () => { |
| 54 | const unchecked: ServerProvider = { |
| 55 | ...provider, |
| 56 | instanceId: ProviderInstanceId.make("antigravity"), |
| 57 | driver: ProviderDriverKind.make("antigravity"), |
| 58 | status: "warning", |
| 59 | auth: { status: "unknown" }, |
| 60 | message: "Antigravity is installed. Google account access is not checked yet.", |
| 61 | }; |
| 62 | |
| 63 | it("presents an unchecked Google sign-in neutrally without claiming authentication is required", () => { |
| 64 | for (const auth of [unchecked.auth, { status: "unknown", type: "oauth-personal" }] as const) { |
| 65 | const candidate = { ...unchecked, auth }; |
| 66 | expect.soft(getProviderSummary(candidate)).toEqual({ |
| 67 | headline: "Installed · Sign-in not checked", |
| 68 | detail: unchecked.message, |
| 69 | }); |
| 70 | expect(getProviderStatusKey(candidate)).toBe("neutral"); |
| 71 | } |
| 72 | }); |
| 73 | |
| 74 | // regression: #18623 neutral unchecked-sign-in display must not mask real warnings |
| 75 | it("preserves actionable warnings, failures and disabled states outside unchecked Google sign-in", () => { |
| 76 | const cases = [ |
| 77 | { |
| 78 | name: "confirmed sign-out", |
| 79 | change: { auth: { status: "unauthenticated" } }, |
| 80 | headline: "Not authenticated", |
| 81 | status: "warning", |
| 82 | }, |
| 83 | { |
| 84 | name: "warning despite known authentication", |
| 85 | change: { auth: { status: "authenticated" } }, |
| 86 | headline: "Needs attention", |
| 87 | status: "warning", |
| 88 | }, |
| 89 | { |
| 90 | name: "probe failure", |
| 91 | change: { status: "error" }, |
| 92 | headline: "Unavailable", |
| 93 | status: "error", |
| 94 | }, |
| 95 | { |
| 96 | name: "missing CLI", |
| 97 | change: { installed: false }, |
| 98 | headline: "Not found", |
| 99 | status: "warning", |
| 100 | }, |
| 101 | { |
| 102 | name: "API key authentication", |
| 103 | change: { auth: { status: "unknown", type: "gemini-api-key" } }, |
| 104 | headline: "Needs attention", |
| 105 | status: "warning", |
| 106 | }, |
| 107 | { |
| 108 | name: "Agent Platform authentication", |
| 109 | change: { auth: { status: "unknown", type: "agent-platform" } }, |
| 110 | headline: "Needs attention", |
| 111 | status: "warning", |
| 112 | }, |
| 113 | { |
| 114 | name: "another provider", |
| 115 | change: { driver: provider.driver }, |
| 116 | headline: "Needs attention", |
| 117 | status: "warning", |
| 118 | }, |
| 119 | { |
| 120 | name: "disabled provider", |
| 121 | change: { enabled: false }, |
| 122 | headline: "Disabled", |
| 123 | status: "disabled", |
| 124 | }, |
| 125 | ] as const; |
| 126 | for (const { name, change, headline, status } of cases) { |
| 127 | const candidate = { ...unchecked, ...change }; |
| 128 | expect.soft(getProviderSummary(candidate).headline, name).toBe(headline); |
| 129 | expect.soft(getProviderStatusKey(candidate), name).toBe(status); |
| 130 | } |
| 131 | }); |
| 132 | }); |
| 133 | |
| 134 | it("does not suggest copying a command that installs an incompatible latest version", () => { |
| 135 | const advisory = { |
| 136 | status: "behind_latest" as const, |
| 137 | currentVersion: "1.0.0", |
| 138 | latestVersion: "2.0.0", |
| 139 | updateCommand: "npm install -g fixture@latest", |
| 140 | canUpdate: true, |
| 141 | checkedAt: provider.checkedAt, |
| 142 | message: null, |
| 143 | }; |
| 144 | const compatibility = { |
| 145 | status: "supported" as const, |
| 146 | latestVersionStatus: "broken" as const, |
| 147 | message: null, |
| 148 | recommendedRange: null, |
| 149 | recommendedVersion: null, |
| 150 | }; |
| 151 | expect(getProviderVersionAdvisoryPresentation(advisory, compatibility)).toBeNull(); |
| 152 | expect( |
| 153 | getProviderVersionAdvisoryPresentation(advisory, { ...compatibility, status: "broken" }, false), |
| 154 | ).toBeNull(); |
| 155 | expect( |
| 156 | getProviderVersionAdvisoryPresentation(advisory, { |
| 157 | ...compatibility, |
| 158 | latestVersionStatus: "supported", |
| 159 | }), |
| 160 | ).not.toBeNull(); |
| 161 | }); |
| 162 | |
| 163 | it("does not offer an update that cannot change a limited-support version", () => { |
| 164 | // OpenCode 1.18.35 is the newest `opencode-ai`; the recommended 2.x ships as another package. |
| 165 | const advisory = { |
| 166 | status: "current" as const, |
| 167 | currentVersion: "1.18.35", |
| 168 | latestVersion: "1.18.35", |
| 169 | updateCommand: "npm install -g opencode-ai@latest", |
| 170 | canUpdate: true, |
| 171 | checkedAt: provider.checkedAt, |
| 172 | message: null, |
| 173 | }; |
| 174 | const compatibility = { |
| 175 | status: "graceful" as const, |
| 176 | latestVersionStatus: "graceful" as const, |
| 177 | message: null, |
| 178 | recommendedRange: ">=2.0.18", |
| 179 | recommendedVersion: null, |
| 180 | }; |
| 181 | expect(getProviderVersionAdvisoryPresentation(advisory, compatibility)).toEqual({ |
| 182 | title: "Limited support", |
| 183 | detail: "Use >=2.0.18 for full support.", |
| 184 | updateCommand: null, |
| 185 | emphasis: "normal", |
| 186 | targetVersion: null, |
| 187 | }); |
| 188 | expect( |
| 189 | getProviderVersionAdvisoryPresentation( |
| 190 | { ...advisory, status: "behind_latest", currentVersion: "1.18.34" }, |
| 191 | compatibility, |
| 192 | )?.updateCommand, |
| 193 | ).toBe(advisory.updateCommand); |
| 194 | }); |
| 195 | |
| 196 | it("shows compatibility in the version popover even when the installed version is current", () => { |
| 197 | const advisory = { |
| 198 | status: "current" as const, |
| 199 | currentVersion: "2.0.0", |
| 200 | latestVersion: "2.0.0", |
| 201 | updateCommand: "npm install -g fixture@latest", |
| 202 | canUpdate: true, |
| 203 | checkedAt: provider.checkedAt, |
| 204 | message: null, |
| 205 | }; |
| 206 | const compatibility = { |
| 207 | status: "broken" as const, |
| 208 | latestVersionStatus: "broken" as const, |
| 209 | message: "This version drops turns. Use 1.9.0.", |
| 210 | recommendedRange: null, |
| 211 | recommendedVersion: "1.9.0", |
| 212 | }; |
| 213 | expect(getProviderVersionAdvisoryPresentation(advisory, compatibility)).toEqual({ |
| 214 | title: "Known broken version", |
| 215 | detail: compatibility.message, |
| 216 | updateCommand: null, |
| 217 | emphasis: "strong", |
| 218 | targetVersion: "1.9.0", |
| 219 | }); |
| 220 | expect( |
| 221 | getProviderVersionAdvisoryPresentation(undefined, { |
| 222 | ...compatibility, |
| 223 | status: "graceful", |
| 224 | recommendedVersion: null, |
| 225 | recommendedRange: ">=2.1.0", |
| 226 | message: null, |
| 227 | }), |
| 228 | ).toEqual({ |
| 229 | title: "Limited support", |
| 230 | detail: "Use >=2.1.0 for full support.", |
| 231 | updateCommand: null, |
| 232 | emphasis: "normal", |
| 233 | targetVersion: null, |
| 234 | }); |
| 235 | }); |