|
| 1 | +import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell"; |
| 2 | +import { |
| 3 | + EnvironmentId, |
| 4 | + ProjectId, |
| 5 | + ProviderInstanceId, |
| 6 | + ThreadId, |
| 7 | + type ServerConfig, |
| 8 | +} from "@t3tools/contracts"; |
| 9 | +import { describe, expect, it } from "vite-plus/test"; |
| 10 | + |
| 11 | +import { resolveThreadProviderInstance } from "./thread-provider-instance"; |
| 12 | + |
| 13 | +function makeConfig( |
| 14 | + providers: ReadonlyArray<{ |
| 15 | + readonly instanceId: string; |
| 16 | + readonly driver: string; |
| 17 | + readonly displayName?: string; |
| 18 | + readonly accentColor?: string; |
| 19 | + }>, |
| 20 | +): ServerConfig { |
| 21 | + return { providers } as unknown as ServerConfig; |
| 22 | +} |
| 23 | + |
| 24 | +function makeThread(environmentId: EnvironmentId, instanceId: string): EnvironmentThreadShell { |
| 25 | + return { |
| 26 | + environmentId, |
| 27 | + id: ThreadId.make("thread-1"), |
| 28 | + projectId: ProjectId.make("project-1"), |
| 29 | + title: "Thread", |
| 30 | + modelSelection: { instanceId: ProviderInstanceId.make(instanceId), model: "gpt-5.4" }, |
| 31 | + runtimeMode: "full-access", |
| 32 | + interactionMode: "default", |
| 33 | + branch: null, |
| 34 | + worktreePath: null, |
| 35 | + latestTurn: null, |
| 36 | + createdAt: "2026-06-01T00:00:00.000Z", |
| 37 | + updatedAt: "2026-06-01T00:00:00.000Z", |
| 38 | + archivedAt: null, |
| 39 | + settledOverride: null, |
| 40 | + settledAt: null, |
| 41 | + session: null, |
| 42 | + latestUserMessageAt: null, |
| 43 | + hasPendingApprovals: false, |
| 44 | + hasPendingUserInput: false, |
| 45 | + hasActionableProposedPlan: false, |
| 46 | + } as unknown as EnvironmentThreadShell; |
| 47 | +} |
| 48 | + |
| 49 | +describe("resolveThreadProviderInstance", () => { |
| 50 | + it("resolves two environments with the same default instance id independently", () => { |
| 51 | + const environmentA = EnvironmentId.make("environment-a"); |
| 52 | + const environmentB = EnvironmentId.make("environment-b"); |
| 53 | + const serverConfigs = new Map<EnvironmentId, ServerConfig>([ |
| 54 | + [ |
| 55 | + environmentA, |
| 56 | + makeConfig([{ instanceId: "codex", driver: "codex", accentColor: "#ff8800" }]), |
| 57 | + ], |
| 58 | + [environmentB, makeConfig([{ instanceId: "codex", driver: "codex" }])], |
| 59 | + ]); |
| 60 | + |
| 61 | + const threadA = makeThread(environmentA, "codex"); |
| 62 | + const threadB = makeThread(environmentB, "codex"); |
| 63 | + |
| 64 | + expect(resolveThreadProviderInstance(serverConfigs, threadA)?.accentColor).toBe("#ff8800"); |
| 65 | + expect(resolveThreadProviderInstance(serverConfigs, threadB)?.accentColor).toBeUndefined(); |
| 66 | + }); |
| 67 | + |
| 68 | + it("labels a custom instance by its id so its initials differ from the default", () => { |
| 69 | + const environmentId = EnvironmentId.make("environment-a"); |
| 70 | + const serverConfigs = new Map<EnvironmentId, ServerConfig>([ |
| 71 | + [ |
| 72 | + environmentId, |
| 73 | + makeConfig([ |
| 74 | + { instanceId: "codex", driver: "codex", displayName: "Codex" }, |
| 75 | + { instanceId: "codex_personal", driver: "codex", displayName: "Codex" }, |
| 76 | + ]), |
| 77 | + ], |
| 78 | + ]); |
| 79 | + |
| 80 | + expect( |
| 81 | + resolveThreadProviderInstance(serverConfigs, makeThread(environmentId, "codex"))?.displayName, |
| 82 | + ).toBe("Codex"); |
| 83 | + expect( |
| 84 | + resolveThreadProviderInstance(serverConfigs, makeThread(environmentId, "codex_personal")) |
| 85 | + ?.displayName, |
| 86 | + ).toBe("Codex Personal"); |
| 87 | + }); |
| 88 | + |
| 89 | + it("hides the badge for a single instance with no accent color", () => { |
| 90 | + const environmentId = EnvironmentId.make("environment-a"); |
| 91 | + const serverConfigs = new Map<EnvironmentId, ServerConfig>([ |
| 92 | + [environmentId, makeConfig([{ instanceId: "codex", driver: "codex" }])], |
| 93 | + ]); |
| 94 | + const thread = makeThread(environmentId, "codex"); |
| 95 | + |
| 96 | + expect(resolveThreadProviderInstance(serverConfigs, thread)?.showBadge).toBe(false); |
| 97 | + }); |
| 98 | +}); |
0 commit comments