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("keeps an emoji whole instead of splitting its surrogate pair", () => {
16 expect(providerInstanceInitials("😀 Work")).toBe("😀W");
17 expect(providerInstanceInitials("😀")).toBe("😀");
18 });
19});
20
21describe("normalizeProviderAccentColor", () => {
22 // regression: #9899 a non-hex accent must not render as the account badge color
23 it("rejects a non-hex value", () => {
24 expect(normalizeProviderAccentColor("blue")).toBeUndefined();
25 });
26});
27
28describe("providerAccentForegroundColor", () => {
29 it.each([
30 ["#b5f23d", "#000000"],
31 ["#2563eb", "#ffffff"],
32 ["#777777", "#000000"],
33 ])("chooses the higher WCAG contrast foreground for %s", (accent, foreground) => {
34 expect(providerAccentForegroundColor(accent)).toBe(foreground);
35 });
36});
37
38describe("shouldShowInstanceBadge", () => {
39 it("hides badges for distinct ACP agents sharing the registry driver", () => {
40 const mistral = { driverKind: acpRegistry, acpRegistryAgentId: "mistral-vibe", enabled: true };
41 const devin = { driverKind: acpRegistry, acpRegistryAgentId: "devin", enabled: true };
42 expect(shouldShowInstanceBadge(mistral, [mistral, devin])).toBe(false);
43 expect(shouldShowInstanceBadge(devin, [mistral, devin])).toBe(false);
44 });
45
46 it("distinguishes registry instances whose agent identity is unavailable", () => {
47 const entry = { driverKind: acpRegistry, enabled: true };
48 expect(shouldShowInstanceBadge(entry, [entry, { ...entry }])).toBe(true);
49 });
50
51 it("shows the badge when the entry has an accent color", () => {
52 const entry = { driverKind: codex, accentColor: "#ff8800", enabled: true };
53 expect(shouldShowInstanceBadge(entry, [entry])).toBe(true);
54 });
55
56 it("shows the badge when two entries share a driver, even without an accent", () => {
57 const first = { driverKind: codex, accentColor: undefined, enabled: true };
58 const second = { driverKind: codex, accentColor: undefined, enabled: true };
59 expect(shouldShowInstanceBadge(first, [first, second])).toBe(true);
60 });
61
62 it("ignores disabled siblings for enabled instances while distinguishing historical owners", () => {
63 const enabled = { driverKind: codex, enabled: true };
64 const disabled = { driverKind: codex, enabled: false };
65
66 expect(shouldShowInstanceBadge(enabled, [enabled, disabled])).toBe(false);
67 expect(shouldShowInstanceBadge(disabled, [enabled, disabled])).toBe(true);
68 expect(shouldShowInstanceBadge(disabled, [disabled, { ...disabled }])).toBe(true);
69 expect(shouldShowInstanceBadge(disabled, [disabled])).toBe(false);
70 });
71});