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