Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
207 changes: 206 additions & 1 deletion apps/web/src/components/ChatView.browser.test.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { ThreadInspectionContext } from "./chat/ThreadInspectionContext";
import { ThreadPanelHostContext } from "./chat/ThreadPanelHostContext";
import { BoardTaskContext } from "./delivery/BoardTaskContext";
import { parseTask } from "~/lib/delivery";
import { createMemoryHistory } from "@tanstack/react-router";
import { scopeProjectRef, scopeThreadRef } from "@t3tools/client-runtime/environment";
import {
EnvironmentId,
NodeId,
IssueTrackerKind,
ORCHESTRATION_V2_WS_METHODS,
ProjectId,
ProviderDriverKind,
ProviderInstanceId,
RunId,
Expand Down Expand Up @@ -35,10 +39,12 @@ import { __setClientSettingsForTests } from "~/hooks/useSettings";
import stylesheet from "~/index.css?inline";
import { environmentContextRecord } from "~/lib/composerContextRecords";
import { startWorkspaceFocus } from "~/lib/workspaceFocus";
import { usePreviewMiniPlayerStore } from "~/previewMiniPlayerStore";
import { usePromptStashStore } from "~/promptStashStore";
import { useRightPanelStore } from "~/rightPanelStore";
import { selectThreadRightPanelState, useRightPanelStore } from "~/rightPanelStore";
import { getRouter } from "~/router";
import { appAtomRegistry } from "~/rpc/atomRegistry";
import { environmentShell } from "~/state/shell";
import { environmentThreadDetails } from "~/state/threads";
import {
ENVIRONMENT_ID,
Expand Down Expand Up @@ -930,6 +936,205 @@ it("opens a timeline parent through the containing workspace", async () => {
expect(router.state.location.pathname).toBe(path);
});

/** The board task a task's view provides to what it hosts. */
const boardTask = () => ({
environmentId: null,
taskId: "t7",
task: parseTask({
id: "t7",
number: 7,
title: "Fix the sync",
body: "Make the sync stop dropping rows.",
state: "ready",
lane: "ready",
card: { id: "t7", number: 7, title: "Fix the sync", lane: "ready" },
}),
stale: false,
refresh: () => {},
openTask: () => {},
openThread: () => {},
seats: { thread: () => null, current: null, open: () => {} },
});

it("a thread a board task's view shows in its own thread's place keeps the task's panels", async () => {
await page.viewport(1400, 900);
const lead = threadWithHistory("task-lead", 1);
const seat = threadWithHistory("task-seat", 1);
using _environment = installFakeEnvironment([lead, seat]);
__setClientSettingsForTests({
...DEFAULT_CLIENT_SETTINGS,
onboardingCompletedAt: "2026-01-01T00:00:00.000Z",
});
const leadRef = scopeThreadRef(ENVIRONMENT_ID, lead.id);
// The task's tabs and its details are open on the task thread's panels; the seat's are empty.
useRightPanelStore.getState().open(leadRef, "task-evidence");
useRightPanelStore.getState().setThreadPanelOpen(leadRef, "inline", true);
const router = getRouter(
createMemoryHistory({ initialEntries: [`/${ENVIRONMENT_ID}/${seat.id}`] }),
);
await router.load();
await using screen = await render(
<BoardTaskContext value={boardTask()}>
<ThreadPanelHostContext value={leadRef}>
<AppRoot router={router} />
</ThreadPanelHostContext>
</BoardTaskContext>,
{
// AppRoot brings its own router.
router: false,
},
);
await expect
.element(screen.getByRole("textbox", { name: `Message ${seat.title}`, exact: true }))
.toBeVisible();
// The right panel is the task thread's, with the task's evidence in it.
await expect
.element(screen.getByRole("button", { name: "Task evidence", exact: true }))
.toBeVisible();
await expect.element(screen.getByText("Execution and checkpoints")).toBeVisible();
// So are the details, whose Task item reads the board's task.
const taskItem = page.getByRole("region", { name: "Task", exact: true });
await expect.element(taskItem.getByText("Make the sync stop dropping rows.")).toBeVisible();
});

it("a board task's thread opened by its own route keeps the task's tabs saved for its task view, out of sight", async () => {
await page.viewport(1400, 900);
const lead = threadWithHistory("task-own-route", 1);
using _environment = installFakeEnvironment([lead]);
__setClientSettingsForTests({
...DEFAULT_CLIENT_SETTINGS,
onboardingCompletedAt: "2026-01-01T00:00:00.000Z",
});
const leadRef = scopeThreadRef(ENVIRONMENT_ID, lead.id);
useRightPanelStore.getState().open(leadRef, "task-evidence");
const router = getRouter(
createMemoryHistory({ initialEntries: [`/${ENVIRONMENT_ID}/${lead.id}`] }),
);
await router.load();
const app = (board: ReturnType<typeof boardTask> | null) => (
<BoardTaskContext value={board}>
<AppRoot router={router} />
</BoardTaskContext>
);
await using screen = await render(app(null), {
// AppRoot brings its own router.
router: false,
});
await expect
.element(screen.getByRole("textbox", { name: `Message ${lead.title}`, exact: true }))
.toBeVisible();
// With no board task around it, the panel is the thread's own: no task tab, and none offered.
await expect.element(screen.getByText("Open a surface")).toBeVisible();
await expect.element(screen.getByText("Task evidence")).not.toBeInTheDocument();
expect(
selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, leadRef).surfaces,
).toEqual([{ id: "task-evidence", kind: "task-evidence" }]);
await screen.rerender(app(boardTask()));
await expect
.element(screen.getByRole("button", { name: "Task evidence", exact: true }))
.toBeVisible();
});

it("a thread without the task's project, shown in a board task's view, leaves the task's file tabs alone", async () => {
await page.viewport(1400, 900);
const lead = threadWithHistory("task-files-lead", 1);
// The conversation the task was filed from, in a project this environment does not have.
const source = {
...threadWithHistory("task-files-source", 1),
projectId: ProjectId.make("project-elsewhere"),
};
using _environment = installFakeEnvironment([lead, source]);
__setClientSettingsForTests({
...DEFAULT_CLIENT_SETTINGS,
onboardingCompletedAt: "2026-01-01T00:00:00.000Z",
});
const leadRef = scopeThreadRef(ENVIRONMENT_ID, lead.id);
useRightPanelStore.getState().open(leadRef, "files");
useRightPanelStore.getState().open(leadRef, "task-evidence");
const router = getRouter(
createMemoryHistory({ initialEntries: [`/${ENVIRONMENT_ID}/${source.id}`] }),
);
await router.load();
const hosted = () => (
<BoardTaskContext value={boardTask()}>
<ThreadPanelHostContext value={leadRef}>
<AppRoot router={router} />
</ThreadPanelHostContext>
</BoardTaskContext>
);
await using screen = await render(hosted(), {
// AppRoot brings its own router.
router: false,
});
await expect
.element(screen.getByRole("textbox", { name: `Message ${source.title}`, exact: true }))
.toBeVisible();
// With the environment's snapshot in, the next render reconciles a panel's file tabs.
await expect
.poll(() => appAtomRegistry.get(environmentShell.hasSnapshotAtom(ENVIRONMENT_ID)))
.toBe(true);
await screen.rerender(hosted());
expect(
selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, leadRef).surfaces.map(
({ kind }) => kind,
),
).toEqual(["files", "task-evidence"]);
});

