| 1 | import { ProviderDriverKind, ProviderInstanceId } from "@t3tools/contracts"; |
| 2 | import { describe, expect, it } from "vite-plus/test"; |
| 3 | |
| 4 | import { |
| 5 | normalizeProviderAccentColor, |
| 6 | providerInstanceInitials, |
| 7 | resolveProviderInstanceDisplayName, |
| 8 | shouldShowInstanceBadge, |
| 9 | } from "./providerInstanceDisplay.ts"; |
| 10 | |
| 11 | const codex = ProviderDriverKind.make("codex"); |
| 12 | const claude = ProviderDriverKind.make("claudeAgent"); |
| 13 | const acpRegistry = ProviderDriverKind.make("acpRegistry"); |
| 14 | |
| 15 | describe("resolveProviderInstanceDisplayName", () => { |
| 16 | it("keeps a snapshot name that differs from the brand label", () => { |
| 17 | expect( |
| 18 | resolveProviderInstanceDisplayName({ |
| 19 | instanceId: ProviderInstanceId.make("codex"), |
| 20 | driver: codex, |
| 21 | displayName: "Work", |
| 22 | }), |
| 23 | ).toBe("Work"); |
| 24 | }); |
| 25 | |
| 26 | it("humanizes a custom instance id when the snapshot only carries the brand label", () => { |
| 27 | expect( |
| 28 | resolveProviderInstanceDisplayName({ |
| 29 | instanceId: ProviderInstanceId.make("codex_personal"), |
| 30 | driver: codex, |
| 31 | displayName: "Codex", |
| 32 | }), |
| 33 | ).toBe("Codex Personal"); |
| 34 | }); |
| 35 | |
| 36 | it("uses the brand label for the default instance", () => { |
| 37 | expect( |
| 38 | resolveProviderInstanceDisplayName({ |
| 39 | instanceId: ProviderInstanceId.make("codex"), |
| 40 | driver: codex, |
| 41 | }), |
| 42 | ).toBe("Codex"); |
| 43 | }); |
| 44 | }); |
| 45 | |
| 46 | describe("providerInstanceInitials", () => { |
| 47 | it("takes the first two characters of a single word", () => { |
| 48 | expect(providerInstanceInitials("Codex")).toBe("CO"); |
| 49 | }); |
| 50 | |
| 51 | it("takes the first character of each of the first two words", () => { |
| 52 | expect(providerInstanceInitials("Codex Personal")).toBe("CP"); |
| 53 | }); |
| 54 | |
| 55 | it("ignores words past the first two", () => { |
| 56 | expect(providerInstanceInitials("Codex Personal Backup Account")).toBe("CP"); |
| 57 | }); |
| 58 | |
| 59 | it("returns an empty string for an empty label", () => { |
| 60 | expect(providerInstanceInitials("")).toBe(""); |
| 61 | }); |
| 62 | |
| 63 | it("keeps an emoji whole instead of splitting its surrogate pair", () => { |
| 64 | expect(providerInstanceInitials("😀 Work")).toBe("😀W"); |
| 65 | expect(providerInstanceInitials("😀")).toBe("😀"); |
| 66 | }); |
| 67 | }); |
| 68 | |
| 69 | describe("normalizeProviderAccentColor", () => { |
| 70 | it("accepts a lowercase hex color", () => { |
| 71 | expect(normalizeProviderAccentColor("#ff8800")).toBe("#ff8800"); |
| 72 | }); |
| 73 | |
| 74 | it("accepts an uppercase hex color", () => { |
| 75 | expect(normalizeProviderAccentColor("#FF8800")).toBe("#FF8800"); |
| 76 | }); |
| 77 | |
| 78 | it("rejects a non-hex value", () => { |
| 79 | expect(normalizeProviderAccentColor("blue")).toBeUndefined(); |
| 80 | }); |
| 81 | |
| 82 | it("rejects a short hex value", () => { |
| 83 | expect(normalizeProviderAccentColor("#fff")).toBeUndefined(); |
| 84 | }); |
| 85 | |
| 86 | it("treats undefined and blank as unset", () => { |
| 87 | expect(normalizeProviderAccentColor(undefined)).toBeUndefined(); |
| 88 | expect(normalizeProviderAccentColor(" ")).toBeUndefined(); |
| 89 | }); |
| 90 | }); |
| 91 | |
| 92 | describe("shouldShowInstanceBadge", () => { |
| 93 | it("hides badges for distinct ACP agents sharing the registry driver", () => { |
| 94 | const mistral = { driverKind: acpRegistry, acpRegistryAgentId: "mistral-vibe" }; |
| 95 | const devin = { driverKind: acpRegistry, acpRegistryAgentId: "devin" }; |
| 96 | expect(shouldShowInstanceBadge(mistral, [mistral, devin])).toBe(false); |
| 97 | expect(shouldShowInstanceBadge(devin, [mistral, devin])).toBe(false); |
| 98 | }); |
| 99 | |
| 100 | it("shows badges for multiple instances of the same ACP agent", () => { |
| 101 | const first = { driverKind: acpRegistry, acpRegistryAgentId: "mistral-vibe" }; |
| 102 | const second = { ...first }; |
| 103 | expect(shouldShowInstanceBadge(first, [first, second])).toBe(true); |
| 104 | }); |
| 105 | |
| 106 | it("keeps an explicit accent on a single ACP agent", () => { |
| 107 | const entry = { |
| 108 | driverKind: acpRegistry, |
| 109 | acpRegistryAgentId: "mistral-vibe", |
| 110 | accentColor: "#ff8800", |
| 111 | }; |
| 112 | expect(shouldShowInstanceBadge(entry, [entry])).toBe(true); |
| 113 | }); |
| 114 | |
| 115 | it("distinguishes registry instances whose agent identity is unavailable", () => { |
| 116 | const entry = { driverKind: acpRegistry }; |
| 117 | expect(shouldShowInstanceBadge(entry, [entry, { ...entry }])).toBe(true); |
| 118 | }); |
| 119 | |
| 120 | it("shows the badge when the entry has an accent color", () => { |
| 121 | const entry = { driverKind: codex, accentColor: "#ff8800" }; |
| 122 | expect(shouldShowInstanceBadge(entry, [entry])).toBe(true); |
| 123 | }); |
| 124 | |
| 125 | it("shows the badge when two entries share a driver, even without an accent", () => { |
| 126 | const first = { driverKind: codex, accentColor: undefined }; |
| 127 | const second = { driverKind: codex, accentColor: undefined }; |
| 128 | expect(shouldShowInstanceBadge(first, [first, second])).toBe(true); |
| 129 | }); |
| 130 | |
| 131 | it("hides the badge for a single instance of a driver with no accent", () => { |
| 132 | const entry = { driverKind: codex, accentColor: undefined }; |
| 133 | const other = { driverKind: claude, accentColor: undefined }; |
| 134 | expect(shouldShowInstanceBadge(entry, [entry, other])).toBe(false); |
| 135 | }); |
| 136 | }); |