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

ThreadRelationshipsControl.agents.test.tsx

857 lines29.2 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}));
22​
23vi.mock("@tanstack/react-router", () => ({ useNavigate: () => state.navigate }));
24vi.mock("../../state/entities", () => ({
25 useThreadProjection: () => ({ projection: state.projection }),
26 useThreadShells: () => state.shells,
27 useProjects: () => state.projects,
28 useServerConfigs: () => state.configs,
29}));
30vi.mock("../../lib/archivedThreadsState", () => ({
31 useArchivedThreadSnapshots: () => ({ snapshots: [] }),
32}));
33vi.mock("../../state/use-atom-command", () => ({ useAtomCommand: () => state.command }));
34vi.mock("../ui/tooltip", () => ({
35 Tooltip: ({ children }: { children: ReactNode }) => children,
36 TooltipTrigger: ({ render, children }: { render: ReactElement; children: ReactNode }) =>
37 cloneElement(render, {}, children),
38 TooltipPopup: ({ children }: { children: ReactNode }) => (state.showTooltips ? children : null),
39}));
40​
41import { ThreadRelationshipsPanel } from "./ThreadRelationshipsControl";
42​
43let renderer: ReactTestRenderer;
44​
45afterEach(async () => {
46 await act(async () => renderer?.unmount());
47 vi.unstubAllGlobals();
48 state.shells = [];
49 state.projects = [];
50 state.configs.clear();
51 state.showTooltips = false;
52 state.command.mockClear();
53 state.projection = null;
54});
55​
56it.each([
57 { driver: "codex", origin: "app_owned" },
58 { driver: "claudeAgent", origin: "app_owned" },
59 { driver: "claudeAgent", origin: "provider_native" },
60])(
61 "stops active $origin $driver subagents without opening their thread",
62 async ({ driver, origin }) => {
63 vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
64 const parent = {
65 id: "parent",
66 lineage: { relationshipToParent: null },
67 activeProviderThreadId: null,
68 };
69 const child = {
70 id: "child",
71 title: "Worker",
72 lineage: { parentThreadId: "parent", relationshipToParent: "subagent" },
73 };
74 const agent = {
75 id: "agent",
76 childThreadId: "child",
77 origin,
78 threadId: "parent",
79 nativeTaskRef: { driver, nativeId: "claude-task", strength: "strong" },
80 driver,
81 providerInstanceId: "codex",
82 title: "Worker",
83 prompt: "Check the change",
84 model: "gpt-5.4",
85 status: "running",
86 progress: null,
87 result: null,
88 startedAt: DateTime.makeUnsafe("2026-09-16T12:00:00Z"),
89 completedAt: null,
90 updatedAt: DateTime.makeUnsafe("2026-09-16T12:00:00Z"),
91 };
92 state.shells = [{ environmentId: "test", source: child }];
93 const projection = {
94 thread: parent,
95 runs: [],
96 providerThreads: [],
97 providerSessions: [],
98 contextTransfers: [],
99 subagents: [agent],
100 };
101 state.projection = projection;
102 const panel = (
103 <ThreadRelationshipsPanel
104 environmentId={EnvironmentId.make("test")}
105 threadId={ThreadId.make("parent")}
106 />
107 );
108 await act(async () => {
109 renderer = create(panel);
110 });
111 const stopButton = () => renderer.root.findByProps({ "aria-label": "Stop subagent Worker" });
112 await act(async () => stopButton().props.onClick());
113 expect(state.command).toHaveBeenCalledWith({
114 environmentId: "test",
115 input:
116 origin === "provider_native"
117 ? { threadId: "parent", subagentId: "agent" }
118 : { threadId: "child" },
119 });
120 expect(state.navigate).not.toHaveBeenCalled();
121​
122 for (const status of ["starting", "running", "waiting"] as const) {
123 state.command.mockClear();
124 state.shells = [
125 {
126 environmentId: "test",
127 source: {
128 ...child,
129 activityRunStatus: status,
130 activityRunStartedAt: DateTime.makeUnsafe("2026-09-16T12:05:00Z"),
131 },
132 },
133 ];
134 state.projection = {
135 ...projection,
136 subagents: [{ ...agent, origin: "provider_native", status: "completed" }],
137 };
138 await act(async () => renderer.update(cloneElement(panel)));
139 expect(renderer.root.findAllByProps({ "aria-label": "Stop subagent Worker" })).toHaveLength(
140 0,
141 );
142 state.projection = { ...projection, subagents: [{ ...agent, status: "completed" }] };
143 await act(async () => renderer.update(cloneElement(panel)));
144 if (origin === "provider_native") {
145 expect(renderer.root.findAllByProps({ "aria-label": "Stop subagent Worker" })).toHaveLength(
146 0,
147 );
148 continue;
149 }
150 await act(async () => stopButton().props.onClick());
151 expect(state.command).toHaveBeenCalledTimes(1);
152 expect(state.command).toHaveBeenLastCalledWith({
153 environmentId: "test",
154 input: { threadId: "child" },
155 });
156 }
157 state.shells = [{ environmentId: "test", source: child }];
158 for (const status of ["completed", "failed", "interrupted"]) {
159 state.projection = { ...projection, subagents: [{ ...agent, status }] };
160 await act(async () => renderer.update(cloneElement(panel)));
161 expect(renderer.root.findAllByProps({ "aria-label": "Stop subagent Worker" })).toHaveLength(
162 0,
163 );
164 }
165 state.projection = { ...projection, subagents: [{ ...agent, startedAt: null }] };
166 await act(async () => renderer.update(cloneElement(panel)));
167 expect(renderer.root.findAllByProps({ "aria-label": "Stop subagent Worker" })).toHaveLength(0);
168 state.projection = {
169 ...projection,
170 subagents: [{ ...agent, origin: "provider_native", driver: "codex" }],
171 };
172 await act(async () => renderer.update(cloneElement(panel)));
173 expect(renderer.root.findAllByProps({ "aria-label": "Stop subagent Worker" })).toHaveLength(0);
174 },
175);
176​
177it("shows the matching child agent details and refreshes them when the agent settles", async () => {
178 vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
179 const agent = {
180 id: "agent-1",
181 driver: "codex",
182 providerInstanceId: "codex",
183 childThreadId: "child-1",
184 title: "Checker",
185 prompt: "Check the change",
186 model: "gpt-5.4",
187 status: "running",
188 progress: "Running checks",
189 result: null,
190 startedAt: DateTime.makeUnsafe("2026-09-16T12:00:00Z"),
191 completedAt: null,
192 updatedAt: DateTime.makeUnsafe("2026-09-16T12:00:00Z"),
193 };
194 const projection = {
195 thread: {
196 id: "parent",
197 lineage: { relationshipToParent: null },
198 activeProviderThreadId: null,
199 },
200 runs: [],
201 providerThreads: [],
202 providerSessions: [],
203 contextTransfers: [],
204 subagents: [
205 { ...agent, id: "unlinked", childThreadId: null, title: "Unlinked agent" },
206 agent,
207 { ...agent, id: "agent-2", childThreadId: "child-2", title: "Worker", model: "gpt-5.3" },
208 ],
209 };
210 state.projection = projection;
211 const panel = (
212 <ThreadRelationshipsPanel
213 environmentId={EnvironmentId.make("test")}
214 threadId={ThreadId.make("parent")}
215 />
216 );
217 await act(async () => {
218 renderer = create(panel);
219 });
220 const text = () =>
221 renderer.root
222 .findAll((node) => typeof node.type === "string")
223 .flatMap((node) => node.children.filter((child) => typeof child === "string"))
224 .join(" ")
225 .replace(/\s+/g, " ");
226 expect(text()).toContain("Checker");
227 expect(text()).toContain("Lineage · 3 running");
228 expect(text()).toContain("running");
229 expect(text()).not.toContain("gpt-5.4");
230 expect(text()).not.toContain("gpt-5.3");
231 expect(text()).not.toContain("tok");
232 expect(text()).not.toContain("Unlinked agent");
233 expect(text()).not.toContain("Active agents");
234 expect(renderer.root.findAllByProps({ type: "button", "aria-expanded": true })).toHaveLength(0);
235​
236 state.projection = {
237 ...projection,
238 subagents: [
239 {
240 ...agent,
241 status: "completed",
242 progress: undefined,
243 result: "All checks passed",
244 completedAt: DateTime.makeUnsafe("2026-09-16T12:02:15Z"),
245 },
246 ],
247 };
248 await act(async () => renderer.update(cloneElement(panel)));
249 expect(renderer.root.findByType("h3").children).toEqual(["Lineage"]);
250 expect(text()).toContain("Previous agents (1)");
251 expect(text()).not.toContain("Checker");
252 await act(async () =>
253 renderer.root.findByProps({ type: "button", "aria-expanded": false }).props.onClick(),
254 );
255 expect(text()).toContain("Checker");
256 // A started agent's row shows only its compact time; the icon carries the status.
257 expect(text()).toContain("Checker 2m");
258 expect(text()).not.toContain("(1)");
259 expect(text()).not.toContain("Done");
260 expect(text()).not.toContain("running");
261 expect(text()).not.toContain("Worker");
262 await act(async () =>
263 renderer.root.findByProps({ type: "button", "aria-expanded": true }).props.onClick(),
264 );
265 expect(text()).not.toContain("Checker");
266 expect(text()).toContain("Previous agents (1)");
267 await act(async () =>
268 renderer.root.findByProps({ type: "button", "aria-expanded": false }).props.onClick(),
269 );
270 expect(text()).toContain("Checker");
271​
272 state.projection = {
273 ...projection,
274 subagents: Array.from({ length: 8 }, (_, index) => ({
275 ...agent,
276 id: `running-agent-${index}`,
277 childThreadId: `running-child-${index}`,
278 })),
279 };
280 await act(async () => renderer.update(cloneElement(panel)));
281 expect(text()).toContain("Lineage · 8 running");
282​
283 state.projection = {
284 ...projection,
285 subagents: Array.from({ length: 8 }, (_, index) => ({
286 ...agent,
287 id: `old-agent-${index}`,
288 childThreadId: `old-child-${index}`,
289 status: index === 7 ? "failed" : "completed",
290 title: `Old agent ${index}`,
291 result: index === 7 ? "Earlier build failed" : "Done",
292 completedAt: DateTime.makeUnsafe("2026-09-16T12:02:15Z"),
293 })),
294 };
295 await act(async () => renderer.update(cloneElement(panel)));
296 expect(text()).toContain("1 failed");
297 expect(text()).not.toContain("Old agent 7");
298 await act(async () =>
299 renderer.root
300 .findAllByType("button")
301 .find((button) => button.children.includes("Show "))!
302 .props.onClick(),
303 );
304 expect(text()).toContain("Old agent 7");
305​
306 state.projection = {
307 ...projection,
308 subagents: [{ ...agent, childThreadId: null }],
309 };
310 await act(async () => renderer.update(cloneElement(panel)));
311 expect(text()).toContain("Lineage · 1 running");
312});
313​
314it("shows readable models and only differing workspace details in agent tooltips", async () => {
315 vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
316 state.showTooltips = true;
317 const parent = {
318 id: "parent",
319 projectId: "main",
320 worktreePath: null,
321 lineage: {},
322 activeProviderThreadId: null,
323 };
324 const child = {
325 id: "child",
326 projectId: "main",
327 worktreePath: null as string | null,
328 branch: null as string | null,
329 title: "Worker",
330 modelSelection: {
331 instanceId: "codex",
332 model: "gpt-5.4",
333 options: [{ id: "reasoningEffort", value: "high" }] as ModelSelection["options"],
334 },
335 lineage: { parentThreadId: "parent", relationshipToParent: "subagent" },
336 };
337 state.projects = [
338 { id: "main", environmentId: "test", title: "Main", workspaceRoot: "/main" },
339 {
340 id: "other",
341 environmentId: "elsewhere",
342 title: "Wrong environment",
343 workspaceRoot: "/wrong",
344 },
345 { id: "other", environmentId: "test", title: "Other project", workspaceRoot: "/other" },
346 ];
347 state.shells = [{ environmentId: "test", source: child }];
348 state.configs.set("test", {
349 providers: [
350 {
351 instanceId: "codex",
352 driver: "codex",
353 models: [
354 { slug: "gpt-5.4", name: "My GPT model", shortName: "My GPT", aliases: ["model-alias"] },
355 ],
356 },
357 ],
358 });
359 const projection = {
360 thread: parent,
361 runs: [],
362 providerThreads: [],
363 providerSessions: [],
364 contextTransfers: [],
365 subagents: [
366 {
367 id: "agent",
368 childThreadId: "child",
369 origin: "app_owned",
370 driver: "codex",
371 providerInstanceId: "codex",
372 title: "Worker",
373 prompt: "Check",
374 model: "gpt-5.4",
375 status: "pending",
376 startedAt: null,
377 completedAt: null,
378 updatedAt: DateTime.makeUnsafe("2026-09-16T12:00:00Z"),
379 },
380 ],
381 };
382 state.projection = projection;
383 const panel = (
384 <ThreadRelationshipsPanel
385 environmentId={EnvironmentId.make("test")}
386 threadId={ThreadId.make("parent")}
387 />
388 );
389 await act(async () => {
390 renderer = create(panel);
391 });
392 const text = (visibleOnly = false) => {
393 const read = (node: ReactTestInstance | string): string => {
394 if (typeof node === "string") return node;
395 if (visibleOnly && node.props.className === "sr-only") return "";
396 return node.children.map(read).join("");
397 };
398 return read(renderer.root);
399 };
400 expect(text()).toContain("My GPT · high");
401 state.projection = {
402 ...projection,
403 subagents: [{ ...projection.subagents[0], origin: "provider_native" }],
404 };
405 await act(async () => renderer.update(cloneElement(panel)));
406 expect(text()).toContain("My GPT");
407 expect(text()).not.toContain("My GPT · high");
408 state.projection = projection;
409 await act(async () => renderer.update(cloneElement(panel)));
410 expect(text()).not.toContain("Tokens");
411 expect(text()).not.toContain("Open subagent");
412 expect(text()).not.toContain("Project");
413 expect(text()).not.toContain("Worktree");
414 expect(text()).not.toContain("Workspace");
415​
416 for (const [model, expected] of [
417 [null, "Not reported"],
418 ["", "Not reported"],
419 [" ", "Not reported"],
420 ["model-alias", "My GPT"],
421 ["gpt-5.5", "GPT-5.5"],
422 ["custom/model-v1", "custom/model-v1"],
423 ] as const) {
424 state.projection = {
425 ...projection,
426 subagents: [{ ...projection.subagents[0], model }],
427 };
428 await act(async () => renderer.update(cloneElement(panel)));
429 expect(text()).toContain(expected);
430 if (!model?.trim() || model === "gpt-5.5" || model === "custom/model-v1") {
431 expect(text()).not.toContain(" · high");
432 } else {
433 expect(text()).toContain(`${expected} · high`);
434 }
435 expect(text()).not.toContain("Unknown");
436 if (!model?.trim()) expect(text()).not.toContain("My GPT");
437 }
438​
439 for (const driver of [
440 "codex",
441 "claudeAgent",
442 "cursor",
443 "opencode",
444 "grok",
445 "antigravity",
446 "pi",
447 "acpRegistry",
448 ]) {
449 state.projection = {
450 ...projection,
451 subagents: [{ ...projection.subagents[0], driver, model: null }],
452 };
453 await act(async () => renderer.update(cloneElement(panel)));
454 expect(text()).toContain("Not reported");
455 expect(text()).not.toContain("My GPT");
456 }
457​
458 state.projection = projection;
459 for (const [options, expected] of [
460 [[{ id: "effort", value: "max" }], " · max"],
461 [[{ id: "reasoning", value: "low" }], " · low"],
462 [[{ id: "variant", value: "high" }], " · high"],
463 [[{ id: "reasoningEffort", value: "none" }], " · none"],
464 [[{ id: "reasoningEffort", value: true }], ""],
465 [[{ id: "serviceTier", value: "fast" }], ""],
466 [[], ""],
467 [undefined, ""],
468 ] as const) {
469 child.modelSelection.options = options;
470 state.shells = [{ environmentId: "test", source: { ...child } }];
471 await act(async () => renderer.update(cloneElement(panel)));
472 expect(text()).toContain(`My GPT${expected}`);
473 if (!expected) expect(text()).not.toContain("My GPT ·");
474 }
475 const speedConfig = state.configs.get("test");
476 const serviceTier: ProviderOptionDescriptor = {
477 id: "serviceTier",
478 label: "Service Tier",
479 type: "select",
480 currentValue: "priority",
481 options: [
482 { id: "default", label: "Standard", isDefault: true },
483 { id: "priority", label: "Fast" },
484 { id: "ultrafast", label: "Ultrafast" },
485 { id: "flex", label: "Flex" },
486 ],
487 };
488 const fastMode: ProviderOptionDescriptor = {
489 id: "fastMode",
490 label: "Fast Mode",
491 type: "boolean",
492 currentValue: true,
493 };
494 for (const [driver, descriptor, value, iconLabel] of [
495 ["codex", serviceTier, "default", ""],
496 ["codex", serviceTier, "priority", "Fast mode on"],
497 ["codex", serviceTier, "ultrafast", "Ultrafast mode on"],
498 ["codex", serviceTier, "flex", ""],
499 ["codex", serviceTier, "unknown", ""],
500 [
501 "codex",
502 { ...serviceTier, options: serviceTier.options.filter(({ id }) => id !== "ultrafast") },
503 "ultrafast",
504 "",
505 ],
506 ["codex", serviceTier, true, ""],
507 ["codex", serviceTier, undefined, ""],
508 ["claudeAgent", fastMode, true, "Fast mode on"],
509 ["claudeAgent", fastMode, false, ""],
510 ["cursor", fastMode, true, "Fast mode on"],
511 ["cursor", fastMode, false, ""],
512 ["opencode", fastMode, true, "Fast mode on"],
513 ["cursor", fastMode, "true", ""],
514 ["cursor", serviceTier, "priority", ""],
515 ] as const) {
516 state.configs.set("test", {
517 providers: [
518 {
519 instanceId: "codex",
520 driver,
521 models: [
522 {
523 slug: "gpt-5.4",
524 name: "My GPT",
525 capabilities: { optionDescriptors: [descriptor] },
526 },
527 ],
528 },
529 ],
530 });
531 child.modelSelection.options = [
532 { id: "reasoningEffort", value: "high" },
533 ...(value === undefined ? [] : [{ id: descriptor.id, value }]),
534 ];
535 state.shells = [{ environmentId: "test", source: { ...child } }];
536 await act(async () => renderer.update(cloneElement(panel)));
537 expect(text(true)).toContain("My GPT · high");
538 expect(text(true)).not.toMatch(/Fast|Ultrafast|Normal|Standard|Flex/);
539 expect(text()).toContain(`My GPT · ${iconLabel}high`);
540 if (!iconLabel) expect(text()).not.toContain("mode on");
541 child.modelSelection.options = child.modelSelection.options.filter(
542 ({ id }) => id !== "reasoningEffort",
543 );
544 state.shells = [{ environmentId: "test", source: { ...child } }];
545 await act(async () => renderer.update(cloneElement(panel)));
546 expect(text()).not.toContain(" · high");
547 expect(text(true)).not.toMatch(/Fast|Ultrafast|Normal|Standard|Flex/);
548 if (iconLabel) expect(text()).toContain(iconLabel);
549 else expect(text()).not.toContain("mode on");
550 state.projection = {
551 ...projection,
552 subagents: [{ ...projection.subagents[0], origin: "provider_native" }],
553 };
554 await act(async () => renderer.update(cloneElement(panel)));
555 expect(text()).not.toMatch(/Fast|Ultrafast|Normal|Standard|Flex| · high/);
556 state.projection = projection;
557 for (const modelSelection of [
558 { ...child.modelSelection, instanceId: "other" },
559 { ...child.modelSelection, model: "gpt-5.5" },
560 ]) {
561 state.shells = [{ environmentId: "test", source: { ...child, modelSelection } }];
562 await act(async () => renderer.update(cloneElement(panel)));
563 expect(text()).not.toMatch(/Fast|Ultrafast|Normal|Standard|Flex| · high/);
564 }
565 }
566 state.configs.set("test", {
567 providers: [
568 {
569 instanceId: "codex",
570 driver: "codex",
571 displayName: "Work account",
572 models: [
573 {
574 slug: "gpt-5.4",
575 name: "My GPT",
576 capabilities: { optionDescriptors: [serviceTier] },
577 },
578 ],
579 },
580 {
581 instanceId: "codex_personal",
582 driver: "codex",
583 displayName: "Personal account",
584 models: [],
585 },
586 ],
587 });
588 child.modelSelection.options = [
589 { id: "reasoningEffort", value: "high" },
590 { id: "serviceTier", value: "priority" },
591 ];
592 state.shells = [{ environmentId: "test", source: { ...child } }];
593 await act(async () => renderer.update(cloneElement(panel)));
594 expect(text(true)).toContain("My GPT · Work account · high");
595 expect(text()).toContain("My GPT · Work account · Fast mode onhigh");
596 expect(text()).not.toContain("Personal account");
597 state.shells = [];
598 for (const status of ["running", "completed", "failed"] as const) {
599 state.projection = {
600 ...projection,
601 subagents: [
602 {
603 ...projection.subagents[0],
604 origin: "provider_native",
605 status,
606 modelSelection: {
607 instanceId: "codex",
608 model: "gpt-5.4",
609 options: [
610 { id: "reasoningEffort", value: "low" },
611 { id: "serviceTier", value: "ultrafast" },
612 ],
613 },
614 },
615 ],
616 };
617 await act(async () => renderer.update(cloneElement(panel)));
618 if (status === "completed") {
619 await act(async () =>
620 renderer.root.findByProps({ type: "button", "aria-expanded": false }).props.onClick(),
621 );
622 }
623 expect(text()).toContain("My GPT · Work account · Ultrafast mode onlow");
624 expect(text()).not.toContain(" · high");
625 }
626 await act(async () =>
627 renderer.root.findByProps({ type: "button", "aria-expanded": true }).props.onClick(),
628 );
629 state.projection = projection;
630 state.configs.set("test", speedConfig);
631 child.modelSelection.options = [{ id: "reasoningEffort", value: "high" }];
632 state.shells = [
633 {
634 environmentId: "test",
635 source: { ...child, modelSelection: { ...child.modelSelection, instanceId: "other" } },
636 },
637 ];
638 await act(async () => renderer.update(cloneElement(panel)));
639 expect(text()).not.toContain("My GPT ·");
640 const config = state.configs.get("test");
641 state.configs.clear();
642 await act(async () => renderer.update(cloneElement(panel)));
643 expect(text()).toContain("GPT-5.4");
644 expect(text()).not.toContain("GPT-5.4 ·");
645 state.shells = [{ environmentId: "test", source: { ...child } }];
646 await act(async () => renderer.update(cloneElement(panel)));
647 expect(text()).toContain("GPT-5.4 · high");
648 state.configs.set("test", config);
649 for (const model of ["custom/model-v1", "custom/model-v2"]) {
650 state.projection = {
651 ...projection,
652 subagents: [{ ...projection.subagents[0], model }],
653 };
654 state.shells = [
655 {
656 environmentId: "test",
657 source: { ...child, modelSelection: { ...child.modelSelection, model: "custom/model-v1" } },
658 },
659 ];
660 await act(async () => renderer.update(cloneElement(panel)));
661 expect(text().includes(`${model} · high`)).toBe(model === "custom/model-v1");
662 }
663​
664 state.projection = {
665 ...projection,
666 subagents: [
667 {
668 ...projection.subagents[0],
669 progress: "Checking the latest changes",
670 result: "Old intermediate result",
671 },
672 ],
673 };
674 await act(async () => renderer.update(cloneElement(panel)));
675 expect(text()).toContain("Checking the latest changes");
676 expect(text()).not.toContain("Old intermediate result");
677 const result = "Final checks passed. " + "More detail. ".repeat(50) + "Hidden tail";
678 state.projection = {
679 ...projection,
680 subagents: [
681 { ...projection.subagents[0], status: "failed", progress: "Stale progress", result },
682 ],
683 };
684 await act(async () => renderer.update(cloneElement(panel)));
685 await act(async () =>
686 renderer.root.findByProps({ type: "button", "aria-expanded": false }).props.onClick(),
687 );
688 expect(text()).toContain("Final checks passed.");
689 expect(text()).not.toContain("Stale progress");
690 expect(text()).not.toContain("Hidden tail");
691 expect(text()).not.toContain(result);
692 state.projection = projection;
693​
694 child.worktreePath = "/main/worktrees/checker";
695 state.shells = [{ environmentId: "test", source: { ...child } }];
696 await act(async () => renderer.update(cloneElement(panel)));
697 expect(text()).toContain("Worktree");
698 expect(text()).toContain("checker");
699 expect(text()).not.toContain("/main/worktrees");
700 expect(text()).not.toContain("Project");
701​
702 child.branch = "fix/checker";
703 state.shells = [{ environmentId: "test", source: { ...child } }];
704 await act(async () => renderer.update(cloneElement(panel)));
705 expect(text()).toContain("Branch");
706 expect(text()).toContain("fix/checker");
707 expect(text()).not.toContain("Worktree");
708 expect(text()).not.toContain("/main/worktrees");
709​
710 child.projectId = "other";
711 child.worktreePath = null;
712 child.branch = null;
713 state.shells = [{ environmentId: "test", source: { ...child } }];
714 await act(async () => renderer.update(cloneElement(panel)));
715 expect(text()).toContain("Other project");
716 expect(text()).toContain("Workspace");
717 expect(text()).toContain("other");
718 expect(text()).not.toContain("/other");
719 expect(text()).not.toContain("Wrong environment");
720 expect(text()).not.toContain("Worktree");
721​
722 state.shells = [];
723 state.configs.clear();
724 await act(async () => renderer.update(cloneElement(panel)));
725 expect(text()).toContain("GPT-5.4");
726 expect(text()).not.toContain("GPT-5.4 ·");
727 expect(text()).not.toContain("gpt-5.4");
728 expect(text()).not.toContain("Project");
729 expect(text()).not.toContain("Workspace");
730​
731 for (const [driver, model, expected] of [
732 ["codex", "gpt-5.3-codex-spark", "GPT-5.3-Codex-Spark"],
733 ["codex", "custom/model-v2", "custom/model-v2"],
734 ["claudeAgent", "gpt-5.4", "GPT-5.4"],
735 ["claudeAgent", "claude-opus-4-6", "Claude Opus 4.6"],
736 ["cursor", "composer-2", "Composer 2"],
737 ["grok", "grok-4-fast", "Grok 4 Fast"],
738 ["antigravity", "gemini-3.8-flash-high", "Gemini 3.8 Flash High"],
739 ["opencode", "anthropic/claude-sonnet-4-6", "anthropic/Claude Sonnet 4.6"],
740 ["codex", null, "Not reported"],
741 ] as const) {
742 state.projection = {
743 ...projection,
744 subagents: [{ ...projection.subagents[0], driver, model }],
745 };
746 await act(async () => renderer.update(cloneElement(panel)));
747 expect(text()).toContain(expected);
748 }
749});
750​
751it("shows the parent's own visible status as parent and child activity change", async () => {
752 vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
753 const environmentId = EnvironmentId.make("test");
754 const parent = {
755 id: "parent",
756 title: "Parent conversation",
757 status: "completed",
758 activityRunStatus: "running",
759 lineage: { parentThreadId: null, relationshipToParent: null },
760 };
761 const child = {
762 id: "child",
763 title: "Current fork",
764 status: "completed",
765 lineage: { parentThreadId: "parent", relationshipToParent: "fork" },
766 };
767 state.projection = {
768 thread: { ...child, activeProviderThreadId: null },
769 runs: [],
770 providerThreads: [],
771 providerSessions: [],
772 contextTransfers: [],
773 subagents: [],
774 };
775 const shells = (parentSource: typeof parent, childSource: typeof child) => [
776 { environmentId, source: parentSource },
777 { environmentId, source: childSource },
778 ];
779 state.shells = shells(parent, child);
780 const panel = (
781 <ThreadRelationshipsPanel environmentId={environmentId} threadId={ThreadId.make("child")} />
782 );
783 await act(async () => {
784 renderer = create(panel);
785 });
786 const visibleText = () =>
787 renderer.root
788 .findAll((node) => typeof node.type === "string" && node.props.className !== "sr-only")
789 .flatMap((node) => node.children.filter((child) => typeof child === "string"))
790 .join(" ");
791 expect(visibleText()).toContain("Parent conversation");
792 expect(visibleText()).toContain("Running");
793 state.shells = shells(
794 { ...parent, activityRunStatus: "completed" },
795 { ...child, status: "running" },
796 );
797 await act(async () => renderer.update(cloneElement(panel)));
798 expect(visibleText()).toContain("Done");
799 expect(visibleText()).not.toContain("Running");
800});
801​
802it.each(["source", "target"])(
803 "shows transfer lifecycle states when viewing the %s thread",
804 async (currentThreadId) => {
805 vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
806 const environmentId = EnvironmentId.make("test");
807 const threads = ["source", "target"].map((id) => ({
808 id,
809 title: `${id} conversation`,
810 status: "running",
811 activityRunStatus: "running",
812 lineage: { parentThreadId: null, relationshipToParent: null },
813 }));
814 state.shells = threads.map((source) => ({ environmentId, source }));
815 const labels: Record<OrchestrationV2ContextTransfer["status"], string> = {
816 pending: "Queued",
817 resolved_native: "Resolved (native)",
818 resolved_portable: "Resolved (portable)",
819 failed: "Failed",
820 consumed: "Consumed",
821 superseded: "Superseded",
822 };
823 const panel = (
824 <ThreadRelationshipsPanel
825 environmentId={environmentId}
826 threadId={ThreadId.make(currentThreadId)}
827 />
828 );
829 for (const [status, label] of Object.entries(labels)) {
830 state.projection = {
831 thread: {
832 ...threads.find((thread) => thread.id === currentThreadId),
833 activeProviderThreadId: null,
834 },
835 runs: [],
836 providerThreads: [],
837 providerSessions: [],
838 subagents: [],
839 contextTransfers: [{ sourceThreadId: "source", targetThreadId: "target", status }],
840 };
841 await act(async () => {
842 if (status === "pending") renderer = create(panel);
843 else renderer.update(cloneElement(panel));
844 });
845 const visibleText = renderer.root
846 .findAll((node) => typeof node.type === "string")
847 .flatMap((node) => node.children.filter((child) => typeof child === "string"))
848 .join(" ");
849 expect(visibleText).toContain(
850 currentThreadId === "source" ? "target conversation" : "source conversation",
851 );
852 expect(visibleText).toContain(label);
853 expect(visibleText).not.toContain("Unknown");
854 expect(visibleText).not.toContain("Running");
855 }
856 },
857);