From 0e22482251264d0c08ae2bf4e6df0865ed5f3325 Mon Sep 17 00:00:00 2001 From: Shivam Sharma <91240327+shivamhwp@users.noreply.github.com> Date: Wed, 29 Jul 2026 06:48:40 +0530 Subject: [PATCH] fix(web): preserve detachable thread controls Co-Authored-By: Claude --- .../chat/ThreadRelationshipsControl.test.tsx | 106 ++++++++++++------ .../chat/ThreadRelationshipsControl.tsx | 2 +- 2 files changed, 70 insertions(+), 38 deletions(-) diff --git a/apps/web/src/components/chat/ThreadRelationshipsControl.test.tsx b/apps/web/src/components/chat/ThreadRelationshipsControl.test.tsx index 2d4ea8cc1f..60f77ee066 100644 --- a/apps/web/src/components/chat/ThreadRelationshipsControl.test.tsx +++ b/apps/web/src/components/chat/ThreadRelationshipsControl.test.tsx @@ -1,49 +1,81 @@ -import { describe, expect, it } from "vite-plus/test"; +import type { EnvironmentId, ThreadId } from "@t3tools/contracts"; +import type { ReactNode } from "react"; import { renderToStaticMarkup } from "react-dom/server"; +import { beforeEach, describe, expect, it, vi } from "vite-plus/test"; -import { resolveThreadLineageWindow, ThreadLineageRowList } from "./ThreadRelationshipsControl"; +const testState = vi.hoisted(() => ({ + canDetach: false, + relationships: [] as ReadonlyArray, +})); -const rows = Array.from({ length: 20 }, (_, index) => `row-${index}`); +vi.mock("@t3tools/client-runtime/state/thread-relationships", () => ({ + deriveThreadRelationshipGraph: () => ({ nodes: new Map() }), + immediateThreadRelationships: () => testState.relationships, + resolveMergeBackTargetThreadId: () => null, +})); +vi.mock("@t3tools/client-runtime/state/thread-workflows", () => ({ + canDetachThreadProviderSession: () => testState.canDetach, +})); +vi.mock("@tanstack/react-router", () => ({ useNavigate: () => vi.fn() })); +vi.mock("../../lib/archivedThreadsState", () => ({ + useArchivedThreadSnapshots: () => ({ snapshots: [] }), +})); +vi.mock("../../state/entities", () => ({ + useThreadProjection: () => ({ projection: { runs: [] } }), + useThreadShells: () => [], +})); +vi.mock("../../state/threads", () => ({ + threadEnvironment: { + mergeBack: Symbol("mergeBack"), + stopSession: Symbol("stopSession"), + }, +})); +vi.mock("../../state/use-atom-command", () => ({ useAtomCommand: () => vi.fn() })); +vi.mock("../ui/menu", () => ({ + Menu: ({ children }: { readonly children: ReactNode }) => <>{children}, + MenuTrigger: ({ children }: { readonly children: ReactNode }) => <>{children}, + MenuPopup: ({ children }: { readonly children: ReactNode }) => <>{children}, + MenuItem: ({ children }: { readonly children: ReactNode }) => <>{children}, +})); -function renderRowList(visibleCount: number) { - const { visibleRows, hiddenCount } = resolveThreadLineageWindow(rows, visibleCount); - return renderToStaticMarkup( - {}}> - {visibleRows.map((row) => ( -
  • {row}
  • - ))} -
    , +import { ThreadRelationshipsPanel } from "./ThreadRelationshipsControl"; + +const environmentId = "environment:relationships" as EnvironmentId; +const threadId = "thread:relationships" as ThreadId; +const childThreadId = "thread:relationships:subagent" as ThreadId; + +const renderPanel = () => + renderToStaticMarkup( + , ); -} -describe("thread lineage row list", () => { - it("shows six rows before the first expansion", () => { - const { visibleRows, hiddenCount } = resolveThreadLineageWindow(rows, 6); - - expect(visibleRows).toEqual(rows.slice(0, 6)); - expect(hiddenCount).toBe(14); +describe("ThreadRelationshipsPanel", () => { + beforeEach(() => { + testState.canDetach = false; + testState.relationships = [ + { + threadId: childThreadId, + edge: { + kind: "subagent", + sourceThreadId: threadId, + targetThreadId: childThreadId, + status: "running", + }, + }, + ]; }); - it("offers one page at a time", () => { - expect(renderRowList(6)).toContain("Show 12 more"); - expect(renderRowList(6 + 12)).toContain("Show 2 more"); + it("keeps disconnect controls when hidden subagent edges are the only relationships", () => { + testState.canDetach = true; + + const markup = renderPanel(); + + expect(markup).toContain("Lineage"); + expect(markup).toContain("Disconnect agent session"); + expect(markup).not.toContain("Subagent"); }); - it("omits the expansion affordance when everything fits", () => { - const markup = renderRowList(rows.length); - - expect(markup).not.toContain("more"); - expect(resolveThreadLineageWindow(rows.slice(0, 6), 6).hiddenCount).toBe(0); - }); - - it("keeps the rows in a bounded, labelled scroll region and the button outside it", () => { - const markup = renderRowList(6); - const list = /]*)>/.exec(markup)?.[1] ?? ""; - - expect(list).toContain('aria-label="Related threads"'); - expect(list).toContain("max-h-[13.5rem]"); - expect(list).toContain("overflow-y-auto"); - expect(list).toContain("overscroll-contain"); - expect(markup.indexOf("")).toBeLessThan(markup.indexOf(" { + expect(renderPanel()).toBe(""); }); }); diff --git a/apps/web/src/components/chat/ThreadRelationshipsControl.tsx b/apps/web/src/components/chat/ThreadRelationshipsControl.tsx index af1f49ac7b..7c53c8c024 100644 --- a/apps/web/src/components/chat/ThreadRelationshipsControl.tsx +++ b/apps/web/src/components/chat/ThreadRelationshipsControl.tsx @@ -176,7 +176,7 @@ export function ThreadRelationshipsPanel(props: { ); const { visibleRows, hiddenCount } = resolveThreadLineageWindow(relationshipRows, visibleCount); - if (relationshipRows.length === 0) { + if (relationshipRows.length === 0 && !canDetach) { return null; }