Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

providerInstanceDisplay.test.ts

147 lines5.4 KB

1import { ProviderDriverKind, ProviderInstanceId } from "@t3tools/contracts";
2import { describe, expect, it } from "vite-plus/test";
3​
4import {
5 normalizeProviderAccentColor,
6 providerInstanceInitials,
7 resolveProviderInstanceDisplayName,
8 shouldShowInstanceBadge,
9} from "./providerInstanceDisplay.ts";
10​
11const codex = ProviderDriverKind.make("codex");
12const claude = ProviderDriverKind.make("claudeAgent");
13const acpRegistry = ProviderDriverKind.make("acpRegistry");
14​
15describe("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​
46describe("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​
69describe("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​
92describe("shouldShowInstanceBadge", () => {
93 it("hides badges for distinct ACP agents sharing the registry driver", () => {
94 const mistral = { driverKind: acpRegistry, acpRegistryAgentId: "mistral-vibe", enabled: true };
95 const devin = { driverKind: acpRegistry, acpRegistryAgentId: "devin", enabled: true };
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", enabled: true };
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 enabled: true,
112 };
113 expect(shouldShowInstanceBadge(entry, [entry])).toBe(true);
114 });
115​
116 it("distinguishes registry instances whose agent identity is unavailable", () => {
117 const entry = { driverKind: acpRegistry, enabled: true };
118 expect(shouldShowInstanceBadge(entry, [entry, { ...entry }])).toBe(true);
119 });
120​
121 it("shows the badge when the entry has an accent color", () => {
122 const entry = { driverKind: codex, accentColor: "#ff8800", enabled: true };
123 expect(shouldShowInstanceBadge(entry, [entry])).toBe(true);
124 });
125​
126 it("shows the badge when two entries share a driver, even without an accent", () => {
127 const first = { driverKind: codex, accentColor: undefined, enabled: true };
128 const second = { driverKind: codex, accentColor: undefined, enabled: true };
129 expect(shouldShowInstanceBadge(first, [first, second])).toBe(true);
130 });
131​
132 it("ignores disabled siblings for enabled instances while distinguishing historical owners", () => {
133 const enabled = { driverKind: codex, enabled: true };
134 const disabled = { driverKind: codex, enabled: false };
135​
136 expect(shouldShowInstanceBadge(enabled, [enabled, disabled])).toBe(false);
137 expect(shouldShowInstanceBadge(disabled, [enabled, disabled])).toBe(true);
138 expect(shouldShowInstanceBadge(disabled, [disabled, { ...disabled }])).toBe(true);
139 expect(shouldShowInstanceBadge(disabled, [disabled])).toBe(false);
140 });
141​
142 it("hides the badge for a single instance of a driver with no accent", () => {
143 const entry = { driverKind: codex, accentColor: undefined, enabled: true };
144 const other = { driverKind: claude, accentColor: undefined, enabled: true };
145 expect(shouldShowInstanceBadge(entry, [entry, other])).toBe(false);
146 });
147});