Files
t3code/packages/client-runtime/src/state/providerInstanceDisplay.test.ts
T
+36 de34391427 feat(orchestrator): introduce new orchestrator (#2829)
Co-authored-by: maria-rcks <[email protected]>
Co-authored-by: Bilal Bakr <[email protected]>
Co-authored-by: shivam <[email protected]>
Co-authored-by: Vitalii Yehorov <[email protected]>
Co-authored-by: Jake Leventhal <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Co-authored-by: Alex Southwell <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Nicholas Wasmiller <[email protected]>
Co-authored-by: PB <[email protected]>
Co-authored-by: Exotic <[email protected]>
Co-authored-by: Yash Singh <[email protected]>
Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Theo Browne <[email protected]>
Co-authored-by: Gabriel De Andrade <[email protected]>
Co-authored-by: Dara Adedeji <[email protected]>
Co-authored-by: scratchyone <[email protected]>
Co-authored-by: Dominic Roy <[email protected]>
Co-authored-by: chukfinley <[email protected]>
Co-authored-by: Primož Ajdišek <[email protected]>
Co-authored-by: benthecarman <[email protected]>
Co-authored-by: NaveDanan <[email protected]>
Co-authored-by: aaditagrawal <[email protected]>
Co-authored-by: Aditya Garud <[email protected]>
Co-authored-by: Nick Anisimov <[email protected]>
Co-authored-by: MacKinley Smith <[email protected]>
Co-authored-by: Yordis Prieto <[email protected]>
Co-authored-by: t3-code[bot] <269035359+t3-code[bot]@users.noreply.github.com>
Co-authored-by: AKolenda <[email protected]>
Co-authored-by: Guillermo Casanova <[email protected]>
Co-authored-by: Otavio Salvador <[email protected]>
Co-authored-by: Shirish Pothi <[email protected]>
Co-authored-by: Ishaan Kothari <[email protected]>
Co-authored-by: Bob Fowler <[email protected]>
Co-authored-by: Anton Bezdenezhnykh <[email protected]>
Co-authored-by: ValeraZSD <[email protected]>
Co-authored-by: Ephraim <[email protected]>
Co-authored-by: Ryan Ilano <[email protected]>
Co-authored-by: Alex <[email protected]>
Co-authored-by: maco <[email protected]>
Co-authored-by: Cursor <[email protected]>
Co-authored-by: Tristan Knight <[email protected]>
Co-authored-by: PR Batch Tester <[email protected]>
Co-authored-by: oliver <[email protected]>
Co-authored-by: kamkm <[email protected]>
Signed-off-by: Yordis Prieto <[email protected]>
2026-10-02 12:22:22 -07:00

137 lines
4.7 KiB
TypeScript

import { ProviderDriverKind, ProviderInstanceId } from "@t3tools/contracts";
import { describe, expect, it } from "vite-plus/test";
import {
normalizeProviderAccentColor,
providerInstanceInitials,
resolveProviderInstanceDisplayName,
shouldShowInstanceBadge,
} from "./providerInstanceDisplay.ts";
const codex = ProviderDriverKind.make("codex");
const claude = ProviderDriverKind.make("claudeAgent");
const acpRegistry = ProviderDriverKind.make("acpRegistry");
describe("resolveProviderInstanceDisplayName", () => {
it("keeps a snapshot name that differs from the brand label", () => {
expect(
resolveProviderInstanceDisplayName({
instanceId: ProviderInstanceId.make("codex"),
driver: codex,
displayName: "Work",
}),
).toBe("Work");
});
it("humanizes a custom instance id when the snapshot only carries the brand label", () => {
expect(
resolveProviderInstanceDisplayName({
instanceId: ProviderInstanceId.make("codex_personal"),
driver: codex,
displayName: "Codex",
}),
).toBe("Codex Personal");
});
it("uses the brand label for the default instance", () => {
expect(
resolveProviderInstanceDisplayName({
instanceId: ProviderInstanceId.make("codex"),
driver: codex,
}),
).toBe("Codex");
});
});
describe("providerInstanceInitials", () => {
it("takes the first two characters of a single word", () => {
expect(providerInstanceInitials("Codex")).toBe("CO");
});
it("takes the first character of each of the first two words", () => {
expect(providerInstanceInitials("Codex Personal")).toBe("CP");
});
it("ignores words past the first two", () => {
expect(providerInstanceInitials("Codex Personal Backup Account")).toBe("CP");
});
it("returns an empty string for an empty label", () => {
expect(providerInstanceInitials("")).toBe("");
});
it("keeps an emoji whole instead of splitting its surrogate pair", () => {
expect(providerInstanceInitials("😀 Work")).toBe("😀W");
expect(providerInstanceInitials("😀")).toBe("😀");
});
});
describe("normalizeProviderAccentColor", () => {
it("accepts a lowercase hex color", () => {
expect(normalizeProviderAccentColor("#ff8800")).toBe("#ff8800");
});
it("accepts an uppercase hex color", () => {
expect(normalizeProviderAccentColor("#FF8800")).toBe("#FF8800");
});
it("rejects a non-hex value", () => {
expect(normalizeProviderAccentColor("blue")).toBeUndefined();
});
it("rejects a short hex value", () => {
expect(normalizeProviderAccentColor("#fff")).toBeUndefined();
});
it("treats undefined and blank as unset", () => {
expect(normalizeProviderAccentColor(undefined)).toBeUndefined();
expect(normalizeProviderAccentColor(" ")).toBeUndefined();
});
});
describe("shouldShowInstanceBadge", () => {
it("hides badges for distinct ACP agents sharing the registry driver", () => {
const mistral = { driverKind: acpRegistry, acpRegistryAgentId: "mistral-vibe" };
const devin = { driverKind: acpRegistry, acpRegistryAgentId: "devin" };
expect(shouldShowInstanceBadge(mistral, [mistral, devin])).toBe(false);
expect(shouldShowInstanceBadge(devin, [mistral, devin])).toBe(false);
});
it("shows badges for multiple instances of the same ACP agent", () => {
const first = { driverKind: acpRegistry, acpRegistryAgentId: "mistral-vibe" };
const second = { ...first };
expect(shouldShowInstanceBadge(first, [first, second])).toBe(true);
});
it("keeps an explicit accent on a single ACP agent", () => {
const entry = {
driverKind: acpRegistry,
acpRegistryAgentId: "mistral-vibe",
accentColor: "#ff8800",
};
expect(shouldShowInstanceBadge(entry, [entry])).toBe(true);
});
it("distinguishes registry instances whose agent identity is unavailable", () => {
const entry = { driverKind: acpRegistry };
expect(shouldShowInstanceBadge(entry, [entry, { ...entry }])).toBe(true);
});
it("shows the badge when the entry has an accent color", () => {
const entry = { driverKind: codex, accentColor: "#ff8800" };
expect(shouldShowInstanceBadge(entry, [entry])).toBe(true);
});
it("shows the badge when two entries share a driver, even without an accent", () => {
const first = { driverKind: codex, accentColor: undefined };
const second = { driverKind: codex, accentColor: undefined };
expect(shouldShowInstanceBadge(first, [first, second])).toBe(true);
});
it("hides the badge for a single instance of a driver with no accent", () => {
const entry = { driverKind: codex, accentColor: undefined };
const other = { driverKind: claude, accentColor: undefined };
expect(shouldShowInstanceBadge(entry, [entry, other])).toBe(false);
});
});