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.configs.set("test", speedConfig);
583 child.modelSelection.options = [{ id: "reasoningEffort", value: "high" }];
584 state.shells = [
585 {
586 environmentId: "test",
587 source: { ...child, modelSelection: { ...child.modelSelection, instanceId: "other" } },
588 },
589 ];
590 await act(async () => renderer.update(cloneElement(panel)));
591 expect(text()).not.toContain("My GPT ·");
592 const config = state.configs.get("test");
593 state.configs.clear();
594 await act(async () => renderer.update(cloneElement(panel)));
595 expect(text()).toContain("GPT-5.4");
596 expect(text()).not.toContain("GPT-5.4 ·");
597 state.shells = [{ environmentId: "test", source: { ...child } }];
598 await act(async () => renderer.update(cloneElement(panel)));
599 expect(text()).toContain("GPT-5.4 · high");
600 state.configs.set("test", config);
601 for (const model of ["custom/model-v1", "custom/model-v2"]) {
602 state.projection = {
603 ...projection,
604 subagents: [{ ...projection.subagents[0], model }],
605 };
606 state.shells = [
607 {
608 environmentId: "test",
609 source: { ...child, modelSelection: { ...child.modelSelection, model: "custom/model-v1" } },
610 },
611 ];
612 await act(async () => renderer.update(cloneElement(panel)));
613 expect(text().includes(`${model} · high`)).toBe(model === "custom/model-v1");
614 }
615
616 state.projection = {
617 ...projection,
618 subagents: [
619 {
620 ...projection.subagents[0],
621 progress: "Checking the latest changes",
622 result: "Old intermediate result",
623 },
624 ],
625 };
626 await act(async () => renderer.update(cloneElement(panel)));
627 expect(text()).toContain("Checking the latest changes");
628 expect(text()).not.toContain("Old intermediate result");
629 const result = "Final checks passed. " + "More detail. ".repeat(50) + "Hidden tail";
630 state.projection = {
631 ...projection,
632 subagents: [
633 { ...projection.subagents[0], status: "failed", progress: "Stale progress", result },
634 ],
635 };
636 await act(async () => renderer.update(cloneElement(panel)));
637 await act(async () =>
638 renderer.root.findByProps({ type: "button", "aria-expanded": false }).props.onClick(),
639 );
640 expect(text()).toContain("Final checks passed.");
641 expect(text()).not.toContain("Stale progress");
642 expect(text()).not.toContain("Hidden tail");
643 expect(text()).not.toContain(result);
644 state.projection = projection;
645
646 child.worktreePath = "/main/worktrees/checker";
647 state.shells = [{ environmentId: "test", source: { ...child } }];
648 await act(async () => renderer.update(cloneElement(panel)));
649 expect(text()).toContain("Worktree");
650 expect(text()).toContain("checker");
651 expect(text()).not.toContain("/main/worktrees");
652 expect(text()).not.toContain("Project");
653
654 child.branch = "fix/checker";
655 state.shells = [{ environmentId: "test", source: { ...child } }];
656 await act(async () => renderer.update(cloneElement(panel)));
657 expect(text()).toContain("Branch");
658 expect(text()).toContain("fix/checker");
659 expect(text()).not.toContain("Worktree");
660 expect(text()).not.toContain("/main/worktrees");
661
662 child.projectId = "other";
663 child.worktreePath = null;
664 child.branch = null;
665 state.shells = [{ environmentId: "test", source: { ...child } }];
666 await act(async () => renderer.update(cloneElement(panel)));
667 expect(text()).toContain("Other project");
668 expect(text()).toContain("Workspace");
669 expect(text()).toContain("other");
670 expect(text()).not.toContain("/other");
671 expect(text()).not.toContain("Wrong environment");
672 expect(text()).not.toContain("Worktree");
673
674 state.shells = [];
675 state.configs.clear();
676 await act(async () => renderer.update(cloneElement(panel)));
677 expect(text()).toContain("GPT-5.4");
678 expect(text()).not.toContain("GPT-5.4 ·");
679 expect(text()).not.toContain("gpt-5.4");
680 expect(text()).not.toContain("Project");
681 expect(text()).not.toContain("Workspace");
682
683 for (const [driver, model, expected] of [
684 ["codex", "gpt-5.3-codex-spark", "GPT-5.3-Codex-Spark"],
685 ["codex", "custom/model-v2", "custom/model-v2"],
686 ["claudeAgent", "gpt-5.4", "GPT-5.4"],
687 ["claudeAgent", "claude-opus-4-6", "Claude Opus 4.6"],
688 ["cursor", "composer-2", "Composer 2"],
689 ["grok", "grok-4-fast", "Grok 4 Fast"],
690 ["antigravity", "gemini-3.8-flash-high", "Gemini 3.8 Flash High"],
691 ["opencode", "anthropic/claude-sonnet-4-6", "anthropic/Claude Sonnet 4.6"],
692 ["codex", null, "Not reported"],
693 ] as const) {
694 state.projection = {
695 ...projection,
696 subagents: [{ ...projection.subagents[0], driver, model }],
697 };
698 await act(async () => renderer.update(cloneElement(panel)));
699 expect(text()).toContain(expected);
700 }
701});
702
703it("shows the parent's own visible status as parent and child activity change", async () => {
704 vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
705 const environmentId = EnvironmentId.make("test");
706 const parent = {
707 id: "parent",
708 title: "Parent conversation",
709 status: "completed",
710 activityRunStatus: "running",
711 lineage: { parentThreadId: null, relationshipToParent: null },
712 };
713 const child = {
714 id: "child",
715 title: "Current fork",
716 status: "completed",
717 lineage: { parentThreadId: "parent", relationshipToParent: "fork" },
718 };
719 state.projection = {
720 thread: { ...child, activeProviderThreadId: null },
721 runs: [],
722 providerThreads: [],
723 providerSessions: [],
724 contextTransfers: [],
725 subagents: [],
726 };
727 const shells = (parentSource: typeof parent, childSource: typeof child) => [
728 { environmentId, source: parentSource },
729 { environmentId, source: childSource },
730 ];
731 state.shells = shells(parent, child);
732 const panel = (
733 <ThreadRelationshipsPanel environmentId={environmentId} threadId={ThreadId.make("child")} />
734 );
735 await act(async () => {
736 renderer = create(panel);
737 });
738 const visibleText = () =>
739 renderer.root
740 .findAll((node) => typeof node.type === "string" && node.props.className !== "sr-only")
741 .flatMap((node) => node.children.filter((child) => typeof child === "string"))
742 .join(" ");
743 expect(visibleText()).toContain("Parent conversation");
744 expect(visibleText()).toContain("Running");
745 state.shells = shells(
746 { ...parent, activityRunStatus: "completed" },
747 { ...child, status: "running" },
748 );
749 await act(async () => renderer.update(cloneElement(panel)));
750 expect(visibleText()).toContain("Done");
751 expect(visibleText()).not.toContain("Running");
752});
753
754it.each(["source", "target"])(
755 "shows transfer lifecycle states when viewing the %s thread",
756 async (currentThreadId) => {
757 vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
758 const environmentId = EnvironmentId.make("test");
759 const threads = ["source", "target"].map((id) => ({
760 id,
761 title: `${id} conversation`,
762 status: "running",
763 activityRunStatus: "running",
764 lineage: { parentThreadId: null, relationshipToParent: null },
765 }));
766 state.shells = threads.map((source) => ({ environmentId, source }));
767 const labels: Record<OrchestrationV2ContextTransfer["status"], string> = {
768 pending: "Queued",
769 resolved_native: "Resolved (native)",
770 resolved_portable: "Resolved (portable)",
771 failed: "Failed",
772 consumed: "Consumed",
773 superseded: "Superseded",
774 };
775 const panel = (
776 <ThreadRelationshipsPanel
777 environmentId={environmentId}
778 threadId={ThreadId.make(currentThreadId)}
779 />
780 );
781 for (const [status, label] of Object.entries(labels)) {
782 state.projection = {
783 thread: {
784 ...threads.find((thread) => thread.id === currentThreadId),
785 activeProviderThreadId: null,
786 },
787 runs: [],
788 providerThreads: [],
789 providerSessions: [],
790 subagents: [],
791 contextTransfers: [{ sourceThreadId: "source", targetThreadId: "target", status }],
792 };
793 await act(async () => {
794 if (status === "pending") renderer = create(panel);
795 else renderer.update(cloneElement(panel));
796 });
797 const visibleText = renderer.root
798 .findAll((node) => typeof node.type === "string")
799 .flatMap((node) => node.children.filter((child) => typeof child === "string"))
800 .join(" ");
801 expect(visibleText).toContain(
802 currentThreadId === "source" ? "target conversation" : "source conversation",
803 );
804 expect(visibleText).toContain(label);
805 expect(visibleText).not.toContain("Unknown");
806 expect(visibleText).not.toContain("Running");
807 }
808 },
809);