Open History to see the last commit
1import "~/index.css";
2import * as DateTime from "effect/DateTime";
3import {
4 EnvironmentId,
5 NodeId,
6 ProviderDriverKind,
7 ProviderInstanceId,
8 ThreadId,
9 type OrchestrationV2ThreadFamily,
10 type OrchestrationV2ThreadProjection,
11 type ServerProvider,
12} from "@t3tools/contracts";
13import * as Cause from "effect/Cause";
14import { AsyncResult } from "effect/reactivity";
15import { expect, it, vi } from "vite-plus/test";
16import { page, userEvent } from "vite-plus/test/browser";
17
18import "~/index.css";
19
20const state = vi.hoisted(() => ({
21 projection: null as unknown,
22 commandSucceeds: false,
23 relatedShells: [] as unknown[],
24 remoteShells: new Map<string, { title: string }>(),
25 connectedEnvironment: null as EnvironmentId | null,
26 family: null as OrchestrationV2ThreadFamily | null,
27 familyQuery: {},
28 providers: new Map<EnvironmentId, ReadonlyArray<ServerProvider>>(),
29 threadTitles: {} as Record<string, string>,
30 archivedThreads: [] as unknown[],
31}));
32
33vi.mock(import("../../state/query"), async (original) => ({
34 ...(await original()),
35 useEnvironmentQuery: ((atom: unknown) =>
36 atom === null
37 ? { data: null, isSuccess: false, isPending: false }
38 : {
39 data: atom === state.familyQuery ? state.family : state.threadTitles,
40 isSuccess: true,
41 isPending: false,
42 }) as never,
43}));
44
45vi.mock(import("../../state/orchestration"), async (original) => {
46 const actual = await original();
47 return {
48 ...actual,
49 orchestrationEnvironment: {
50 ...actual.orchestrationEnvironment,
51 threadFamily: () => state.familyQuery as never,
52 },
53 };
54});
55
56vi.mock(import("@effect/atom-react"), async (original) => ({
57 ...(await original()),
58 useAtomValue: (() => false) as never,
59}));
60
61vi.mock(import("../../state/entities"), () => ({
62 useQuietThreadShell: ((ref: { environmentId: EnvironmentId; threadId: ThreadId } | null) =>
63 ref ? (state.remoteShells.get(`${ref.environmentId}/${ref.threadId}`) ?? null) : null) as never,
64 useQuietThreadProjection: ((ref: unknown) =>
65 ref === null ? null : { projection: state.projection }) as never,
66 useThreadRelationshipShells: (() =>
67 state.projection === null
68 ? []
69 : [(state.projection as { thread: unknown }).thread, ...state.relatedShells]) as never,
70 useProjects: (() => []) as never,
71 useHiddenThreadKeys: (() => new Set()) as never,
72 useAnyEnvironmentHiding: (() => false) as never,
73}));
74vi.mock(import("../../state/environments"), () => ({
75 // The click rule reads the client setting, whose module asks for these.
76 useEnvironments: (() => []) as never,
77 usePrimaryEnvironment: (() => null) as never,
78 useEnvironment: ((id: EnvironmentId | null) =>
79 id !== null && id === state.connectedEnvironment
80 ? { label: "Linked machine", connection: { phase: "connected" } }
81 : null) as never,
82 useEnvironmentProviders: () => state.providers,
83}));
84vi.mock(import("../../state/peerLinks"), () => ({
85 peerLinkEnvironment: { readThread: {} } as never,
86 useLinkedEnvironments: (() => new Map()) as never,
87}));
88vi.mock(import("../../lib/archivedThreadsState"), () => ({
89 useArchivedThreadSnapshots: (() => ({
90 snapshots: [{ environmentId: "environment", snapshot: { threads: state.archivedThreads } }],
91 })) as never,
92}));
93vi.mock(import("../../state/use-atom-command"), () => ({
94 useAtomCommand: (() => async () =>
95 state.commandSucceeds
96 ? AsyncResult.success(undefined)
97 : AsyncResult.failure(Cause.fail(new Error("Connection lost")))) as never,
98}));
99
100import { scopeThreadRef } from "@t3tools/client-runtime/environment";
101
102import { act, fakeTimers, render } from "../../../test/render";
103import { isMacPlatform } from "../../lib/utils";
104import { selectThreadRightPanelState, useRightPanelStore } from "../../rightPanelStore";
105import { makeThreadFixture, makeThreadProjectionFixture } from "../../test-fixtures";
106import { ScrollArea } from "../ui/scroll-area";
107import { ToastProvider } from "../ui/toast";
108import { ThreadRelationshipsPanel } from "./ThreadRelationshipsControl";
109
110const environmentId = EnvironmentId.make("environment");
111const threadId = ThreadId.make("fork");
112
113function setup() {
114 useRightPanelStore.setState(useRightPanelStore.getInitialState());
115 state.commandSucceeds = false;
116 state.relatedShells = [];
117 state.remoteShells.clear();
118 state.connectedEnvironment = null;
119 state.family = null;
120 state.providers = new Map();
121 state.threadTitles = { source: "Source" };
122 state.archivedThreads = [];
123 state.projection = {
124 thread: {
125 id: threadId,
126 title: "Fork",
127 activeProviderThreadId: null,
128 lineage: { parentThreadId: ThreadId.make("source"), relationshipToParent: "fork" },
129 forkedFrom: null,
130 },
131 runs: [{ id: "run", ordinal: 1, status: "completed" }],
132 subagents: [],
133 contextTransfers: [],
134 providerThreads: [],
135 providerSessions: [{ id: "session", status: "ready" }],
136 };
137}
138
139it.each([
140 ["merge", "Could not merge back"],
141 ["disconnect", "Could not disconnect agent session"],
142])("reports a rejected %s command and clears the busy state", async (action, title) => {
143 setup();
144 await using screen = await render(
145 <ToastProvider timeout={0}>
146 <ThreadRelationshipsPanel
147 environmentId={environmentId}
148 threadId={threadId}
149 showLineage
150 showSideChats
151 />
152 </ToastProvider>,
153 );
154
155 if (action === "merge") {
156 await screen.getByRole("button", { name: "Merge back to source conversation" }).click();
157 } else {
158 await screen.getByRole("button", { name: "More thread actions" }).click();
159 await page.getByRole("menuitem", { name: "Disconnect agent session" }).click();
160 }
161
162 await expect.element(page.getByText(title, { exact: true })).toBeVisible();
163 await expect
164 .element(
165 screen.getByRole("button", {
166 name: action === "merge" ? "Merge back to source conversation" : "More thread actions",
167 }),
168 )
169 .toBeEnabled();
170});
171
172it.each([
173 ["merge", "Could not merge back"],
174 ["disconnect", "Could not disconnect agent session"],
175])("clears the previous %s error after a successful retry", async (action, title) => {
176 setup();
177 await using screen = await render(
178 <ToastProvider timeout={0}>
179 <ThreadRelationshipsPanel
180 environmentId={environmentId}
181 threadId={threadId}
182 showLineage
183 showSideChats
184 />
185 </ToastProvider>,
186 { router: "/environment/fork" },
187 );
188
189 const runAction = async () => {
190 if (action === "merge") {
191 await screen.getByRole("button", { name: "Merge back to source conversation" }).click();
192 } else {
193 await screen.getByRole("button", { name: "More thread actions" }).click();
194 await page.getByRole("menuitem", { name: "Disconnect agent session" }).click();
195 }
196 };
197
198 await runAction();
199 await expect.element(page.getByText(title, { exact: true })).toBeVisible();
200 expect(screen.router?.state.location.pathname).toBe("/environment/fork");
201
202 state.commandSucceeds = true;
203 await runAction();
204
205 await expect.element(page.getByText(title, { exact: true })).not.toBeInTheDocument();
206 await vi.waitFor(() => {
207 expect(screen.router?.state.location.pathname).toBe(
208 action === "merge" ? "/environment/source" : "/environment/fork",
209 );
210 });
211 if (action === "disconnect") {
212 await expect.element(screen.getByRole("button", { name: "More thread actions" })).toBeEnabled();
213 }
214});
215
216it("opens an idle child beside the thread, and in its place with the modifier", async () => {
217 setup();
218 const projection = makeThreadProjectionFixture();
219 const childId = ThreadId.make("omitted-child");
220 const environmentId = EnvironmentId.make("local");
221 state.projection = {
222 ...projection,
223 subagents: [
224 {
225 id: NodeId.make("agent"),
226 threadId: projection.thread.id,
227 runId: null,
228 parentNodeId: NodeId.make("parent"),
229 origin: "app_owned",
230 createdBy: "agent",
231 driver: "codex",
232 providerInstanceId: projection.thread.providerInstanceId,
233 providerThreadId: null,
234 childThreadId: childId,
235 nativeTaskRef: null,
236 prompt: "Inspect the change",
237 title: "Idle child",
238 model: null,
239 status: "completed",
240 result: null,
241 startedAt: null,
242 completedAt: projection.thread.updatedAt,
243 updatedAt: projection.thread.updatedAt,
244 },
245 ],
246 };
247 await using screen = await render(
248 <ThreadRelationshipsPanel
249 environmentId={environmentId}
250 threadId={projection.thread.id}
251 showLineage
252 showSideChats
253 />,
254 );
255 await screen.getByRole("button", { name: /Previous agents/ }).click();
256 const child = screen.getByRole("button", { name: /Idle child/ });
257 await expect.element(child).toBeEnabled();
258 const panelRef = scopeThreadRef(environmentId, projection.thread.id);
259 const panel = () =>
260 selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, panelRef);
261 await child.click();
262 expect(panel()).toMatchObject({
263 isOpen: true,
264 activeSurfaceId: "thread:omitted-child",
265 surfaces: [{ kind: "thread", threadId: childId }],
266 });
267 expect(screen.router?.state.location.pathname).toBe("/");
268 // Idle children can be omitted from the shell; the route loads the child's own detail.
269 await child.click({ modifiers: [isMacPlatform(navigator.platform) ? "Meta" : "Control"] });
270 await vi.waitFor(() =>
271 expect(screen.router?.state.location.pathname).toBe("/local/omitted-child"),
272 );
273 expect(panel().surfaces).toHaveLength(1);
274});
275
276it("keeps focus on the list when Show more pages reveal the last rows", async () => {
277 setup();
278 const projection = makeThreadProjectionFixture();
279 const environmentId = EnvironmentId.make("local");
280 const { updatedAt } = projection.thread;
281 state.projection = {
282 ...projection,
283 subagents: Array.from({ length: 7 }, (_, index) => ({
284 id: NodeId.make(`agent-${index}`),
285 threadId: projection.thread.id,
286 runId: null,
287 parentNodeId: NodeId.make("parent"),
288 origin: "app_owned",
289 createdBy: "agent",
290 driver: "codex",
291 providerInstanceId: projection.thread.providerInstanceId,
292 providerThreadId: null,
293 childThreadId: ThreadId.make(`omitted-child-${index}`),
294 nativeTaskRef: null,
295 prompt: `Inspect the change part ${index}`,
296 title: `Agent ${index}`,
297 model: null,
298 status: "completed",
299 result: null,
300 startedAt: null,
301 completedAt: updatedAt,
302 updatedAt,
303 })),
304 };
305 await using screen = await render(
306 <ThreadRelationshipsPanel
307 environmentId={environmentId}
308 threadId={projection.thread.id}
309 showLineage
310 showSideChats
311 />,
312 );
313 await screen.getByRole("button", { name: /Previous agents/ }).click();
314 await screen.getByRole("button", { name: "Show 1 more" }).click();
315 await expect.element(screen.getByRole("list", { name: "Related threads" })).toHaveFocus();
316});
317
318it("shows a lineage thread's full title in its tooltip", async () => {
319 setup();
320 const longTitle = "Compare the lineage tooltip against a title that the row truncates";
321 const sourceThread = {
322 ...(state.projection as { thread: Record<string, unknown> }).thread,
323 id: "source",
324 title: longTitle,
325 lineage: { parentThreadId: null, relationshipToParent: null },
326 };
327 state.relatedShells = [sourceThread];
328 await using _screen = await render(
329 <ThreadRelationshipsPanel
330 environmentId={environmentId}
331 threadId={threadId}
332 showLineage
333 showSideChats={false}
334 />,
335 );
336
337 await userEvent.hover(page.getByText(longTitle, { exact: true }));
338 await vi.waitFor(() =>
339 expect(document.querySelector('[data-slot="tooltip-popup"]')?.textContent).toContain(longTitle),
340 );
341});
342
343it("shows the current Fast mode while a child runs and after its shell is omitted", async () => {
344 setup();
345 const projection = makeThreadProjectionFixture();
346 const childId = ThreadId.make("opus-child");
347 const instanceId = ProviderInstanceId.make("claudeAgent");
348 const model = "claude-opus-5-5";
349 const title = "Opus child";
350 const selection = (fastMode: boolean) => ({
351 instanceId,
352 model,
353 options: [{ id: "fastMode", value: fastMode }],
354 });
355 const provider: ServerProvider = {
356 instanceId,
357 driver: ProviderDriverKind.make("claudeAgent"),
358 enabled: true,
359 installed: true,
360 version: null,
361 status: "ready",
362 auth: { status: "authenticated" },
363 checkedAt: DateTime.formatIso(projection.thread.updatedAt),
364 models: [
365 {
366 slug: model,
367 name: "Opus 5.5",
368 isCustom: false,
369 capabilities: {
370 optionDescriptors: [{ id: "fastMode", label: "Fast", type: "boolean" }],
371 },
372 },
373 ],
374 slashCommands: [],
375 skills: [],
376 };
377 state.providers.set(environmentId, [provider]);
378 const running = {
379 ...projection,
380 subagents: [
381 {
382 id: NodeId.make("agent"),
383 threadId: projection.thread.id,
384 runId: null,
385 parentNodeId: NodeId.make("parent"),
386 childThreadId: childId,
387 providerThreadId: null,
388 nativeTaskRef: null,
389 prompt: "Inspect the change",
390 title,
391 origin: "app_owned",
392 createdBy: "agent",
393 status: "running",
394 driver: provider.driver,
395 providerInstanceId: instanceId,
396 model,
397 modelSelection: selection(false),
398 result: null,
399 startedAt: projection.thread.updatedAt,
400 completedAt: null,
401 updatedAt: projection.thread.updatedAt,
402 },
403 ],
404 } satisfies OrchestrationV2ThreadProjection;
405 state.projection = running;
406 const childShell = (fastMode: boolean) =>
407 makeThreadFixture({
408 id: childId,
409 title,
410 providerInstanceId: instanceId,
411 modelSelection: selection(fastMode),
412 lineage: {
413 parentThreadId: projection.thread.id,
414 rootThreadId: projection.thread.id,
415 relationshipToParent: "subagent",
416 },
417 }).source;
418 const panel = () => (
419 <ThreadRelationshipsPanel
420 environmentId={environmentId}
421 threadId={projection.thread.id}
422 showLineage
423 showSideChats={false}
424 />
425 );
426
427 state.relatedShells = [childShell(true)];
428 await using screen = await render(panel());
429 await userEvent.hover(screen.getByText(title, { exact: true }));
430 const popup = page.getByText("Opus 5.5", { exact: true });
431 const fast = page.getByText("Fast mode on", { exact: true });
432 await expect.element(fast).toBeInTheDocument();
433
434 state.relatedShells = [childShell(false)];
435 await screen.rerender(panel());
436 await expect.element(popup).toBeVisible();
437 await expect.element(fast).not.toBeInTheDocument();
438
439 state.relatedShells = [childShell(true)];
440 await screen.rerender(panel());
441 await expect.element(fast).toBeInTheDocument();
442
443 state.projection = {
444 ...running,
445 subagents: running.subagents.map((agent) => ({
446 ...agent,
447 status: "completed",
448 completedAt: projection.thread.updatedAt,
449 })),
450 } satisfies OrchestrationV2ThreadProjection;
451 state.relatedShells = [];
452 state.family = { snapshotSequence: 1, threads: [childShell(true)] };
453 await screen.rerender(panel());
454 await screen.getByRole("button", { name: /Previous agents/ }).click();
455 await userEvent.hover(screen.getByText(title, { exact: true }));
456 await expect.element(fast).toBeInTheDocument();
457});
458
459it("shows a side chat's full title in its tooltip", async () => {
460 setup();
461 const longTitle = "Side chat question with a title that the side chat row truncates";
462 state.relatedShells = [
463 {
464 id: "side",
465 title: longTitle,
466 lineage: {
467 parentThreadId: threadId,
468 relationshipToParent: "fork",
469 rootThreadId: threadId,
470 sideChat: true,
471 },
472 },
473 ];
474 await using _screen = await render(
475 <ThreadRelationshipsPanel
476 environmentId={environmentId}
477 threadId={threadId}
478 showLineage={false}
479 showSideChats
480 />,
481 );
482
483 await userEvent.hover(page.getByText(longTitle, { exact: true }));
484 await vi.waitFor(() =>
485 expect(document.querySelector('[data-slot="tooltip-popup"]')?.textContent).toContain(longTitle),
486 );
487});
488
489it("shows a remote subagent's current title and falls back when disconnected", async () => {
490 setup();
491 const longTitle = "Investigate a remote subagent issue across linked environments";
492 const remoteEnvId = EnvironmentId.make("remote-env");
493 const remoteThreadId = ThreadId.make("remote-thread");
494 const now = DateTime.makeUnsafe("2026-10-31T20:00:00.000Z");
495 state.projection = {
496 ...(state.projection as Record<string, unknown>),
497 subagents: [
498 {
499 id: NodeId.make("remote-agent"),
500 threadId,
501 runId: null,
502 parentNodeId: NodeId.make("parent"),
503 origin: "app_owned",
504 createdBy: "agent",
505 driver: "codex",
506 providerInstanceId: "provider",
507 providerThreadId: null,
508 childThreadId: null,
509 nativeTaskRef: null,
510 prompt: "Run remote task",
511 title: longTitle,
512 model: null,
513 status: "completed",
514 result: null,
515 startedAt: null,
516 completedAt: null,
517 updatedAt: now,
518 remoteChild: {
519 environmentId: remoteEnvId,
520 threadId: remoteThreadId,
521 label: "Remote VM with a long machine name in the office",
522 },
523 },
524 ],
525 };
526 const panel = () => (
527 <div style={{ width: 320 }}>
528 <ThreadRelationshipsPanel
529 environmentId={environmentId}
530 threadId={threadId}
531 showLineage
532 showSideChats={false}
533 />
534 </div>
535 );
536 await using screen = await render(panel(), { router: "/environment/fork" });
537
538 // A finished remote task sits with the other finished agents, not in its own list.
539 await expect
540 .element(screen.getByRole("button", { name: new RegExp(longTitle) }))
541 .not.toBeInTheDocument();
542 await screen.getByRole("button", { name: /Previous agents/ }).click();
543 const row = screen.getByRole("button", { name: new RegExp(longTitle) });
544 // A long environment label must not squeeze the title out of the row.
545 expect(
546 page.getByText(longTitle, { exact: true }).element().getBoundingClientRect().width,
547 ).toBeGreaterThan(0);
548 await userEvent.hover(row);
549 await vi.waitFor(() =>
550 expect(document.querySelector('[data-slot="tooltip-popup"]')?.textContent).toContain(longTitle),
551 );
552 // This client is not connected there, so the row reads the thread through this environment.
553 expect(document.querySelector('[data-slot="tooltip-popup"]')?.textContent).toContain(
554 "Read the thread on Remote VM with a long machine name in the office",
555 );
556
557 await row.click({ force: true });
558 expect(screen.router?.state.location.pathname).toBe("/environment/fork");
559
560 const renamed = "Renamed remote child";
561 state.connectedEnvironment = remoteEnvId;
562 state.remoteShells.set(`${remoteEnvId}/${remoteThreadId}`, { title: renamed });
563 await screen.rerender(panel());
564 const renamedRow = screen.getByRole("button", { name: new RegExp(renamed) });
565 await expect.element(renamedRow).toBeVisible();
566 await userEvent.hover(screen.getByRole("button", { name: /Previous agents/ }));
567 await userEvent.hover(renamedRow);
568 await vi.waitFor(() =>
569 expect(document.querySelector('[data-slot="tooltip-popup"]')?.textContent).toContain(renamed),
570 );
571
572 state.remoteShells.clear();
573 state.threadTitles[remoteThreadId] = "Renamed idle remote child";
574 await screen.rerender(panel());
575 await expect
576 .element(screen.getByRole("button", { name: /Renamed idle remote child/ }))
577 .toBeVisible();
578});
579
580it("shows how long a running remote subagent has been running, as a local one does", async () => {
581 setup();
582 const remoteTitle = "Remote subagent running on a linked machine";
583 using _timers = fakeTimers();
584 vi.setSystemTime(new Date("2026-11-23T12:12:00.000Z"));
585 const startedAt = DateTime.makeUnsafe("2026-11-23T12:00:00.000Z");
586 state.projection = {
587 ...(state.projection as Record<string, unknown>),
588 subagents: [
589 {
590 id: NodeId.make("remote-agent"),
591 threadId,
592 runId: null,
593 parentNodeId: NodeId.make("parent"),
594 origin: "app_owned",
595 createdBy: "agent",
596 driver: "remote",
597 providerInstanceId: "provider",
598 providerThreadId: null,
599 childThreadId: null,
600 nativeTaskRef: null,
601 prompt: "Run remote task",
602 title: remoteTitle,
603 model: null,
604 status: "running",
605 result: null,
606 startedAt,
607 completedAt: null,
608 updatedAt: startedAt,
609 remoteChild: {
610 environmentId: EnvironmentId.make("remote-env"),
611 threadId: ThreadId.make("remote-thread"),
612 label: "127x05",
613 },
614 },
615 ],
616 };
617 await using screen = await render(
618 <ThreadRelationshipsPanel
619 environmentId={environmentId}
620 threadId={threadId}
621 showLineage
622 showSideChats={false}
623 />,
624 { router: "/environment/fork" },
625 );
626
627 // Assert synchronously: expect.element polls on timers this test fakes.
628 const row = screen.getByRole("button", { name: new RegExp(remoteTitle) });
629 expect(row.element().textContent).toContain("12m");
630});
631
632it("explains why Merge back is unavailable before the fork completes a run", async () => {
633 setup();
634 state.projection = { ...(state.projection as Record<string, unknown>), runs: [] };
635 await using screen = await render(
636 <ThreadRelationshipsPanel
637 environmentId={environmentId}
638 threadId={threadId}
639 showLineage
640 showSideChats={false}
641 />,
642 { router: "/environment/fork" },
643 );
644
645 const mergeBack = screen.getByRole("button", { name: "Merge back to source conversation" });
646 await userEvent.hover(mergeBack);
647 await vi.waitFor(() =>
648 expect(document.querySelector('[data-slot="tooltip-popup"]')?.textContent).toBe(
649 "Complete a run in this fork before merging it back",
650 ),
651 );
652
653 state.commandSucceeds = true;
654 await mergeBack.click({ force: true });
655 expect(screen.router?.state.location.pathname).toBe("/environment/fork");
656});
657
658it("shows a delegated-from thread's full title in its tooltip even when its environment is unavailable", async () => {
659 setup();
660 const longTitle = "Parent task delegated from another machine that has a long description";
661 state.projection = {
662 ...(state.projection as Record<string, unknown>),
663 thread: {
664 ...(state.projection as { thread: Record<string, unknown> }).thread,
665 delegatedFrom: {
666 environmentId: EnvironmentId.make("parent-env"),
667 threadId: ThreadId.make("parent-thread"),
668 title: longTitle,
669 },
670 },
671 };
672 await using screen = await render(
673 <ThreadRelationshipsPanel
674 environmentId={environmentId}
675 threadId={threadId}
676 showLineage
677 showSideChats={false}
678 />,
679 { router: "/environment/fork" },
680 );
681
682 const row = screen.getByRole("button", { name: new RegExp(longTitle) });
683 await userEvent.hover(row);
684 await vi.waitFor(() =>
685 expect(document.querySelector('[data-slot="tooltip-popup"]')?.textContent).toContain(longTitle),
686 );
687 expect(document.querySelector('[data-slot="tooltip-popup"]')?.textContent).toContain(
688 "Delegated from a linked environment. Connect to it to open the parent thread.",
689 );
690
691 await row.click({ force: true });
692 expect(screen.router?.state.location.pathname).toBe("/environment/fork");
693});
694
695it("hides a deleted fork and keeps unloaded and archived forks with their current titles", async () => {
696 setup();
697 const projection = makeThreadProjectionFixture();
698 state.threadTitles = { "unloaded-fork": "Unloaded fork", "archived-fork": "Archived fork" };
699 state.archivedThreads = [
700 {
701 ...projection.thread,
702 id: ThreadId.make("archived-fork"),
703 title: "Old archived title",
704 archivedAt: projection.thread.updatedAt,
705 lineage: { parentThreadId: projection.thread.id, relationshipToParent: "fork" },
706 },
707 ];
708 state.projection = {
709 ...projection,
710 contextTransfers: ["deleted-fork", "unloaded-fork", "archived-fork"].map((id) => ({
711 sourceThreadId: projection.thread.id,
712 targetThreadId: ThreadId.make(id),
713 status: "pending",
714 })),
715 };
716 await using screen = await render(
717 <ThreadRelationshipsPanel
718 environmentId={environmentId}
719 threadId={projection.thread.id}
720 showLineage
721 showSideChats
722 />,
723 );
724 await expect.element(screen.getByText("Unloaded fork", { exact: true })).toBeVisible();
725 await expect.element(screen.getByText("Archived fork", { exact: true })).toBeVisible();
726 await expect.element(screen.getByText("deleted-fork", { exact: true })).not.toBeInTheDocument();
727});
728
729it("shares the hover delay between adjacent lineage rows", async () => {
730 setup();
731 state.relatedShells = [
732 { id: "source", title: "First agent", lineage: { parentThreadId: null } },
733 {
734 id: "child",
735 title: "Second agent",
736 lineage: { parentThreadId: threadId, relationshipToParent: "fork", sideChat: false },
737 },
738 ];
739 await using screen = await render(
740 <ThreadRelationshipsPanel
741 environmentId={environmentId}
742 threadId={threadId}
743 showLineage
744 showSideChats={false}
745 />,
746 );
747 using _timers = fakeTimers();
748 const first = screen.getByRole("button", { name: /^First agent/ });
749 const second = screen.getByRole("button", { name: /^Second agent/ });
750 await userEvent.hover(first);
751 await act(() => vi.advanceTimersByTime(200));
752 expect(first.element()).toHaveAttribute("data-popup-open");
753 await userEvent.hover(second);
754 await act(() => vi.advanceTimersByTime(1));
755 expect(second.element()).toHaveAttribute("data-popup-open");
756});
757
758it.each([1, 18])("continues scrolling the panel past a list of %i subagents", async (count) => {
759 setup();
760 const projection = makeThreadProjectionFixture();
761 state.projection = projection;
762 state.relatedShells = Array.from({ length: count }, (_, index) => ({
763 id: ThreadId.make(`subagent-${index}`),
764 title: `Subagent ${index}`,
765 forkedFrom: null,
766 lineage: { parentThreadId: projection.thread.id, relationshipToParent: "subagent" },
767 activityRunStatus: "running",
768 status: "running",
769 }));
770 await using screen = await render(
771 <div data-testid="panel" style={{ height: 320, width: 280 }}>
772 <ScrollArea>
773 <ThreadRelationshipsPanel
774 environmentId={environmentId}
775 threadId={projection.thread.id}
776 showLineage
777 showSideChats
778 />
779 <div style={{ height: 600 }} />
780 </ScrollArea>
781 </div>,
782 );
783 if (count > 6) {
784 await screen.getByRole("button", { name: "Show 12 more" }).click();
785 await expect.element(screen.getByText("Subagent 17", { exact: true })).toBeInTheDocument();
786 }
787 const list = screen.getByRole("list", { name: "Related threads" }).element();
788 const viewport = screen
789 .getByTestId("panel")
790 .element()
791 .querySelector<HTMLElement>("[data-slot=scroll-area-viewport]")!;
792 list.scrollTop = list.scrollHeight;
793 if (count > 6) expect(list.scrollTop).toBeGreaterThan(0);
794 viewport.scrollTop = 0;
795 await userEvent.wheel(list, { delta: { y: 300 } });
796 await vi.waitFor(() => expect(viewport.scrollTop).toBeGreaterThan(0));
797});