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

ThreadRelationshipsControl.agents.browser.test.tsx

1,390 lines46.3 KB

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