+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]>
498 lines
16 KiB
TypeScript
498 lines
16 KiB
TypeScript
import { act, cloneElement, type ReactElement, type ReactNode } from "react";
|
|
import { create, type ReactTestRenderer } from "react-test-renderer";
|
|
import { EnvironmentId, ThreadId, type OrchestrationV2ContextTransfer } from "@t3tools/contracts";
|
|
import * as DateTime from "effect/DateTime";
|
|
import { afterEach, expect, it, vi } from "vite-plus/test";
|
|
|
|
const state = vi.hoisted(() => ({
|
|
projection: null as unknown,
|
|
navigate: vi.fn(),
|
|
shells: [] as unknown[],
|
|
projects: [] as unknown[],
|
|
configs: new Map<string, unknown>(),
|
|
showTooltips: false,
|
|
}));
|
|
|
|
vi.mock("@tanstack/react-router", () => ({ useNavigate: () => state.navigate }));
|
|
vi.mock("../../state/entities", () => ({
|
|
useThreadProjection: () => ({ projection: state.projection }),
|
|
useThreadShells: () => state.shells,
|
|
useProjects: () => state.projects,
|
|
useServerConfigs: () => state.configs,
|
|
}));
|
|
vi.mock("../../lib/archivedThreadsState", () => ({
|
|
useArchivedThreadSnapshots: () => ({ snapshots: [] }),
|
|
}));
|
|
vi.mock("../../state/use-atom-command", () => ({ useAtomCommand: () => vi.fn() }));
|
|
vi.mock("../ui/tooltip", () => ({
|
|
Tooltip: ({ children }: { children: ReactNode }) => children,
|
|
TooltipTrigger: ({ render, children }: { render: ReactElement; children: ReactNode }) =>
|
|
cloneElement(render, {}, children),
|
|
TooltipPopup: ({ children }: { children: ReactNode }) => (state.showTooltips ? children : null),
|
|
}));
|
|
|
|
import { ThreadRelationshipsPanel } from "./ThreadRelationshipsControl";
|
|
|
|
let renderer: ReactTestRenderer;
|
|
|
|
afterEach(async () => {
|
|
await act(async () => renderer?.unmount());
|
|
vi.unstubAllGlobals();
|
|
state.shells = [];
|
|
state.projects = [];
|
|
state.configs.clear();
|
|
state.showTooltips = false;
|
|
});
|
|
|
|
it("shows the matching child agent details and refreshes them when the agent settles", async () => {
|
|
vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
|
|
const agent = {
|
|
id: "agent-1",
|
|
driver: "codex",
|
|
providerInstanceId: "codex",
|
|
childThreadId: "child-1",
|
|
title: "Checker",
|
|
prompt: "Check the change",
|
|
model: "gpt-5.4",
|
|
status: "running",
|
|
progress: "Running checks",
|
|
result: null,
|
|
startedAt: DateTime.makeUnsafe("2026-09-16T12:00:00Z"),
|
|
completedAt: null,
|
|
updatedAt: DateTime.makeUnsafe("2026-09-16T12:00:00Z"),
|
|
};
|
|
const projection = {
|
|
thread: {
|
|
id: "parent",
|
|
lineage: { relationshipToParent: null },
|
|
activeProviderThreadId: null,
|
|
},
|
|
runs: [],
|
|
providerThreads: [],
|
|
providerSessions: [],
|
|
contextTransfers: [],
|
|
subagents: [
|
|
{ ...agent, id: "unlinked", childThreadId: null, title: "Unlinked agent" },
|
|
agent,
|
|
{ ...agent, id: "agent-2", childThreadId: "child-2", title: "Worker", model: "gpt-5.3" },
|
|
],
|
|
};
|
|
state.projection = projection;
|
|
const panel = (
|
|
<ThreadRelationshipsPanel
|
|
environmentId={EnvironmentId.make("test")}
|
|
threadId={ThreadId.make("parent")}
|
|
/>
|
|
);
|
|
await act(async () => {
|
|
renderer = create(panel);
|
|
});
|
|
const text = () =>
|
|
renderer.root
|
|
.findAll((node) => typeof node.type === "string")
|
|
.flatMap((node) => node.children.filter((child) => typeof child === "string"))
|
|
.join(" ")
|
|
.replace(/\s+/g, " ");
|
|
expect(text()).toContain("Checker");
|
|
expect(text()).toContain("Lineage · 3 running");
|
|
expect(text()).toContain("running");
|
|
expect(text()).not.toContain("gpt-5.4");
|
|
expect(text()).not.toContain("gpt-5.3");
|
|
expect(text()).not.toContain("tok");
|
|
expect(text()).not.toContain("Unlinked agent");
|
|
expect(text()).not.toContain("Active agents");
|
|
expect(renderer.root.findAllByProps({ type: "button", "aria-expanded": true })).toHaveLength(0);
|
|
|
|
state.projection = {
|
|
...projection,
|
|
subagents: [
|
|
{
|
|
...agent,
|
|
status: "completed",
|
|
progress: undefined,
|
|
result: "All checks passed",
|
|
completedAt: DateTime.makeUnsafe("2026-09-16T12:02:15Z"),
|
|
},
|
|
],
|
|
};
|
|
await act(async () => renderer.update(cloneElement(panel)));
|
|
expect(renderer.root.findByType("h3").children).toEqual(["Lineage"]);
|
|
expect(text()).toContain("Previous agents (1)");
|
|
expect(text()).not.toContain("Checker");
|
|
await act(async () =>
|
|
renderer.root.findByProps({ type: "button", "aria-expanded": false }).props.onClick(),
|
|
);
|
|
expect(text()).toContain("Checker");
|
|
expect(text()).toContain("2m 15s");
|
|
expect(text()).not.toContain("(1)");
|
|
expect(text()).toContain("Done");
|
|
expect(text()).not.toContain("running");
|
|
expect(text()).not.toContain("Worker");
|
|
await act(async () =>
|
|
renderer.root.findByProps({ type: "button", "aria-expanded": true }).props.onClick(),
|
|
);
|
|
expect(text()).not.toContain("Checker");
|
|
expect(text()).toContain("Previous agents (1)");
|
|
await act(async () =>
|
|
renderer.root.findByProps({ type: "button", "aria-expanded": false }).props.onClick(),
|
|
);
|
|
expect(text()).toContain("Checker");
|
|
|
|
state.projection = {
|
|
...projection,
|
|
subagents: Array.from({ length: 8 }, (_, index) => ({
|
|
...agent,
|
|
id: `running-agent-${index}`,
|
|
childThreadId: `running-child-${index}`,
|
|
})),
|
|
};
|
|
await act(async () => renderer.update(cloneElement(panel)));
|
|
expect(text()).toContain("Lineage · 8 running");
|
|
|
|
state.projection = {
|
|
...projection,
|
|
subagents: Array.from({ length: 8 }, (_, index) => ({
|
|
...agent,
|
|
id: `old-agent-${index}`,
|
|
childThreadId: `old-child-${index}`,
|
|
status: index === 7 ? "failed" : "completed",
|
|
title: `Old agent ${index}`,
|
|
result: index === 7 ? "Earlier build failed" : "Done",
|
|
completedAt: DateTime.makeUnsafe("2026-09-16T12:02:15Z"),
|
|
})),
|
|
};
|
|
await act(async () => renderer.update(cloneElement(panel)));
|
|
expect(text()).toContain("1 failed");
|
|
expect(text()).not.toContain("Old agent 7");
|
|
await act(async () =>
|
|
renderer.root
|
|
.findAllByType("button")
|
|
.find((button) => button.children.includes("Show "))!
|
|
.props.onClick(),
|
|
);
|
|
expect(text()).toContain("Old agent 7");
|
|
|
|
state.projection = {
|
|
...projection,
|
|
subagents: [{ ...agent, childThreadId: null }],
|
|
};
|
|
await act(async () => renderer.update(cloneElement(panel)));
|
|
expect(text()).toContain("Lineage · 1 running");
|
|
});
|
|
|
|
it("shows readable models and only differing workspace details in agent tooltips", async () => {
|
|
vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
|
|
state.showTooltips = true;
|
|
const parent = {
|
|
id: "parent",
|
|
projectId: "main",
|
|
worktreePath: null,
|
|
lineage: {},
|
|
activeProviderThreadId: null,
|
|
};
|
|
const child = {
|
|
id: "child",
|
|
projectId: "main",
|
|
worktreePath: null as string | null,
|
|
branch: null as string | null,
|
|
title: "Worker",
|
|
modelSelection: { instanceId: "codex", model: "gpt-5.4" },
|
|
lineage: { parentThreadId: "parent", relationshipToParent: "subagent" },
|
|
};
|
|
state.projects = [
|
|
{ id: "main", environmentId: "test", title: "Main", workspaceRoot: "/main" },
|
|
{
|
|
id: "other",
|
|
environmentId: "elsewhere",
|
|
title: "Wrong environment",
|
|
workspaceRoot: "/wrong",
|
|
},
|
|
{ id: "other", environmentId: "test", title: "Other project", workspaceRoot: "/other" },
|
|
];
|
|
state.shells = [{ environmentId: "test", source: child }];
|
|
state.configs.set("test", {
|
|
providers: [
|
|
{
|
|
instanceId: "codex",
|
|
driver: "codex",
|
|
models: [
|
|
{ slug: "gpt-5.4", name: "My GPT model", shortName: "My GPT", aliases: ["model-alias"] },
|
|
],
|
|
},
|
|
],
|
|
});
|
|
const projection = {
|
|
thread: parent,
|
|
runs: [],
|
|
providerThreads: [],
|
|
providerSessions: [],
|
|
contextTransfers: [],
|
|
subagents: [
|
|
{
|
|
id: "agent",
|
|
childThreadId: "child",
|
|
driver: "codex",
|
|
providerInstanceId: "codex",
|
|
title: "Worker",
|
|
prompt: "Check",
|
|
model: "gpt-5.4",
|
|
status: "pending",
|
|
startedAt: null,
|
|
completedAt: null,
|
|
updatedAt: DateTime.makeUnsafe("2026-09-16T12:00:00Z"),
|
|
},
|
|
],
|
|
};
|
|
state.projection = projection;
|
|
const panel = (
|
|
<ThreadRelationshipsPanel
|
|
environmentId={EnvironmentId.make("test")}
|
|
threadId={ThreadId.make("parent")}
|
|
/>
|
|
);
|
|
await act(async () => {
|
|
renderer = create(panel);
|
|
});
|
|
const text = () =>
|
|
renderer.root
|
|
.findAll((node) => typeof node.type === "string")
|
|
.flatMap((node) => node.children.filter((child) => typeof child === "string"))
|
|
.join("");
|
|
expect(text()).toContain("My GPT");
|
|
expect(text()).not.toContain("Tokens");
|
|
expect(text()).not.toContain("Open subagent");
|
|
expect(text()).not.toContain("Project");
|
|
expect(text()).not.toContain("Worktree");
|
|
expect(text()).not.toContain("Workspace");
|
|
|
|
for (const [model, expected] of [
|
|
[null, "Not reported"],
|
|
["", "Not reported"],
|
|
[" ", "Not reported"],
|
|
["model-alias", "My GPT"],
|
|
["gpt-5.5", "GPT-5.5"],
|
|
["custom/model-v1", "custom/model-v1"],
|
|
] as const) {
|
|
state.projection = {
|
|
...projection,
|
|
subagents: [{ ...projection.subagents[0], model }],
|
|
};
|
|
await act(async () => renderer.update(cloneElement(panel)));
|
|
expect(text()).toContain(expected);
|
|
expect(text()).not.toContain("Unknown");
|
|
if (!model?.trim()) expect(text()).not.toContain("My GPT");
|
|
}
|
|
|
|
for (const driver of [
|
|
"codex",
|
|
"claudeAgent",
|
|
"cursor",
|
|
"opencode",
|
|
"grok",
|
|
"antigravity",
|
|
"pi",
|
|
"acpRegistry",
|
|
]) {
|
|
state.projection = {
|
|
...projection,
|
|
subagents: [{ ...projection.subagents[0], driver, model: null }],
|
|
};
|
|
await act(async () => renderer.update(cloneElement(panel)));
|
|
expect(text()).toContain("Not reported");
|
|
expect(text()).not.toContain("My GPT");
|
|
}
|
|
|
|
state.projection = {
|
|
...projection,
|
|
subagents: [
|
|
{
|
|
...projection.subagents[0],
|
|
progress: "Checking the latest changes",
|
|
result: "Old intermediate result",
|
|
},
|
|
],
|
|
};
|
|
await act(async () => renderer.update(cloneElement(panel)));
|
|
expect(text()).toContain("Checking the latest changes");
|
|
expect(text()).not.toContain("Old intermediate result");
|
|
const result = "Final checks passed. " + "More detail. ".repeat(50) + "Hidden tail";
|
|
state.projection = {
|
|
...projection,
|
|
subagents: [
|
|
{ ...projection.subagents[0], status: "failed", progress: "Stale progress", result },
|
|
],
|
|
};
|
|
await act(async () => renderer.update(cloneElement(panel)));
|
|
await act(async () =>
|
|
renderer.root.findByProps({ type: "button", "aria-expanded": false }).props.onClick(),
|
|
);
|
|
expect(text()).toContain("Final checks passed.");
|
|
expect(text()).not.toContain("Stale progress");
|
|
expect(text()).not.toContain("Hidden tail");
|
|
expect(text()).not.toContain(result);
|
|
state.projection = projection;
|
|
|
|
child.worktreePath = "/main/worktrees/checker";
|
|
state.shells = [{ environmentId: "test", source: { ...child } }];
|
|
await act(async () => renderer.update(cloneElement(panel)));
|
|
expect(text()).toContain("Worktree");
|
|
expect(text()).toContain("checker");
|
|
expect(text()).not.toContain("/main/worktrees");
|
|
expect(text()).not.toContain("Project");
|
|
|
|
child.branch = "fix/checker";
|
|
state.shells = [{ environmentId: "test", source: { ...child } }];
|
|
await act(async () => renderer.update(cloneElement(panel)));
|
|
expect(text()).toContain("Branch");
|
|
expect(text()).toContain("fix/checker");
|
|
expect(text()).not.toContain("Worktree");
|
|
expect(text()).not.toContain("/main/worktrees");
|
|
|
|
child.projectId = "other";
|
|
child.worktreePath = null;
|
|
child.branch = null;
|
|
state.shells = [{ environmentId: "test", source: { ...child } }];
|
|
await act(async () => renderer.update(cloneElement(panel)));
|
|
expect(text()).toContain("Other project");
|
|
expect(text()).toContain("Workspace");
|
|
expect(text()).toContain("other");
|
|
expect(text()).not.toContain("/other");
|
|
expect(text()).not.toContain("Wrong environment");
|
|
expect(text()).not.toContain("Worktree");
|
|
|
|
state.shells = [];
|
|
state.configs.clear();
|
|
await act(async () => renderer.update(cloneElement(panel)));
|
|
expect(text()).toContain("GPT-5.4");
|
|
expect(text()).not.toContain("gpt-5.4");
|
|
expect(text()).not.toContain("Project");
|
|
expect(text()).not.toContain("Workspace");
|
|
|
|
for (const [driver, model, expected] of [
|
|
["codex", "gpt-5.3-codex-spark", "GPT-5.3-Codex-Spark"],
|
|
["codex", "custom/model-v2", "custom/model-v2"],
|
|
["claudeAgent", "gpt-5.4", "GPT-5.4"],
|
|
["claudeAgent", "claude-opus-4-6", "Claude Opus 4.6"],
|
|
["cursor", "composer-2", "Composer 2"],
|
|
["grok", "grok-4-fast", "Grok 4 Fast"],
|
|
["antigravity", "gemini-3.8-flash-high", "Gemini 3.8 Flash High"],
|
|
["opencode", "anthropic/claude-sonnet-4-6", "anthropic/Claude Sonnet 4.6"],
|
|
["codex", null, "Not reported"],
|
|
] as const) {
|
|
state.projection = {
|
|
...projection,
|
|
subagents: [{ ...projection.subagents[0], driver, model }],
|
|
};
|
|
await act(async () => renderer.update(cloneElement(panel)));
|
|
expect(text()).toContain(expected);
|
|
}
|
|
});
|
|
|
|
it("shows the parent's own visible status as parent and child activity change", async () => {
|
|
vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
|
|
const environmentId = EnvironmentId.make("test");
|
|
const parent = {
|
|
id: "parent",
|
|
title: "Parent conversation",
|
|
status: "completed",
|
|
activityRunStatus: "running",
|
|
lineage: { parentThreadId: null, relationshipToParent: null },
|
|
};
|
|
const child = {
|
|
id: "child",
|
|
title: "Current fork",
|
|
status: "completed",
|
|
lineage: { parentThreadId: "parent", relationshipToParent: "fork" },
|
|
};
|
|
state.projection = {
|
|
thread: { ...child, activeProviderThreadId: null },
|
|
runs: [],
|
|
providerThreads: [],
|
|
providerSessions: [],
|
|
contextTransfers: [],
|
|
subagents: [],
|
|
};
|
|
const shells = (parentSource: typeof parent, childSource: typeof child) => [
|
|
{ environmentId, source: parentSource },
|
|
{ environmentId, source: childSource },
|
|
];
|
|
state.shells = shells(parent, child);
|
|
const panel = (
|
|
<ThreadRelationshipsPanel environmentId={environmentId} threadId={ThreadId.make("child")} />
|
|
);
|
|
await act(async () => {
|
|
renderer = create(panel);
|
|
});
|
|
const visibleText = () =>
|
|
renderer.root
|
|
.findAll((node) => typeof node.type === "string" && node.props.className !== "sr-only")
|
|
.flatMap((node) => node.children.filter((child) => typeof child === "string"))
|
|
.join(" ");
|
|
expect(visibleText()).toContain("Parent conversation");
|
|
expect(visibleText()).toContain("Running");
|
|
state.shells = shells(
|
|
{ ...parent, activityRunStatus: "completed" },
|
|
{ ...child, status: "running" },
|
|
);
|
|
await act(async () => renderer.update(cloneElement(panel)));
|
|
expect(visibleText()).toContain("Done");
|
|
expect(visibleText()).not.toContain("Running");
|
|
});
|
|
|
|
it.each(["source", "target"])(
|
|
"shows transfer lifecycle states when viewing the %s thread",
|
|
async (currentThreadId) => {
|
|
vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
|
|
const environmentId = EnvironmentId.make("test");
|
|
const threads = ["source", "target"].map((id) => ({
|
|
id,
|
|
title: `${id} conversation`,
|
|
status: "running",
|
|
activityRunStatus: "running",
|
|
lineage: { parentThreadId: null, relationshipToParent: null },
|
|
}));
|
|
state.shells = threads.map((source) => ({ environmentId, source }));
|
|
const labels: Record<OrchestrationV2ContextTransfer["status"], string> = {
|
|
pending: "Queued",
|
|
resolved_native: "Resolved (native)",
|
|
resolved_portable: "Resolved (portable)",
|
|
failed: "Failed",
|
|
consumed: "Consumed",
|
|
superseded: "Superseded",
|
|
};
|
|
const panel = (
|
|
<ThreadRelationshipsPanel
|
|
environmentId={environmentId}
|
|
threadId={ThreadId.make(currentThreadId)}
|
|
/>
|
|
);
|
|
for (const [status, label] of Object.entries(labels)) {
|
|
state.projection = {
|
|
thread: {
|
|
...threads.find((thread) => thread.id === currentThreadId),
|
|
activeProviderThreadId: null,
|
|
},
|
|
runs: [],
|
|
providerThreads: [],
|
|
providerSessions: [],
|
|
subagents: [],
|
|
contextTransfers: [{ sourceThreadId: "source", targetThreadId: "target", status }],
|
|
};
|
|
await act(async () => {
|
|
if (status === "pending") renderer = create(panel);
|
|
else renderer.update(cloneElement(panel));
|
|
});
|
|
const visibleText = renderer.root
|
|
.findAll((node) => typeof node.type === "string")
|
|
.flatMap((node) => node.children.filter((child) => typeof child === "string"))
|
|
.join(" ");
|
|
expect(visibleText).toContain(
|
|
currentThreadId === "source" ? "target conversation" : "source conversation",
|
|
);
|
|
expect(visibleText).toContain(label);
|
|
expect(visibleText).not.toContain("Unknown");
|
|
expect(visibleText).not.toContain("Running");
|
|
}
|
|
},
|
|
);
|