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

ThreadRelationshipsControl.agents.test.tsx

1,264 lines43.1 KB

1import { act, cloneElement, type ReactElement, type ReactNode } from "react";
2import { create, type ReactTestInstance, type ReactTestRenderer } from "react-test-renderer";
3import {
4 EnvironmentId,
5 ThreadId,
6 type ModelSelection,
7 type ProviderOptionDescriptor,
8 type OrchestrationV2ContextTransfer,
9} from "@t3tools/contracts";
10import * as DateTime from "effect/DateTime";
11import { afterEach, expect, it, vi } from "vite-plus/test";
12​
13const state = vi.hoisted(() => ({
14 projection: null as unknown,
15 navigate: vi.fn(),
16 shells: [] as unknown[],
17 projects: [] as unknown[],
18 configs: new Map<string, unknown>(),
19 showTooltips: false,
20 command: vi.fn().mockResolvedValue({ _tag: "Success" }),
21 workflowCommand: vi.fn().mockResolvedValue({ _tag: "Success" }),
22 toast: vi.fn(),
23}));
24​
25vi.mock("@tanstack/react-router", () => ({ useNavigate: () => state.navigate }));
26vi.mock("../../state/entities", () => ({
27 useThreadProjection: () => ({ projection: state.projection }),
28 useThreadShells: () => state.shells,
29 useProjects: () => state.projects,
30 useServerConfigs: () => state.configs,
31}));
32vi.mock("../../lib/archivedThreadsState", () => ({
33 useArchivedThreadSnapshots: () => ({ snapshots: [] }),
34}));
35vi.mock("../../state/use-atom-command", () => ({
36 useAtomCommand: (command: { label: string }) =>
37 command.label === "environment-data:orchestration:stop-workflow"
38 ? state.workflowCommand
39 : state.command,
40}));
41vi.mock("../ui/toast", () => ({ toastManager: { add: state.toast } }));
42vi.mock("../../state/orchestration", async () => {
43 const { Atom } = await import("effect/reactivity");
44 const granted = Atom.make(true);
45 return {
46 orchestrationEnvironment: {
47 stopWorkflow: {
48 label: "environment-data:orchestration:stop-workflow",
49 permissionAtom: () => granted,
50 },
51 },
52 };
53});
54vi.mock("../ui/tooltip", () => ({
55 Tooltip: ({ children }: { children: ReactNode }) => children,
56 TooltipTrigger: ({ render, children }: { render: ReactElement; children: ReactNode }) =>
57 cloneElement(render, {}, children),
58 TooltipPopup: ({ children }: { children: ReactNode }) => (state.showTooltips ? children : null),
59}));
60​
61import { ThreadRelationshipsPanel } from "./ThreadRelationshipsControl";
62​
63let renderer: ReactTestRenderer;
64​
65afterEach(async () => {
66 await act(async () => renderer?.unmount());
67 vi.unstubAllGlobals();
68 state.shells = [];
69 state.projects = [];
70 state.configs.clear();
71 state.showTooltips = false;
72 state.navigate.mockClear();
73 state.command.mockClear();
74 state.workflowCommand.mockReset().mockResolvedValue({ _tag: "Success" });
75 state.toast.mockClear();
76 state.projection = null;
77});
78​
79it("stops the entire native workflow through its parent without changing state before acknowledgement", async () => {
80 vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
81 const coordinator = {
82 id: "workflow",
83 origin: "provider_native",
84 driver: "claudeAgent",
85 providerInstanceId: "claude-work",
86 childThreadId: "workflow-chat",
87 title: "Checkout review",
88 status: "running",
89 startedAt: DateTime.makeUnsafe("2026-09-21T12:00:00Z"),
90 completedAt: null,
91 updatedAt: DateTime.makeUnsafe("2026-09-21T12:00:00Z"),
92 workflow: {
93 name: "Checkout review",
94 phases: [{ index: 0, title: "Inspect" }],
95 agents: [{ index: 0, label: "Checker", state: "running", phaseIndex: 0 }],
96 },
97 };
98 state.projection = {
99 thread: { id: "parent", lineage: { relationshipToParent: null } },
100 runs: [],
101 providerThreads: [],
102 providerSessions: [],
103 contextTransfers: [],
104 subagents: [
105 coordinator,
106 {
107 ...coordinator,
108 id: "worker",
109 childThreadId: "worker-chat",
110 origin: "app_owned",
111 title: "Worker",
112 workflow: undefined,
113 },
114 ],
115 };
116 state.shells = [
117 {
118 environmentId: "remote",
119 source: {
120 id: "workflow-chat",
121 title: "Coordinator chat",
122 lineage: { parentThreadId: "parent", relationshipToParent: "subagent" },
123 activityRunStatus: "waiting",
124 },
125 },
126 ];
127 await act(async () => {
128 renderer = create(
129 <ThreadRelationshipsPanel
130 environmentId={EnvironmentId.make("remote")}
131 threadId={ThreadId.make("parent")}
132 />,
133 );
134 });
135 await act(async () =>
136 renderer.root.findByProps({ "aria-label": "Expand Checkout review" }).props.onClick(),
137 );
138 const stopButton = () =>
139 renderer.root.findByProps({ "aria-label": "Stop workflow Checkout review" });
140 expect(
141 renderer.root.findAll(
142 (node) => node.type === "button" && String(node.props["aria-label"]).startsWith("Stop "),
143 ),
144 ).toHaveLength(2);
145 let acknowledge!: (result: { _tag: string }) => void;
146 state.workflowCommand.mockImplementationOnce(
147 () =>
148 new Promise((resolve) => {
149 acknowledge = resolve;
150 }),
151 );
152 await act(async () => {
153 stopButton().props.onClick();
154 });
155 expect(state.workflowCommand).toHaveBeenCalledExactlyOnceWith({
156 environmentId: "remote",
157 input: { threadId: "parent", subagentId: "workflow" },
158 });
159 expect(state.command).not.toHaveBeenCalled();
160 expect(state.navigate).not.toHaveBeenCalled();
161 expect(stopButton().props.disabled).toBe(true);
162 expect(renderer.root.findByProps({ "aria-label": "Stop subagent Worker" }).props.disabled).toBe(
163 true,
164 );
165 expect(renderer.root.findByProps({ "aria-label": "Open Checker chat" })).toBeDefined();
166 expect(renderer.root.findByType("h3").children).toEqual(["Lineage · 2 running"]);
167 await act(async () => {
168 acknowledge({ _tag: "Success" });
169 });
170 expect(stopButton().props.disabled).toBe(false);
171 expect(renderer.root.findByType("h3").children).toEqual(["Lineage · 2 running"]);
172 state.workflowCommand.mockResolvedValueOnce({ _tag: "Failure" });
173 await act(async () => {
174 stopButton().props.onClick();
175 });
176 expect(state.toast).toHaveBeenCalledExactlyOnceWith({
177 type: "error",
178 title: "Could not stop workflow",
179 });
180 expect(stopButton().props.disabled).toBe(false);
181 expect(state.command).not.toHaveBeenCalled();
182 expect(state.navigate).not.toHaveBeenCalled();
183});
184​
185it.each([
186 ["claudeAgent", "provider_native", "completed"],
187 ["claudeAgent", "provider_native", "failed"],
188 ["claudeAgent", "provider_native", "interrupted"],
189 ["claudeAgent", "provider_native", "waiting"],
190 ["codex", "provider_native", "running"],
191 ["claudeAgent", "app_owned", "running"],
192])("does not offer workflow stop for %s %s %s", async (driver, origin, status) => {
193 vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
194 state.projection = {
195 thread: { id: "parent", lineage: { relationshipToParent: null } },
196 runs: [],
197 providerThreads: [],
198 providerSessions: [],
199 contextTransfers: [],
200 subagents: [
201 {
202 id: "workflow",
203 driver,
204 origin,
205 status,
206 providerInstanceId: "claude-work",
207 childThreadId: "workflow-chat",
208 title: "Checkout review",
209 startedAt: DateTime.makeUnsafe("2026-09-21T12:00:00Z"),
210 completedAt: null,
211 updatedAt: DateTime.makeUnsafe("2026-09-21T12:00:00Z"),
212 workflow: { name: "Checkout review", phases: [], agents: [] },
213 },
214 ],
215 };
216 await act(async () => {
217 renderer = create(
218 <ThreadRelationshipsPanel
219 environmentId={EnvironmentId.make("remote")}
220 threadId={ThreadId.make("parent")}
221 />,
222 );
223 });
224 const previousAgents = renderer.root.findAll(
225 (node) =>
226 node.type === "button" && node.props["aria-expanded"] === false && !node.props["aria-label"],
227 );
228 if (previousAgents.length > 0) await act(async () => previousAgents[0]!.props.onClick());
229 expect(renderer.root.findByProps({ "aria-label": "Expand Checkout review" })).toBeDefined();
230 expect(
231 renderer.root.findAllByProps({ "aria-label": "Stop workflow Checkout review" }),
232 ).toHaveLength(0);
233 expect(state.workflowCommand).not.toHaveBeenCalled();
234});
235​
236it("opens the correct chat for every workflow phase and unphased member", async () => {
237 vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
238 state.showTooltips = true;
239 state.configs.set("remote", {
240 providers: [
241 {
242 instanceId: "claude-personal",
243 driver: "claudeAgent",
244 displayName: "Personal account",
245 models: [],
246 },
247 {
248 instanceId: "claude-work",
249 driver: "claudeAgent",
250 displayName: "Work account",
251 models: [{ slug: "claude-sonnet-4-6", name: "Sonnet" }],
252 },
253 ],
254 });
255 const phases = ["Inspect", "Improve", "Verify"].map((title, index) => ({ index, title }));
256 const agents = Array.from({ length: 7 }, (_, index) => ({
257 index,
258 label: `Member ${index}`,
259 state:
260 index === 2 ? "cancelled" : index === 4 ? "failed" : index === 5 ? "running" : "completed",
261 ...(index < 6 ? { phaseIndex: Math.floor(index / 2) } : {}),
262 childThreadId: `member-chat-${index}`,
263 model: "claude-sonnet-4-6",
264 result: `Result ${index}`,
265 totalTokens: 1200,
266 startedAt: 1_700_000_000_000 + index * 1000,
267 durationMs: 5000,
268 }));
269 const project = (members: typeof agents) => ({
270 thread: { id: "parent", lineage: { relationshipToParent: null } },
271 runs: [],
272 providerThreads: [],
273 providerSessions: [],
274 contextTransfers: [],
275 subagents: [
276 {
277 id: "workflow",
278 driver: "claudeAgent",
279 providerInstanceId: "claude-work",
280 childThreadId: "workflow-chat",
281 title: "Checkout review",
282 status: "running",
283 startedAt: null,
284 completedAt: null,
285 updatedAt: DateTime.makeUnsafe("2026-09-21T12:00:00Z"),
286 workflow: { name: "Checkout review", phases, agents: members },
287 },
288 ],
289 });
290 state.projection = project(agents);
291 const memberShells = agents.map((agent) => ({
292 id: agent.childThreadId,
293 title: agent.label,
294 lineage: { parentThreadId: "workflow-chat", relationshipToParent: "subagent" },
295 status: "completed",
296 activityRunStatus: null,
297 }));
298 state.shells = memberShells.map((source) => ({ environmentId: "other", source }));
299 const panel = (
300 <ThreadRelationshipsPanel
301 environmentId={EnvironmentId.make("remote")}
302 threadId={ThreadId.make("parent")}
303 />
304 );
305 await act(async () => {
306 renderer = create(panel);
307 });
308 await act(async () =>
309 renderer.root.findByProps({ "aria-label": "Expand Checkout review" }).props.onClick(),
310 );
311 const memberButtons = () =>
312 renderer.root.findAll(
313 (node) =>
314 node.type === "button" && String(node.props["aria-label"]).startsWith("Open Member"),
315 );
316 const phaseButtons = () =>
317 renderer.root.findAll(
318 (node) =>
319 node.type === "button" &&
320 typeof node.props["aria-expanded"] === "boolean" &&
321 String(node.props["aria-label"]).includes(" phase, "),
322 );
323 expect(memberButtons()).toHaveLength(3);
324 expect(phaseButtons()).toHaveLength(3);
325 expect(renderer.root.findByProps({ "aria-label": "Expand Inspect phase, done" })).toBeDefined();
326 expect(
327 renderer.root.findByProps({ "aria-label": "Expand Improve phase, stopped" }),
328 ).toBeDefined();
329 expect(
330 renderer.root.findByProps({ "aria-label": "Collapse Verify phase, running" }),
331 ).toBeDefined();
332 for (const phase of phaseButtons().slice(0, 2)) await act(async () => phase.props.onClick());
333 expect(memberButtons()).toHaveLength(7);
334 for (const button of memberButtons()) {
335 expect(button.props.disabled).toBe(true);
336 await act(async () => button.props.onClick());
337 }
338 expect(state.navigate).not.toHaveBeenCalled();
339 state.shells = memberShells.map((source) => ({ environmentId: "remote", source }));
340 await act(async () => renderer.update(cloneElement(panel)));
341 for (const button of memberButtons()) expect(button.props.disabled).toBe(false);
342 for (const agent of agents) {
343 await act(async () =>
344 renderer.root.findByProps({ "aria-label": `Open ${agent.label} chat` }).props.onClick(),
345 );
346 expect(state.navigate).toHaveBeenLastCalledWith({
347 to: "/$environmentId/$threadId",
348 params: { environmentId: "remote", threadId: agent.childThreadId },
349 });
350 }
351 const rendered = JSON.stringify(renderer.toJSON());
352 expect(rendered.match(/Sonnet · Work account/g)).toHaveLength(7);
353 expect(rendered).not.toContain("Personal account");
354 for (const phase of phases) expect(rendered).toContain(phase.title);
355 expect(rendered).not.toContain(" phases");
356 expect(rendered).toContain('"1","/","2"," ","agents"');
357 expect(rendered).toContain("Running");
358 expect(rendered).toContain("running");
359 expect(rendered).toContain("done");
360 expect(rendered).toContain("stopped");
361 expect(rendered).toContain('"6s"');
362 for (const phase of phaseButtons()) {
363 const label = String(phase.props["aria-label"]).slice("Collapse ".length);
364 await act(async () => phase.props.onClick());
365 expect(memberButtons()).toHaveLength(5);
366 await act(async () =>
367 renderer.root.findByProps({ "aria-label": `Expand ${label}` }).props.onClick(),
368 );
369 expect(memberButtons()).toHaveLength(7);
370 }
371 await act(async () => phaseButtons()[0]!.props.onClick());
372 expect(memberButtons()).toHaveLength(5);
373 const restarted = agents.map((agent) =>
374 agent.index === 0 ? { ...agent, state: "running" } : agent,
375 );
376 state.projection = project(restarted);
377 await act(async () => renderer.update(cloneElement(panel)));
378 expect(memberButtons()).toHaveLength(5);
379 state.projection = project(agents);
380 await act(async () => renderer.update(cloneElement(panel)));
381 expect(memberButtons()).toHaveLength(5);
382 await act(async () =>
383 renderer.root.findByProps({ "aria-label": "Collapse Checkout review" }).props.onClick(),
384 );
385 expect(memberButtons()).toHaveLength(0);
386 expect(state.navigate).toHaveBeenCalledTimes(7);
387});
388​
389it("groups and counts a workflow by its run status instead of its coordinator chat", async () => {
390 vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
391 state.showTooltips = true;
392 const coordinator = {
393 id: "workflow",
394 driver: "claudeAgent",
395 providerInstanceId: "claudeAgent",
396 childThreadId: "workflow-chat",
397 title: "Checkout review",
398 status: "running",
399 startedAt: DateTime.makeUnsafe("2026-09-21T12:00:00Z"),
400 progress: "Inspecting the checkout workflow",
401 result: "Workflow checks complete",
402 completedAt: null,
403 updatedAt: DateTime.makeUnsafe("2026-09-21T12:00:00Z"),
404 workflow: {
405 name: "Checkout review",
406 phases: [{ index: 0, title: "Inspect" }],
407 agents: [{ index: 0, label: "Checker", state: "running", phaseIndex: 0 }],
408 },
409 };
410 const projection = {
411 thread: { id: "parent", lineage: { relationshipToParent: null } },
412 runs: [],
413 providerThreads: [],
414 providerSessions: [],
415 contextTransfers: [],
416 subagents: [coordinator],
417 };
418 const child = {
419 id: "workflow-chat",
420 title: "Coordinator chat",
421 lineage: { parentThreadId: "parent", relationshipToParent: "subagent" },
422 status: "completed",
423 activityRunStatus: null,
424 };
425 state.projection = projection;
426 state.shells = [{ environmentId: "test", source: child }];
427 const panel = (
428 <ThreadRelationshipsPanel
429 environmentId={EnvironmentId.make("test")}
430 threadId={ThreadId.make("parent")}
431 />
432 );
433 await act(async () => {
434 renderer = create(panel);
435 });
436 const text = () =>
437 renderer.root
438 .findAll((node) => typeof node.type === "string")
439 .flatMap((node) => node.children.filter((child) => typeof child === "string"))
440 .join("");
441 expect(renderer.root.findByType("h3").children).toEqual(["Lineage · 1 running"]);
442 await act(async () =>
443 renderer.root.findByProps({ "aria-label": "Expand Checkout review" }).props.onClick(),
444 );
445 expect(renderer.root.findByProps({ "aria-label": "Open Checker chat" })).toBeDefined();
446 state.shells = [{ environmentId: "test", source: { ...child, activityRunStatus: "waiting" } }];
447 await act(async () => renderer.update(cloneElement(panel)));
448 expect(renderer.root.findByType("h3").children).toEqual(["Lineage · 1 running"]);
449 expect(text()).toContain("Inspecting the checkout workflow");
450 state.projection = {
451 ...projection,
452 subagents: [
453 {
454 ...coordinator,
455 status: "completed",
456 completedAt: DateTime.makeUnsafe("2026-09-21T12:10:00Z"),
457 },
458 ],
459 };
460 await act(async () => renderer.update(cloneElement(panel)));
461 expect(renderer.root.findByType("h3").children).toEqual(["Lineage"]);
462 expect(text()).toContain("Previous agents");
463 expect(renderer.root.findAllByProps({ "aria-label": "Open Checker chat" })).toHaveLength(0);
464 await act(async () =>
465 renderer.root.findByProps({ type: "button", "aria-expanded": false }).props.onClick(),
466 );
467 expect(renderer.root.findByProps({ "aria-label": "Expand Checkout review" })).toBeDefined();
468 expect(text()).toContain("Workflow checks complete");
469 expect(text()).toContain("10m");
470});
471​
472it.each([
473 { driver: "codex", origin: "app_owned", runId: null, canStop: true },
474 { driver: "claudeAgent", origin: "app_owned", runId: null, canStop: true },
475 { driver: "claudeAgent", origin: "provider_native", runId: "run-1", canStop: true },
476 { driver: "claudeAgent", origin: "provider_native", runId: null, canStop: false },
477])(
478 "offers individual Stop for supported $origin $driver subagents with run $runId",
479 async ({ driver, origin, runId, canStop }) => {
480 vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
481 const parent = {
482 id: "parent",
483 lineage: { relationshipToParent: null },
484 activeProviderThreadId: null,
485 };
486 const child = {
487 id: "child",
488 title: "Worker",
489 lineage: { parentThreadId: "parent", relationshipToParent: "subagent" },
490 };
491 const agent = {
492 id: "agent",
493 childThreadId: "child",
494 origin,
495 threadId: "parent",
496 runId,
497 nativeTaskRef: { driver, nativeId: "claude-task", strength: "strong" },
498 driver,
499 providerInstanceId: "codex",
500 title: "Worker",
501 prompt: "Check the change",
502 model: "gpt-5.4",
503 status: "running",
504 progress: null,
505 result: null,
506 startedAt: DateTime.makeUnsafe("2026-09-16T12:00:00Z"),
507 completedAt: null,
508 updatedAt: DateTime.makeUnsafe("2026-09-16T12:00:00Z"),
509 };
510 state.shells = [{ environmentId: "test", source: child }];
511 const projection = {
512 thread: parent,
513 runs: [],
514 providerThreads: [],
515 providerSessions: [],
516 contextTransfers: [],
517 subagents: [agent],
518 };
519 state.projection = projection;
520 const panel = (
521 <ThreadRelationshipsPanel
522 environmentId={EnvironmentId.make("test")}
523 threadId={ThreadId.make("parent")}
524 />
525 );
526 await act(async () => {
527 renderer = create(panel);
528 });
529 if (!canStop) {
530 expect(renderer.root.findAllByProps({ "aria-label": "Stop subagent Worker" })).toHaveLength(
531 0,
532 );
533 return;
534 }
535 const stopButton = () => renderer.root.findByProps({ "aria-label": "Stop subagent Worker" });
536 await act(async () => stopButton().props.onClick());
537 expect(state.command).toHaveBeenCalledWith({
538 environmentId: "test",
539 input:
540 origin === "provider_native"
541 ? { threadId: "parent", subagentId: "agent" }
542 : { threadId: "child" },
543 });
544 expect(state.navigate).not.toHaveBeenCalled();
545​
546 for (const status of ["starting", "running", "waiting"] as const) {
547 state.command.mockClear();
548 state.shells = [
549 {
550 environmentId: "test",
551 source: {
552 ...child,
553 activityRunStatus: status,
554 activityRunStartedAt: DateTime.makeUnsafe("2026-09-16T12:05:00Z"),
555 },
556 },
557 ];
558 state.projection = {
559 ...projection,
560 subagents: [{ ...agent, origin: "provider_native", status: "completed" }],
561 };
562 await act(async () => renderer.update(cloneElement(panel)));
563 expect(renderer.root.findAllByProps({ "aria-label": "Stop subagent Worker" })).toHaveLength(
564 0,
565 );
566 state.projection = { ...projection, subagents: [{ ...agent, status: "completed" }] };
567 await act(async () => renderer.update(cloneElement(panel)));
568 if (origin === "provider_native") {
569 expect(renderer.root.findAllByProps({ "aria-label": "Stop subagent Worker" })).toHaveLength(
570 0,
571 );
572 continue;
573 }
574 await act(async () => stopButton().props.onClick());
575 expect(state.command).toHaveBeenCalledTimes(1);
576 expect(state.command).toHaveBeenLastCalledWith({
577 environmentId: "test",
578 input: { threadId: "child" },
579 });
580 }
581 state.shells = [{ environmentId: "test", source: child }];
582 for (const status of ["completed", "failed", "interrupted"]) {
583 state.projection = { ...projection, subagents: [{ ...agent, status }] };
584 await act(async () => renderer.update(cloneElement(panel)));
585 expect(renderer.root.findAllByProps({ "aria-label": "Stop subagent Worker" })).toHaveLength(
586 0,
587 );
588 }
589 state.projection = { ...projection, subagents: [{ ...agent, startedAt: null }] };
590 await act(async () => renderer.update(cloneElement(panel)));
591 expect(renderer.root.findAllByProps({ "aria-label": "Stop subagent Worker" })).toHaveLength(0);
592 state.projection = {
593 ...projection,
594 subagents: [{ ...agent, origin: "provider_native", driver: "codex" }],
595 };
596 await act(async () => renderer.update(cloneElement(panel)));
597 expect(renderer.root.findAllByProps({ "aria-label": "Stop subagent Worker" })).toHaveLength(0);
598 },
599);
600​
601it("shows the matching child agent details and refreshes them when the agent settles", async () => {
602 vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
603 const agent = {
604 id: "agent-1",
605 driver: "codex",
606 providerInstanceId: "codex",
607 childThreadId: "child-1",
608 title: "Checker",
609 prompt: "Check the change",
610 model: "gpt-5.4",
611 status: "running",
612 progress: "Running checks",
613 result: null,
614 startedAt: DateTime.makeUnsafe("2026-09-16T12:00:00Z"),
615 completedAt: null,
616 updatedAt: DateTime.makeUnsafe("2026-09-16T12:00:00Z"),
617 };
618 const projection = {
619 thread: {
620 id: "parent",
621 lineage: { relationshipToParent: null },
622 activeProviderThreadId: null,
623 },
624 runs: [],
625 providerThreads: [],
626 providerSessions: [],
627 contextTransfers: [],
628 subagents: [
629 { ...agent, id: "unlinked", childThreadId: null, title: "Unlinked agent" },
630 agent,
631 { ...agent, id: "agent-2", childThreadId: "child-2", title: "Worker", model: "gpt-5.3" },
632 ],
633 };
634 state.projection = projection;
635 const panel = (
636 <ThreadRelationshipsPanel
637 environmentId={EnvironmentId.make("test")}
638 threadId={ThreadId.make("parent")}
639 />
640 );
641 await act(async () => {
642 renderer = create(panel);
643 });
644 const text = () =>
645 renderer.root
646 .findAll((node) => typeof node.type === "string")
647 .flatMap((node) => node.children.filter((child) => typeof child === "string"))
648 .join(" ")
649 .replace(/\s+/g, " ");
650 expect(text()).toContain("Checker");
651 expect(text()).toContain("Lineage · 3 running");
652 expect(text()).toContain("running");
653 expect(text()).not.toContain("gpt-5.4");
654 expect(text()).not.toContain("gpt-5.3");
655 expect(text()).not.toContain("tok");
656 expect(text()).not.toContain("Unlinked agent");
657 expect(text()).not.toContain("Active agents");
658 expect(renderer.root.findAllByProps({ type: "button", "aria-expanded": true })).toHaveLength(0);
659​
660 state.projection = {
661 ...projection,
662 subagents: [
663 {
664 ...agent,
665 status: "completed",
666 progress: undefined,
667 result: "All checks passed",
668 completedAt: DateTime.makeUnsafe("2026-09-16T12:02:15Z"),
669 },
670 ],
671 };
672 await act(async () => renderer.update(cloneElement(panel)));
673 expect(renderer.root.findByType("h3").children).toEqual(["Lineage"]);
674 expect(text()).toContain("Previous agents (1)");
675 expect(text()).not.toContain("Checker");
676 await act(async () =>
677 renderer.root.findByProps({ type: "button", "aria-expanded": false }).props.onClick(),
678 );
679 expect(text()).toContain("Checker");
680 expect(text()).toContain("Checker 2m");
681 expect(text()).not.toContain("(1)");
682 expect(text()).not.toContain("Done");
683 expect(text()).not.toContain("running");
684 expect(text()).not.toContain("Worker");
685 await act(async () =>
686 renderer.root.findByProps({ type: "button", "aria-expanded": true }).props.onClick(),
687 );
688 expect(text()).not.toContain("Checker");
689 expect(text()).toContain("Previous agents (1)");
690 await act(async () =>
691 renderer.root.findByProps({ type: "button", "aria-expanded": false }).props.onClick(),
692 );
693 expect(text()).toContain("Checker");
694​
695 state.projection = {
696 ...projection,
697 subagents: Array.from({ length: 8 }, (_, index) => ({
698 ...agent,
699 id: `running-agent-${index}`,
700 childThreadId: `running-child-${index}`,
701 })),
702 };
703 await act(async () => renderer.update(cloneElement(panel)));
704 expect(text()).toContain("Lineage · 8 running");
705​
706 state.projection = {
707 ...projection,
708 subagents: Array.from({ length: 8 }, (_, index) => ({
709 ...agent,
710 id: `old-agent-${index}`,
711 childThreadId: `old-child-${index}`,
712 status: index === 7 ? "failed" : "completed",
713 title: `Old agent ${index}`,
714 result: index === 7 ? "Earlier build failed" : "Done",
715 completedAt: DateTime.makeUnsafe("2026-09-16T12:02:15Z"),
716 })),
717 };
718 await act(async () => renderer.update(cloneElement(panel)));
719 expect(text()).toContain("1 failed");
720 expect(text()).not.toContain("Old agent 7");
721 await act(async () =>
722 renderer.root
723 .findAllByType("button")
724 .find((button) => button.children.includes("Show "))!
725 .props.onClick(),
726 );
727 expect(text()).toContain("Old agent 7");
728​
729 state.projection = {
730 ...projection,
731 subagents: [{ ...agent, childThreadId: null }],
732 };
733 await act(async () => renderer.update(cloneElement(panel)));
734 expect(text()).toContain("Lineage · 1 running");
735});
736​
737it("shows readable models and only differing workspace details in agent tooltips", async () => {
738 vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
739 state.showTooltips = true;
740 const parent = {
741 id: "parent",
742 projectId: "main",
743 worktreePath: null,
744 lineage: {},
745 activeProviderThreadId: null,
746 };
747 const child = {
748 id: "child",
749 projectId: "main",
750 worktreePath: null as string | null,
751 branch: null as string | null,
752 title: "Worker",
753 modelSelection: {
754 instanceId: "codex",
755 model: "gpt-5.4",
756 options: [{ id: "reasoningEffort", value: "high" }] as ModelSelection["options"],
757 },
758 lineage: { parentThreadId: "parent", relationshipToParent: "subagent" },
759 };
760 state.projects = [
761 { id: "main", environmentId: "test", title: "Main", workspaceRoot: "/main" },
762 {
763 id: "other",
764 environmentId: "elsewhere",
765 title: "Wrong environment",
766 workspaceRoot: "/wrong",
767 },
768 { id: "other", environmentId: "test", title: "Other project", workspaceRoot: "/other" },
769 ];
770 state.shells = [{ environmentId: "test", source: child }];
771 state.configs.set("test", {
772 providers: [
773 {
774 instanceId: "codex",
775 driver: "codex",
776 models: [
777 { slug: "gpt-5.4", name: "My GPT model", shortName: "My GPT", aliases: ["model-alias"] },
778 ],
779 },
780 ],
781 });
782 const projection = {
783 thread: parent,
784 runs: [],
785 providerThreads: [],
786 providerSessions: [],
787 contextTransfers: [],
788 subagents: [
789 {
790 id: "agent",
791 childThreadId: "child",
792 origin: "app_owned",
793 driver: "codex",
794 providerInstanceId: "codex",
795 title: "Worker",
796 prompt: "Check",
797 model: "gpt-5.4",
798 status: "pending",
799 startedAt: null,
800 completedAt: null,
801 updatedAt: DateTime.makeUnsafe("2026-09-16T12:00:00Z"),
802 },
803 ],
804 };
805 state.projection = projection;
806 const panel = (
807 <ThreadRelationshipsPanel
808 environmentId={EnvironmentId.make("test")}
809 threadId={ThreadId.make("parent")}
810 />
811 );
812 await act(async () => {
813 renderer = create(panel);
814 });
815 const text = (visibleOnly = false) => {
816 const read = (node: ReactTestInstance | string): string => {
817 if (typeof node === "string") return node;
818 if (visibleOnly && node.props.className === "sr-only") return "";
819 return node.children.map(read).join("");
820 };
821 return read(renderer.root);
822 };
823 const rerender = async (source = child) => {
824 state.shells = [{ environmentId: "test", source: { ...source } }];
825 await act(async () => renderer.update(cloneElement(panel)));
826 };
827 const nativeProjection = {
828 ...projection,
829 subagents: [{ ...projection.subagents[0], origin: "provider_native" }],
830 };
831 expect(text()).toContain("My GPT · high");
832 state.projection = nativeProjection;
833 await act(async () => renderer.update(cloneElement(panel)));
834 expect(text()).toContain("My GPT");
835 expect(text()).not.toContain("My GPT · high");
836 state.projection = projection;
837 await act(async () => renderer.update(cloneElement(panel)));
838 expect(text()).not.toContain("Tokens");
839 expect(text()).not.toContain("Open subagent");
840 expect(text()).not.toContain("Project");
841 expect(text()).not.toContain("Worktree");
842 expect(text()).not.toContain("Workspace");
843​
844 for (const [model, expected] of [
845 [null, "Not reported"],
846 ["", "Not reported"],
847 [" ", "Not reported"],
848 ["model-alias", "My GPT"],
849 ["gpt-5.5", "GPT-5.5"],
850 ["custom/model-v1", "custom/model-v1"],
851 ] as const) {
852 state.projection = {
853 ...projection,
854 subagents: [{ ...projection.subagents[0], model }],
855 };
856 await act(async () => renderer.update(cloneElement(panel)));
857 expect(text()).toContain(expected);
858 if (!model?.trim() || model === "gpt-5.5" || model === "custom/model-v1") {
859 expect(text()).not.toContain(" · high");
860 } else {
861 expect(text()).toContain(`${expected} · high`);
862 }
863 expect(text()).not.toContain("Unknown");
864 if (!model?.trim()) expect(text()).not.toContain("My GPT");
865 }
866​
867 for (const driver of [
868 "codex",
869 "claudeAgent",
870 "cursor",
871 "opencode",
872 "grok",
873 "antigravity",
874 "pi",
875 "acpRegistry",
876 ]) {
877 state.projection = {
878 ...projection,
879 subagents: [{ ...projection.subagents[0], driver, model: null }],
880 };
881 await act(async () => renderer.update(cloneElement(panel)));
882 expect(text()).toContain("Not reported");
883 expect(text()).not.toContain("My GPT");
884 }
885​
886 state.projection = projection;
887 for (const [options, expected] of [
888 [[{ id: "effort", value: "max" }], " · max"],
889 [[{ id: "reasoning", value: "low" }], " · low"],
890 [[{ id: "variant", value: "high" }], " · high"],
891 [[{ id: "reasoningEffort", value: "none" }], " · none"],
892 [[{ id: "reasoningEffort", value: true }], ""],
893 [[{ id: "serviceTier", value: "fast" }], ""],
894 [[], ""],
895 [undefined, ""],
896 ] as const) {
897 child.modelSelection.options = options;
898 await rerender();
899 expect(text()).toContain(`My GPT${expected}`);
900 if (!expected) expect(text()).not.toContain("My GPT ·");
901 }
902 const speedConfig = state.configs.get("test");
903 const serviceTier: ProviderOptionDescriptor = {
904 id: "serviceTier",
905 label: "Service Tier",
906 type: "select",
907 currentValue: "priority",
908 options: [
909 { id: "default", label: "Standard", isDefault: true },
910 { id: "priority", label: "Fast" },
911 { id: "ultrafast", label: "Ultrafast" },
912 { id: "flex", label: "Flex" },
913 ],
914 };
915 const fastMode: ProviderOptionDescriptor = {
916 id: "fastMode",
917 label: "Fast Mode",
918 type: "boolean",
919 currentValue: true,
920 };
921 for (const [driver, descriptor, value, iconLabel] of [
922 ["codex", serviceTier, "default", ""],
923 ["codex", serviceTier, "priority", "Fast mode on"],
924 ["codex", serviceTier, "ultrafast", "Ultrafast mode on"],
925 ["codex", serviceTier, "flex", ""],
926 ["codex", serviceTier, "unknown", ""],
927 [
928 "codex",
929 { ...serviceTier, options: serviceTier.options.filter(({ id }) => id !== "ultrafast") },
930 "ultrafast",
931 "",
932 ],
933 ["codex", serviceTier, true, ""],
934 ["codex", serviceTier, undefined, ""],
935 ["claudeAgent", fastMode, true, "Fast mode on"],
936 ["claudeAgent", fastMode, false, ""],
937 ["cursor", fastMode, true, "Fast mode on"],
938 ["cursor", fastMode, false, ""],
939 ["opencode", fastMode, true, "Fast mode on"],
940 ["cursor", fastMode, "true", ""],
941 ["cursor", serviceTier, "priority", ""],
942 ] as const) {
943 state.configs.set("test", {
944 providers: [
945 {
946 instanceId: "codex",
947 driver,
948 models: [
949 {
950 slug: "gpt-5.4",
951 name: "My GPT",
952 capabilities: { optionDescriptors: [descriptor] },
953 },
954 ],
955 },
956 ],
957 });
958 child.modelSelection.options = [
959 { id: "reasoningEffort", value: "high" },
960 ...(value === undefined ? [] : [{ id: descriptor.id, value }]),
961 ];
962 await rerender();
963 expect(text(true)).toContain("My GPT · high");
964 expect(text(true)).not.toMatch(/Fast|Ultrafast|Normal|Standard|Flex/);
965 expect(text()).toContain(`My GPT · ${iconLabel}high`);
966 if (!iconLabel) expect(text()).not.toContain("mode on");
967 child.modelSelection.options = child.modelSelection.options.filter(
968 ({ id }) => id !== "reasoningEffort",
969 );
970 await rerender();
971 expect(text()).not.toContain(" · high");
972 expect(text(true)).not.toMatch(/Fast|Ultrafast|Normal|Standard|Flex/);
973 if (iconLabel) expect(text()).toContain(iconLabel);
974 else expect(text()).not.toContain("mode on");
975 }
976 state.configs.set("test", {
977 providers: [
978 {
979 instanceId: "codex",
980 driver: "codex",
981 displayName: "Work account",
982 models: [
983 {
984 slug: "gpt-5.4",
985 name: "My GPT",
986 capabilities: { optionDescriptors: [serviceTier] },
987 },
988 ],
989 },
990 {
991 instanceId: "codex_personal",
992 driver: "codex",
993 displayName: "Personal account",
994 models: [],
995 },
996 ],
997 });
998 child.modelSelection.options = [
999 { id: "reasoningEffort", value: "high" },
1000 { id: "serviceTier", value: "priority" },
1001 ];
1002 await rerender();
1003 expect(text(true)).toContain("My GPT · Work account · high");
1004 expect(text()).toContain("My GPT · Work account · Fast mode onhigh");
1005 expect(text()).not.toContain("Personal account");
1006 state.projection = nativeProjection;
1007 await act(async () => renderer.update(cloneElement(panel)));
1008 expect(text()).not.toMatch(/Fast|Ultrafast|Normal|Standard|Flex| · high/);
1009 state.projection = projection;
1010 for (const modelSelection of [
1011 { ...child.modelSelection, instanceId: "other" },
1012 { ...child.modelSelection, model: "gpt-5.5" },
1013 ]) {
1014 await rerender({ ...child, modelSelection });
1015 expect(text()).not.toMatch(/Fast|Ultrafast|Normal|Standard|Flex| · high/);
1017 state.shells = [];
1018 for (const status of ["running", "completed", "failed"] as const) {
1019 state.projection = {
1020 ...projection,
1021 subagents: [
1023 ...projection.subagents[0],
1024 origin: "provider_native",
1025 status,
1026 modelSelection: {
1027 instanceId: "codex",
1028 model: "gpt-5.4",
1029 options: [
1030 { id: "reasoningEffort", value: "low" },
1031 { id: "serviceTier", value: "ultrafast" },
1032 ],
1033 },
1034 },
1035 ],
1036 };
1037 await act(async () => renderer.update(cloneElement(panel)));
1038 if (status === "completed") {
1039 await act(async () =>
1040 renderer.root.findByProps({ type: "button", "aria-expanded": false }).props.onClick(),
1041 );
1043 expect(text()).toContain("My GPT · Work account · Ultrafast mode onlow");
1044 expect(text()).not.toContain(" · high");
1046 await act(async () =>
1047 renderer.root.findByProps({ type: "button", "aria-expanded": true }).props.onClick(),
1048 );
1049 state.projection = projection;
1050 state.configs.set("test", speedConfig);
1051 child.modelSelection.options = [{ id: "reasoningEffort", value: "high" }];
1052 await rerender({ ...child, modelSelection: { ...child.modelSelection, instanceId: "other" } });
1053 expect(text()).not.toContain("My GPT ·");
1054 const config = state.configs.get("test");
1055 state.configs.clear();
1056 await act(async () => renderer.update(cloneElement(panel)));
1057 expect(text()).toContain("GPT-5.4");
1058 expect(text()).not.toContain("GPT-5.4 ·");
1059 await rerender();
1060 expect(text()).toContain("GPT-5.4 · high");
1061 state.configs.set("test", config);
1062 for (const model of ["custom/model-v1", "custom/model-v2"]) {
1063 state.projection = {
1064 ...projection,
1065 subagents: [{ ...projection.subagents[0], model }],
1066 };
1067 await rerender({
1068 ...child,
1069 modelSelection: { ...child.modelSelection, model: "custom/model-v1" },
1070 });
1071 expect(text().includes(`${model} · high`)).toBe(model === "custom/model-v1");
1073​
1074 state.projection = {
1075 ...projection,
1076 subagents: [
1078 ...projection.subagents[0],
1079 progress: "Checking the latest changes",
1080 result: "Old intermediate result",
1081 },
1082 ],
1083 };
1084 await act(async () => renderer.update(cloneElement(panel)));
1085 expect(text()).toContain("Checking the latest changes");
1086 expect(text()).not.toContain("Old intermediate result");
1087 const result = "Final checks passed. " + "More detail. ".repeat(50) + "Hidden tail";
1088 state.projection = {
1089 ...projection,
1090 subagents: [
1091 { ...projection.subagents[0], status: "failed", progress: "Stale progress", result },
1092 ],
1093 };
1094 await act(async () => renderer.update(cloneElement(panel)));
1095 await act(async () =>
1096 renderer.root.findByProps({ type: "button", "aria-expanded": false }).props.onClick(),
1097 );
1098 expect(text()).toContain("Final checks passed.");
1099 expect(text()).not.toContain("Stale progress");
1100 expect(text()).not.toContain("Hidden tail");
1101 expect(text()).not.toContain(result);
1102 state.projection = projection;
1103​
1104 child.worktreePath = "/main/worktrees/checker";
1105 await rerender();
1106 expect(text()).toContain("Worktree");
1107 expect(text()).toContain("checker");
1108 expect(text()).not.toContain("/main/worktrees");
1109 expect(text()).not.toContain("Project");
1110​
1111 child.branch = "fix/checker";
1112 await rerender();
1113 expect(text()).toContain("Branch");
1114 expect(text()).toContain("fix/checker");
1115 expect(text()).not.toContain("Worktree");
1116 expect(text()).not.toContain("/main/worktrees");
1117​
1118 child.projectId = "other";
1119 child.worktreePath = null;
1120 child.branch = null;
1121 await rerender();
1122 expect(text()).toContain("Other project");
1123 expect(text()).toContain("Workspace");
1124 expect(text()).toContain("other");
1125 expect(text()).not.toContain("/other");
1126 expect(text()).not.toContain("Wrong environment");
1127 expect(text()).not.toContain("Worktree");
1128​
1129 state.shells = [];
1130 state.configs.clear();
1131 await act(async () => renderer.update(cloneElement(panel)));
1132 expect(text()).toContain("GPT-5.4");
1133 expect(text()).not.toContain("GPT-5.4 ·");
1134 expect(text()).not.toContain("gpt-5.4");
1135 expect(text()).not.toContain("Project");
1136 expect(text()).not.toContain("Workspace");
1137​
1138 for (const [driver, model, expected] of [
1139 ["codex", "gpt-5.3-codex-spark", "GPT-5.3-Codex-Spark"],
1140 ["codex", "custom/model-v2", "custom/model-v2"],
1141 ["claudeAgent", "gpt-5.4", "GPT-5.4"],
1142 ["claudeAgent", "claude-opus-4-6", "Claude Opus 4.6"],
1143 ["cursor", "composer-2", "Composer 2"],
1144 ["grok", "grok-4-fast", "Grok 4 Fast"],
1145 ["antigravity", "gemini-3.8-flash-high", "Gemini 3.8 Flash High"],
1146 ["opencode", "anthropic/claude-sonnet-4-6", "anthropic/Claude Sonnet 4.6"],
1147 ["codex", null, "Not reported"],
1148 ] as const) {
1149 state.projection = {
1150 ...projection,
1151 subagents: [{ ...projection.subagents[0], driver, model }],
1152 };
1153 await act(async () => renderer.update(cloneElement(panel)));
1154 expect(text()).toContain(expected);
1156});
1157​
1158it("shows the parent's own visible status as parent and child activity change", async () => {
1159 vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
1160 const environmentId = EnvironmentId.make("test");
1161 const parent = {
1162 id: "parent",
1163 title: "Parent conversation",
1164 status: "completed",
1165 activityRunStatus: "running",
1166 lineage: { parentThreadId: null, relationshipToParent: null },
1167 };
1168 const child = {
1169 id: "child",
1170 title: "Current fork",
1171 status: "completed",
1172 lineage: { parentThreadId: "parent", relationshipToParent: "fork" },
1173 };
1174 state.projection = {
1175 thread: { ...child, activeProviderThreadId: null },
1176 runs: [],
1177 providerThreads: [],
1178 providerSessions: [],
1179 contextTransfers: [],
1180 subagents: [],
1181 };
1182 const shells = (parentSource: typeof parent, childSource: typeof child) => [
1183 { environmentId, source: parentSource },
1184 { environmentId, source: childSource },
1185 ];
1186 state.shells = shells(parent, child);
1187 const panel = (
1188 <ThreadRelationshipsPanel environmentId={environmentId} threadId={ThreadId.make("child")} />
1189 );
1190 await act(async () => {
1191 renderer = create(panel);
1192 });
1193 const visibleText = () =>
1194 renderer.root
1195 .findAll((node) => typeof node.type === "string" && node.props.className !== "sr-only")
1196 .flatMap((node) => node.children.filter((child) => typeof child === "string"))
1197 .join(" ");
1198 expect(visibleText()).toContain("Parent conversation");
1199 expect(visibleText()).toContain("Running");
1200 state.shells = shells(
1201 { ...parent, activityRunStatus: "completed" },
1202 { ...child, status: "running" },
1203 );
1204 await act(async () => renderer.update(cloneElement(panel)));
1205 expect(visibleText()).toContain("Done");
1206 expect(visibleText()).not.toContain("Running");
1207});
1208​
1209it.each(["source", "target"])(
1210 "shows transfer lifecycle states when viewing the %s thread",
1211 async (currentThreadId) => {
1212 vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
1213 const environmentId = EnvironmentId.make("test");
1214 const threads = ["source", "target"].map((id) => ({
1215 id,
1216 title: `${id} conversation`,
1217 status: "running",
1218 activityRunStatus: "running",
1219 lineage: { parentThreadId: null, relationshipToParent: null },
1220 }));
1221 state.shells = threads.map((source) => ({ environmentId, source }));
1222 const labels: Record<OrchestrationV2ContextTransfer["status"], string> = {
1223 pending: "Queued",
1224 resolved_native: "Resolved (native)",
1225 resolved_portable: "Resolved (portable)",
1226 failed: "Failed",
1227 consumed: "Consumed",
1228 superseded: "Superseded",
1229 };
1230 const panel = (
1231 <ThreadRelationshipsPanel
1232 environmentId={environmentId}
1233 threadId={ThreadId.make(currentThreadId)}
1234 />
1235 );
1236 for (const [status, label] of Object.entries(labels)) {
1237 state.projection = {
1238 thread: {
1239 ...threads.find((thread) => thread.id === currentThreadId),
1240 activeProviderThreadId: null,
1241 },
1242 runs: [],
1243 providerThreads: [],
1244 providerSessions: [],
1245 subagents: [],
1246 contextTransfers: [{ sourceThreadId: "source", targetThreadId: "target", status }],
1247 };
1248 await act(async () => {
1249 if (status === "pending") renderer = create(panel);
1250 else renderer.update(cloneElement(panel));
1251 });
1252 const visibleText = renderer.root
1253 .findAll((node) => typeof node.type === "string")
1254 .flatMap((node) => node.children.filter((child) => typeof child === "string"))
1255 .join(" ");
1256 expect(visibleText).toContain(
1257 currentThreadId === "source" ? "target conversation" : "source conversation",
1258 );
1259 expect(visibleText).toContain(label);
1260 expect(visibleText).not.toContain("Unknown");
1261 expect(visibleText).not.toContain("Running");
1263 },