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 } from "@t3tools/contracts"; |
| 2 | import { describe, expect, it } from "vite-plus/test"; |
| 3 | |
| 4 | import { |
| 5 | normalizeProviderAccentColor, |
| 6 | providerAccentForegroundColor, |
| 7 | providerInstanceInitials, |
| 8 | shouldShowInstanceBadge, |
| 9 | } from "./providerInstanceDisplay.ts"; |
| 10 | |
| 11 | const codex = ProviderDriverKind.make("codex"); |
| 12 | const acpRegistry = ProviderDriverKind.make("acpRegistry"); |
| 13 | |
| 14 | describe("providerInstanceInitials", () => { |
| 15 | it("treats punctuation and camel-case humps as word breaks but keeps apostrophes between letters", () => { |
| 16 | expect(providerInstanceInitials("Codex (hub)")).toBe("CH"); |
| 17 | expect(providerInstanceInitials("work_codex")).toBe("WC"); |
| 18 | expect(providerInstanceInitials("Theo's Codex")).toBe("TC"); |
| 19 | expect(providerInstanceInitials("Codex 'hub'")).toBe("CH"); |
| 20 | expect(providerInstanceInitials("‘hub’")).toBe("HU"); |
| 21 | expect(providerInstanceInitials("(hub)")).toBe("HU"); |
| 22 | expect(providerInstanceInitials("ClaudeProx")).toBe("CP"); |
| 23 | expect(providerInstanceInitials("ClaudeAPI")).toBe("CA"); |
| 24 | expect(providerInstanceInitials("API")).toBe("AP"); |
| 25 | expect(providerInstanceInitials("ClaudeProx Work")).toBe("CW"); |
| 26 | expect(providerInstanceInitials("(ClaudeProx)")).toBe("CP"); |
| 27 | }); |
| 28 | |
| 29 | it("keeps an emoji whole instead of splitting its surrogate pair", () => { |
| 30 | expect(providerInstanceInitials("😀 Work")).toBe("😀W"); |
| 31 | expect(providerInstanceInitials("😀")).toBe("😀"); |
| 32 | }); |
| 33 | }); |
| 34 | |
| 35 | describe("normalizeProviderAccentColor", () => { |
| 36 | // regression: #9899 a non-hex accent must not render as the account badge color |
| 37 | it("rejects a non-hex value", () => { |
| 38 | expect(normalizeProviderAccentColor("blue")).toBeUndefined(); |
| 39 | }); |
| 40 | }); |
| 41 | |
| 42 | describe("providerAccentForegroundColor", () => { |
| 43 | it.each([ |
| 44 | ["#b5f23d", "#000000"], |
| 45 | ["#2563eb", "#ffffff"], |
| 46 | ["#777777", "#000000"], |
| 47 | ])("chooses the higher WCAG contrast foreground for %s", (accent, foreground) => { |
| 48 | expect(providerAccentForegroundColor(accent)).toBe(foreground); |
| 49 | }); |
| 50 | }); |
| 51 | |
| 52 | describe("shouldShowInstanceBadge", () => { |
| 53 | it("hides badges for distinct ACP agents sharing the registry driver", () => { |
| 54 | const mistral = { driverKind: acpRegistry, acpRegistryAgentId: "mistral-vibe", enabled: true }; |
| 55 | const devin = { driverKind: acpRegistry, acpRegistryAgentId: "devin", enabled: true }; |
| 56 | expect(shouldShowInstanceBadge(mistral, [mistral, devin])).toBe(false); |
| 57 | expect(shouldShowInstanceBadge(devin, [mistral, devin])).toBe(false); |
| 58 | }); |
| 59 | |
| 60 | it("distinguishes registry instances whose agent identity is unavailable", () => { |
| 61 | const entry = { driverKind: acpRegistry, enabled: true }; |
| 62 | expect(shouldShowInstanceBadge(entry, [entry, { ...entry }])).toBe(true); |
| 63 | }); |
| 64 | |
| 65 | it("shows the badge when the entry has an accent color", () => { |
| 66 | const entry = { driverKind: codex, accentColor: "#ff8800", enabled: true }; |
| 67 | expect(shouldShowInstanceBadge(entry, [entry])).toBe(true); |
| 68 | }); |
| 69 | |
| 70 | it("ignores a non-hex accent color", () => { |
| 71 | const entry = { driverKind: codex, accentColor: "blue", enabled: true }; |
| 72 | expect(shouldShowInstanceBadge(entry, [entry])).toBe(false); |
| 73 | }); |
| 74 | |
| 75 | it("shows the badge when two entries share a driver, even without an accent", () => { |
| 76 | const first = { driverKind: codex, accentColor: undefined, enabled: true }; |
| 77 | const second = { driverKind: codex, accentColor: undefined, enabled: true }; |
| 78 | expect(shouldShowInstanceBadge(first, [first, second])).toBe(true); |
| 79 | }); |
| 80 | |
| 81 | it("ignores disabled siblings for enabled instances while distinguishing historical owners", () => { |
| 82 | const enabled = { driverKind: codex, enabled: true }; |
| 83 | const disabled = { driverKind: codex, enabled: false }; |
| 84 | |
| 85 | expect(shouldShowInstanceBadge(enabled, [enabled, disabled])).toBe(false); |
| 86 | expect(shouldShowInstanceBadge(disabled, [enabled, disabled])).toBe(true); |
| 87 | expect(shouldShowInstanceBadge(disabled, [disabled, { ...disabled }])).toBe(true); |
| 88 | expect(shouldShowInstanceBadge(disabled, [disabled])).toBe(false); |
| 89 | }); |
| 90 | }); |