Open History to see the last commit
1import { ProviderDriverKind } from "@t3tools/contracts";
2import { describe, expect, it } from "vite-plus/test";
3
4import {
5 normalizeProviderAccentColor,
6 providerAccentForegroundColor,
7 providerInstanceInitials,
8 shouldShowInstanceBadge,
9} from "./providerInstanceDisplay.ts";
10
11const codex = ProviderDriverKind.make("codex");
12const acpRegistry = ProviderDriverKind.make("acpRegistry");
13
14describe("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 it("normalizes decomposed accents before extracting initials", () => {
35 expect(providerInstanceInitials("E\u0301clair")).toBe("ÉC");
36 expect(providerInstanceInitials("E\u0301clair Pro")).toBe("ÉP");
37 });
38
39 it("keeps combining marks that have no precomposed form on their letter", () => {
40 expect(providerInstanceInitials("हिन्दी Codex")).toBe("हिC");
41 expect(providerInstanceInitials("ที่บ้าน")).toBe("ที่บ้");
42 });
43});
44
45describe("normalizeProviderAccentColor", () => {
46 // regression: #9899 a non-hex accent must not render as the account badge color
47 it("rejects a non-hex value", () => {
48 expect(normalizeProviderAccentColor("blue")).toBeUndefined();
49 });
50});
51
52describe("providerAccentForegroundColor", () => {
53 it.each([
54 ["#b5f23d", "#000000"],
55 ["#2563eb", "#ffffff"],
56 ["#777777", "#000000"],
57 ])("chooses the higher WCAG contrast foreground for %s", (accent, foreground) => {
58 expect(providerAccentForegroundColor(accent)).toBe(foreground);
59 });
60});
61
62describe("shouldShowInstanceBadge", () => {
63 it("hides badges for distinct ACP agents sharing the registry driver", () => {
64 const mistral = { driverKind: acpRegistry, acpRegistryAgentId: "mistral-vibe", enabled: true };
65 const devin = { driverKind: acpRegistry, acpRegistryAgentId: "devin", enabled: true };
66 expect(shouldShowInstanceBadge(mistral, [mistral, devin])).toBe(false);
67 expect(shouldShowInstanceBadge(devin, [mistral, devin])).toBe(false);
68 });
69
70 it("distinguishes registry instances whose agent identity is unavailable", () => {
71 const entry = { driverKind: acpRegistry, enabled: true };
72 expect(shouldShowInstanceBadge(entry, [entry, { ...entry }])).toBe(true);
73 });
74
75 it("shows the badge when the entry has an accent color", () => {
76 const entry = { driverKind: codex, accentColor: "#ff8800", enabled: true };
77 expect(shouldShowInstanceBadge(entry, [entry])).toBe(true);
78 });
79
80 it("ignores a non-hex accent color", () => {
81 const entry = { driverKind: codex, accentColor: "blue", enabled: true };
82 expect(shouldShowInstanceBadge(entry, [entry])).toBe(false);
83 });
84
85 it("shows the badge when two entries share a driver, even without an accent", () => {
86 const first = { driverKind: codex, accentColor: undefined, enabled: true };
87 const second = { driverKind: codex, accentColor: undefined, enabled: true };
88 expect(shouldShowInstanceBadge(first, [first, second])).toBe(true);
89 });
90
91 it("ignores disabled siblings for enabled instances while distinguishing historical owners", () => {
92 const enabled = { driverKind: codex, enabled: true };
93 const disabled = { driverKind: codex, enabled: false };
94
95 expect(shouldShowInstanceBadge(enabled, [enabled, disabled])).toBe(false);
96 expect(shouldShowInstanceBadge(disabled, [enabled, disabled])).toBe(true);
97 expect(shouldShowInstanceBadge(disabled, [disabled, { ...disabled }])).toBe(true);
98 expect(shouldShowInstanceBadge(disabled, [disabled])).toBe(false);
99 });
100});