it("a seat in a board task's view floats its own preview, which opens in the seat's own view", async () => {
await page.viewport(1400, 900);
const lead = threadWithHistory("task-preview-lead", 1);
const seat = threadWithHistory("task-preview-seat", 1);
using _environment = installFakeEnvironment([lead, seat]);
__setClientSettingsForTests({
...DEFAULT_CLIENT_SETTINGS,
onboardingCompletedAt: "2026-01-01T00:00:00.000Z",
});
const leadRef = scopeThreadRef(ENVIRONMENT_ID, lead.id);
const seatRef = scopeThreadRef(ENVIRONMENT_ID, seat.id);
usePreviewMiniPlayerStore.getState().open(seatRef, {
kind: "device",
hostId: "local",
deviceId: "phone",
platform: "ios",
name: "Phone",
});
using _miniPlayer = {
[Symbol.dispose]: () => usePreviewMiniPlayerStore.getState().removeThread(seatRef),
};
const router = getRouter(
createMemoryHistory({ initialEntries: [`/${ENVIRONMENT_ID}/${seat.id}`] }),
);
await router.load();
using navigate = vi.spyOn(router, "navigate");
await using screen = await render(
<BoardTaskContext value={boardTask()}>
<ThreadPanelHostContext value={leadRef}>
<AppRoot router={router} />
</ThreadPanelHostContext>
</BoardTaskContext>,
{
// AppRoot brings its own router.
router: false,
},
);
await expect
.element(screen.getByRole("region", { name: "Floating device preview" }))
.toBeVisible();
// The pill shows on hover; the click is what is under test.
screen
.getByRole("button", { name: "Open preview in right panel" })
.element()
.dispatchEvent(new MouseEvent("click", { bubbles: true }));
const panel = (ref: typeof leadRef) =>
selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, ref).surfaces;
expect(panel(seatRef)).toEqual([expect.objectContaining({ kind: "device" })]);
expect(panel(leadRef)).toEqual([]);
expect(navigate).toHaveBeenCalledWith(
expect.objectContaining({ to: "/$environmentId/$threadId" }),
);
});

it("a subagent tab shows its read-only bar under no header of its own", async () => {
const parent = threadWithHistory("subagent-parent", 1);
const subagent = {
Expand Down
Loading
Loading