+36
![github-actions[bot]](/assets/img/avatar_default.png)








Julius Marminge
maria-rcks
Bilal Bakr
shivam
Vitalii Yehorov
Jake Leventhal
Claude Opus 5
Alex Southwell
github-actions[bot]
Nicholas Wasmiller
PB
Exotic
Yash Singh
Devin
Theo Browne
Gabriel De Andrade
Dara Adedeji
scratchyone
Dominic Roy
chukfinley
Primož Ajdišek
benthecarman
NaveDanan
aaditagrawal
Aditya Garud
Nick Anisimov
MacKinley Smith
Yordis Prieto
t3-code[bot]
AKolenda
Guillermo Casanova
Otavio Salvador
Shirish Pothi
Ishaan Kothari
Bob Fowler
Anton Bezdenezhnykh
ValeraZSD
Ephraim
Ryan Ilano
Alex
maco
Cursor
Tristan Knight
PR Batch Tester
oliver
kamkm
de34391427
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]>
208 lines
7.1 KiB
TypeScript
208 lines
7.1 KiB
TypeScript
import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
|
|
import {
|
|
EnvironmentId,
|
|
ProjectId,
|
|
ProviderInstanceId,
|
|
ThreadId,
|
|
type ServerConfig,
|
|
} from "@t3tools/contracts";
|
|
import { describe, expect, it } from "vite-plus/test";
|
|
|
|
import {
|
|
createThreadRowProviderInstanceResolver,
|
|
resolveThreadProviderInstance,
|
|
} from "./thread-provider-instance";
|
|
|
|
function makeConfig(
|
|
providers: ReadonlyArray<{
|
|
readonly instanceId: string;
|
|
readonly driver: string;
|
|
readonly displayName?: string;
|
|
readonly accentColor?: string;
|
|
}>,
|
|
): ServerConfig {
|
|
return { providers } as unknown as ServerConfig;
|
|
}
|
|
|
|
function makeThread(environmentId: EnvironmentId, instanceId: string): EnvironmentThreadShell {
|
|
return {
|
|
environmentId,
|
|
id: ThreadId.make("thread-1"),
|
|
projectId: ProjectId.make("project-1"),
|
|
title: "Thread",
|
|
modelSelection: { instanceId: ProviderInstanceId.make(instanceId), model: "gpt-5.4" },
|
|
runtimeMode: "full-access",
|
|
interactionMode: "default",
|
|
branch: null,
|
|
worktreePath: null,
|
|
latestRun: null,
|
|
createdAt: "2026-06-01T00:00:00.000Z",
|
|
updatedAt: "2026-06-01T00:00:00.000Z",
|
|
archivedAt: null,
|
|
settledOverride: null,
|
|
settledAt: null,
|
|
runtime: null,
|
|
latestUserMessageAt: null,
|
|
hasPendingApprovals: false,
|
|
hasPendingUserInput: false,
|
|
hasActionableProposedPlan: false,
|
|
} as unknown as EnvironmentThreadShell;
|
|
}
|
|
|
|
describe("resolveThreadProviderInstance", () => {
|
|
it("resolves two environments with the same default instance id independently", () => {
|
|
const environmentA = EnvironmentId.make("environment-a");
|
|
const environmentB = EnvironmentId.make("environment-b");
|
|
const serverConfigs = new Map<EnvironmentId, ServerConfig>([
|
|
[
|
|
environmentA,
|
|
makeConfig([{ instanceId: "codex", driver: "codex", accentColor: "#ff8800" }]),
|
|
],
|
|
[environmentB, makeConfig([{ instanceId: "codex", driver: "codex" }])],
|
|
]);
|
|
|
|
const threadA = makeThread(environmentA, "codex");
|
|
const threadB = makeThread(environmentB, "codex");
|
|
|
|
expect(
|
|
resolveThreadProviderInstance(serverConfigs.get(environmentA)?.providers, threadA)
|
|
?.accentColor,
|
|
).toBe("#ff8800");
|
|
expect(
|
|
resolveThreadProviderInstance(serverConfigs.get(environmentB)?.providers, threadB)
|
|
?.accentColor,
|
|
).toBeUndefined();
|
|
});
|
|
|
|
it("labels a custom instance by its id so its initials differ from the default", () => {
|
|
const environmentId = EnvironmentId.make("environment-a");
|
|
const serverConfigs = new Map<EnvironmentId, ServerConfig>([
|
|
[
|
|
environmentId,
|
|
makeConfig([
|
|
{ instanceId: "codex", driver: "codex", displayName: "Codex" },
|
|
{ instanceId: "codex_personal", driver: "codex", displayName: "Codex" },
|
|
]),
|
|
],
|
|
]);
|
|
|
|
expect(
|
|
resolveThreadProviderInstance(
|
|
serverConfigs.get(environmentId)?.providers,
|
|
makeThread(environmentId, "codex"),
|
|
)?.displayName,
|
|
).toBe("Codex");
|
|
expect(
|
|
resolveThreadProviderInstance(
|
|
serverConfigs.get(environmentId)?.providers,
|
|
makeThread(environmentId, "codex_personal"),
|
|
)?.displayName,
|
|
).toBe("Codex Personal");
|
|
});
|
|
|
|
it("uses the current runtime owner after a provider handoff", () => {
|
|
const environmentId = EnvironmentId.make("environment-a");
|
|
const serverConfigs = new Map<EnvironmentId, ServerConfig>([
|
|
[
|
|
environmentId,
|
|
makeConfig([
|
|
{ instanceId: "claudeAgent", driver: "claudeAgent" },
|
|
{ instanceId: "codex", driver: "codex", displayName: "Codex" },
|
|
{ instanceId: "codex_work", driver: "codex", displayName: "Codex" },
|
|
]),
|
|
],
|
|
]);
|
|
const thread = {
|
|
...makeThread(environmentId, "claudeAgent"),
|
|
runtime: {
|
|
status: "running" as const,
|
|
activeRunId: null,
|
|
providerInstanceId: ProviderInstanceId.make("codex_work"),
|
|
providerName: "Codex",
|
|
lastError: null,
|
|
updatedAt: "2026-06-01T00:01:00.000Z",
|
|
},
|
|
};
|
|
|
|
expect(
|
|
resolveThreadProviderInstance(serverConfigs.get(environmentId)?.providers, thread),
|
|
).toMatchObject({
|
|
driverKind: "codex",
|
|
displayName: "Codex Work",
|
|
showBadge: true,
|
|
});
|
|
});
|
|
|
|
it("hides the badge for a single instance with no accent color", () => {
|
|
const environmentId = EnvironmentId.make("environment-a");
|
|
const serverConfigs = new Map<EnvironmentId, ServerConfig>([
|
|
[environmentId, makeConfig([{ instanceId: "codex", driver: "codex" }])],
|
|
]);
|
|
const thread = makeThread(environmentId, "codex");
|
|
|
|
expect(
|
|
resolveThreadProviderInstance(serverConfigs.get(environmentId)?.providers, thread)?.showBadge,
|
|
).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe("createThreadRowProviderInstanceResolver", () => {
|
|
const environmentId = EnvironmentId.make("environment-a");
|
|
const serverConfigs = new Map<EnvironmentId, ServerConfig>([
|
|
[
|
|
environmentId,
|
|
makeConfig([
|
|
{ instanceId: "codex", driver: "codex", displayName: "Codex" },
|
|
{ instanceId: "codex_work", driver: "codex", displayName: "Codex" },
|
|
]),
|
|
],
|
|
]);
|
|
|
|
it("hands out the same reference for repeated lookups of one instance", () => {
|
|
const resolve = createThreadRowProviderInstanceResolver(
|
|
new Map([...serverConfigs].map(([id, config]) => [id, config.providers])),
|
|
);
|
|
const first = resolve(makeThread(environmentId, "codex"));
|
|
const second = resolve(makeThread(environmentId, "codex"));
|
|
// Memoized rows compare props by reference: a fresh object per call would
|
|
// re-render every row on every parent render (minute tick included).
|
|
expect(first).not.toBeNull();
|
|
expect(second).toBe(first);
|
|
});
|
|
|
|
it("distinguishes instances of the same driver", () => {
|
|
const resolve = createThreadRowProviderInstanceResolver(
|
|
new Map([...serverConfigs].map(([id, config]) => [id, config.providers])),
|
|
);
|
|
const personal = resolve(makeThread(environmentId, "codex"));
|
|
const work = resolve(makeThread(environmentId, "codex_work"));
|
|
expect(personal).not.toBeNull();
|
|
expect(work).not.toBeNull();
|
|
expect(work).not.toBe(personal);
|
|
expect(work?.displayName).toBe("Codex Work");
|
|
});
|
|
|
|
it("hands out a new identity when the server-config generation changes", () => {
|
|
const before = createThreadRowProviderInstanceResolver(
|
|
new Map([...serverConfigs].map(([id, config]) => [id, config.providers])),
|
|
);
|
|
const nextConfigs = new Map<EnvironmentId, ServerConfig>([
|
|
[environmentId, makeConfig([{ instanceId: "codex", driver: "codex" }])],
|
|
]);
|
|
const after = createThreadRowProviderInstanceResolver(
|
|
new Map([...nextConfigs].map(([id, config]) => [id, config.providers])),
|
|
);
|
|
expect(after(makeThread(environmentId, "codex"))).not.toBe(
|
|
before(makeThread(environmentId, "codex")),
|
|
);
|
|
});
|
|
|
|
it("resolves unknown instances to null without throwing", () => {
|
|
const resolve = createThreadRowProviderInstanceResolver(
|
|
new Map([...serverConfigs].map(([id, config]) => [id, config.providers])),
|
|
);
|
|
expect(resolve(makeThread(environmentId, "ghost"))).toBeNull();
|
|
expect(resolve(makeThread(environmentId, "ghost"))).toBeNull();
|
|
});
|
|
});
|