feat(webui): keep delegated work within reach (#6443)

This commit is contained in:
chengyongru authored and GitHub committed 2026-10-26 13:16:44 +08:00
1 parent 9270137d65
commit 9b3af7b66c
27 files changed
+2265 -234

No files matched your search

+4
View File
@@ -44,6 +44,7 @@ import { DisplayMathFixture } from "./display-math-fixture";
import { AttachmentLayoutFixture } from "./attachment-layout-fixture";
import { LoadedSessionSearchFixture } from "./loaded-session-search-fixture";
import { AppearanceFixture } from "./appearance-fixture";
import { installSubagentDockApi, SubagentDockFixture } from "./subagent-dock-fixture";
const history: UIMessage[] = [
{ id: "question", role: "user", content: "Earlier question", createdAt: 1_700_000_000_000 },
@@ -215,6 +216,7 @@ function AppsFixture() {
}
if (parameters.get("case") === "skeleton-additions") installSkeletonPreviewApi();
if (parameters.get("case") === "idle-compaction") installIdleCompactionApi();
if (parameters.get("case") === "subagent-dock") installSubagentDockApi();
await initializeI18n();
if (parameters.get("case") === "appearance" && parameters.has("lang")) {
await setAppLanguage(normalizeLocale(parameters.get("lang")));
@@ -224,6 +226,8 @@ createRoot(document.getElementById("root")!).render(<TooltipProvider>
? <AppearanceFixture />
: parameters.get("case") === "loaded-session-search"
? <LoadedSessionSearchFixture />
: parameters.get("case") === "subagent-dock"
? <SubagentDockFixture parameters={parameters} />
: parameters.get("case") === "attachments"
? <AttachmentLayoutFixture />
: parameters.get("case") === "theme-toggle"
+7 -1
View File
@@ -230,7 +230,13 @@ test("wheel loading hands off to a retained 48px slot; prepend and delayed layou
const { body, header } = await openSettledHistory(page);
const nativeTop = await body.evaluate((node) => node.scrollTop);
await body.hover();
// Lazy Markdown can change scrollTop before the queued wheel reaches the viewport.
const wheelDelivered = await body.evaluateHandle((node) => ({
done: new Promise<void>((resolve) => node.addEventListener("wheel", () => resolve(), { once: true })),
}));
await page.mouse.wheel(0, -100);
await wheelDelivered.evaluate(({ done }) => done);
await wheelDelivered.dispose();
await expect.poll(() => body.evaluate((node) => node.scrollTop)).toBeLessThan(nativeTop);
expect(await displacement(body)).toBe(0);
expect(history.reads).toHaveLength(0);
@@ -299,7 +305,7 @@ test("wheel loading hands off to a retained 48px slot; prepend and delayed layou
expect(history.reads).toHaveLength(1);
});
test("unlinked task prelude stays with the retained boundary when earlier messages load", async ({ page }) => {
test("archived task results stay with the retained boundary when earlier messages load", async ({ page }) => {
const history = await installHistory(page);
await page.route("**/api/sessions/**/subagents", (route) => route.fulfill({ json: { tasks: [{
task_id: "legacy", revision: 1, label: "Earlier check", task_description: "Check earlier work",
+150
View File
@@ -0,0 +1,150 @@
import { useEffect, useRef, useState } from "react";
import { ThreadShell } from "@/components/thread/ThreadShell";
import { settings } from "@/dev/gallery/settings";
import { setAppLanguage } from "@/i18n";
import { normalizeLocale } from "@/i18n/config";
import { ClientProvider } from "@/providers/ClientProvider";
import type { SubagentTaskSnapshot, ThreadProjectionEvent } from "@/lib/types";
import { createStreamClient } from "@/tests/stream-client";
const { client, receive } = createStreamClient();
const chatId = "dock-preview";
const turnId = "preview-turn";
const createdAt = Date.now() / 1000;
let streamLength = 0;
let inputNumber = 0;
const saveTasks = new URLSearchParams(location.search).has("saved");
const taskStorageKey = "fixture.subagent-dock.tasks";
const taskLabels = new URLSearchParams(location.search).has("long-labels")
? ["核对多轮任务完成后的归档位置、长标题换行与独立详情入口", "Review_the_responsive_subtask_panel_and_keyboard_focus_without_interrupting_running_work", "整理交互建议"]
: ["检查项目实现", "核对回归测试", "整理交互建议"];
const tasks: SubagentTaskSnapshot[] = taskLabels.map((label, index) => ({
task_id: `preview-${index}`, revision: 1, label, task_description: `这是虚构的演示任务:${label}。不会读取项目或调用模型。`,
origin_turn_id: turnId, origin_message_id: "preview-prompt", created_at: createdAt + index, completed_at: null,
state: index === 2 ? "queued" : "running", phase: "awaiting_model", elapsed_seconds: 20 + index * 3, iteration: 1,
tool_events: index === 0 ? [{ name: "read_file", status: "running" }] : index === 1 ? [{ name: "exec", status: "running" }] : [],
usage: null, receipts: {}, result: null, partial: false, stop_reason: null, error: null,
}));
const history: ThreadProjectionEvent[] = [
{ event: "user_message", chat_id: chatId, projection_id: "preview-prompt", turn_id: turnId, text: "请让三个子任务分别检查实现、测试和交互。主对话继续讨论,不要等它们全部结束。", starts_turn: true },
{ event: "message", chat_id: chatId, projection_id: "preview-answer", turn_id: turnId,
text: "已经安排。你可以继续在这里交流,子任务会独立推进。\n\n**随时查看,不必回翻聊天**\n\n输入区上方的子任务入口会留在原位。点开可以查看每一路任务的状态、真实工具活动和最终结果。\n\n" + "主对话仍然可以正常输出和滚动。任务列表与消息区分别滚动,展开详情也不会取消正在执行的任务。\n\n".repeat(12) },
];
function updateTask(index: number, patch: Partial<SubagentTaskSnapshot>) {
const previous = tasks[index];
const next = { ...previous, ...patch, revision: (previous.revision ?? 0) + 1 };
tasks[index] = next;
if (saveTasks) sessionStorage.setItem(taskStorageKey, JSON.stringify(tasks));
receive({ event: "subagent_task", chat_id: chatId, task: next });
}
export function installSubagentDockApi() {
const stored = saveTasks ? sessionStorage.getItem(taskStorageKey) : null;
if (stored) tasks.splice(0, tasks.length, ...JSON.parse(stored) as SubagentTaskSnapshot[]);
else if (new URLSearchParams(location.search).has("archived")) {
tasks.forEach((task, index) => {
tasks[index] = { ...task, state: "done", phase: "done", elapsed_seconds: [9, 89, 1234][index], completed_at: createdAt + 30, tool_events: [] };
});
} else if (new URLSearchParams(location.search).has("past")) {
tasks.push(...Array.from({ length: 40 }, (_, index) => ({
...tasks[0], task_id: `past-${index}`, label: `Past check ${index}`, state: "done" as const,
origin_message_id: null, origin_turn_id: "past-turn", created_at: createdAt - 100 + index,
completed_at: createdAt - 50 + index, tool_events: [], result: "Saved past result",
})));
}
const original = window.fetch.bind(window);
window.fetch = async (input, init) => {
const url = new URL(input instanceof Request ? input.url : String(input), location.href);
if (url.origin !== location.origin || !url.pathname.startsWith("/api/")) return original(input, init);
if (url.pathname === "/api/settings") return Response.json(settings);
if (url.pathname === "/api/commands") return Response.json({ commands: [
{ command: "/history", title: "Chat history", description: "Show recent messages", icon: "history", lifecycle: "side_channel", accepts_args: true },
] });
if (url.pathname.endsWith("/subagents")) return Response.json({ tasks: url.pathname.includes(encodeURIComponent(`websocket:${chatId}`)) ? tasks : [] });
if (url.pathname.includes("/subagents/") && url.pathname.endsWith("/webui-thread")) {
const task = tasks.find(item => url.pathname.includes(`/${item.task_id}/`))!;
return Response.json({ schemaVersion: 3, projection: "events", events: [
{ event: "user_message", chat_id: task.task_id, projection_id: `${task.task_id}-prompt`, turn_id: "child", starts_turn: true, text: task.task_description },
{ event: "message", chat_id: task.task_id, projection_id: `${task.task_id}-answer`, turn_id: "child", text: task.result ?? "正在检查。这是隔离的演示内容,没有真实文件操作。" },
] });
}
if (url.pathname.includes("/webui-thread")) return Response.json({ schemaVersion: 3, projection: "events", events: history });
return Response.json({}, { status: 404 });
};
client.requestMutation = async <T,>(action: string, payload?: Record<string, unknown>): Promise<T> => {
if (action !== "subagent.cancel") throw new Error(`Unexpected preview mutation: ${action}`);
const index = tasks.findIndex(task => task.task_id === payload?.task_id);
updateTask(index, { state: "cancelled", phase: "cancelled", tool_events: [], completed_at: Date.now() / 1000 });
return tasks[index] as T;
};
}
export function SubagentDockFixture({ parameters }: { parameters: URLSearchParams }) {
const [topic, setTopic] = useState(chatId);
const [active, setActive] = useState(true);
const [dark, setDark] = useState(parameters.has("dark"));
const [portal, setPortal] = useState<HTMLDivElement | null>(null);
const timers = useRef<number[]>([]);
useEffect(() => {
document.documentElement.classList.toggle("dark", dark);
void setAppLanguage(normalizeLocale(parameters.get("lang")));
}, [dark, parameters]);
useEffect(() => () => timers.current.forEach(window.clearTimeout), []);
const finish = () => tasks.forEach((task, index) => {
if (task.state === "running" || task.state === "queued") updateTask(index, {
state: "done", phase: "done", tool_events: [], completed_at: Date.now() / 1000,
result: index === 0 && parameters.has("image-result") ? "## Image result\n\n![Result image](https://example.com/dock-result.svg)"
: index === 0 && parameters.has("markdown-result")
? "## 天气结果\n\n**北京**:约 **10°C**,有小雨。\n\n" + "这是完整的多行查询结果,保留原始段落、文字样式和详细说明,阅读时可以滚动任务列表。".repeat(30)
+ "\n\n- **南京**:约 18°C,有雾。\n- **天津**:约 12°C,多云。\n\n[天气来源](https://example.com/weather)\n\n```text\nchecked_at: 2026-10-25T20:52:00+08:00\n```\n\n最后一条完整结论:以上结果均可继续核对。"
: ["已核对面板的位置与滚动边界。", "定向检查已完成,保留详情与单任务停止。", "建议让任务入口始终留在输入区附近。"][index % 3],
});
});
const growReply = () => {
streamLength += 12;
const replyTurn = `long-reply-${streamLength}`;
receive({ event: "goal_status", chat_id: chatId, turn_id: replyTurn, status: "running", started_at: Date.now() / 1000 });
receive({ event: "delta", chat_id: chatId, turn_id: replyTurn, stream_id: "reply", text: "主助手继续输出较长的说明,子任务入口保持在输入框上方。\n\n".repeat(streamLength) });
receive({ event: "stream_end", chat_id: chatId, turn_id: replyTurn, stream_id: "reply" });
receive({ event: "turn_end", chat_id: chatId, turn_id: replyTurn });
};
return <ClientProvider client={client} token="fixture" webuiCapabilities={["webui.core.v1", "webui.subagents.v1", "webui.subagents.events.v1", "webui.subagents.history.v1"]}>
<main className="thread-workspace flex min-w-0 flex-col overflow-hidden bg-background text-foreground" style={{ height: "var(--app-viewport-height, 100dvh)" }}>
<nav aria-label="Preview controls" className="flex shrink-0 items-center gap-4 overflow-x-auto whitespace-nowrap border-b px-4 py-2 text-xs text-muted-foreground">
<span>虚构任务预览</span>
<button onClick={() => {
growReply();
updateTask(2, { state: "running", tool_events: [{ name: "web_fetch", status: "running" }] });
timers.current.push(window.setTimeout(() => updateTask(0, { state: "done", tool_events: [], completed_at: Date.now() / 1000, result: "入口不会随主回复滚走。" }), 3000));
timers.current.push(window.setTimeout(finish, 7000));
}}>模拟运行</button>
<button onClick={growReply}>追加长回复</button>
<button onClick={() => updateTask(0, { state: "done", phase: "done", tool_events: [], completed_at: Date.now() / 1000, result: "第一项已完成并归档。" })}>完成第一项</button>
<button onClick={finish}>全部完成</button>
<button onClick={() => {
inputNumber += 1;
receive({ event: "user_message", chat_id: chatId, turn_id: `next-turn-${inputNumber}`, turn_seq: 1, starts_turn: true, text: `下一轮消息 ${inputNumber}` });
}}>新一轮消息</button>
<button onClick={() => updateTask(1, { state: "error", error: "演示:测试执行失败,请打开详情检查。", tool_events: [], completed_at: Date.now() / 1000 })}>模拟失败</button>
<button onClick={() => {
for (let index = 3; index < 23; index++) {
if (tasks[index]) continue;
tasks[index] = { ...tasks[0], task_id: `preview-${index}`, label: `额外检查 ${index}`, revision: 1, created_at: createdAt + index, state: "queued", completed_at: null, result: null, error: null, tool_events: [] };
receive({ event: "subagent_task", chat_id: chatId, task: tasks[index] });
}
}}>增加任务</button>
<button onClick={() => setTopic(topic === chatId ? "other-preview" : chatId)}>切换会话</button>
<button onClick={() => setActive(value => !value)}>切换活动面板</button>
<button onClick={() => setDark(value => !value)}>切换主题</button>
<button onClick={() => location.reload()}>重播</button>
</nav>
<ThreadShell session={{ key: `websocket:${topic}`, channel: "websocket", chatId: topic, createdAt: null, updatedAt: null, preview: "" }}
title="子任务交互预览" onToggleSidebar={() => {}} theme={dark ? "dark" : "light"} onToggleTheme={() => setDark(value => !value)}
settingsSnapshot={settings} composerActive={active} composerPortalTarget={parameters.has("portal") ? portal : undefined}
sessions={[{ key: "websocket:reference-preview", channel: "websocket", chatId: "reference-preview", title: "Reference conversation", preview: "", createdAt: null, updatedAt: null,
handle: { id: "handle_00000000000000000000000000000001", name: "reference" } }]} />
{parameters.has("portal") ? <div ref={setPortal} className="shrink-0 px-4 pb-4" data-testid="preview-composer-portal" /> : null}
</main>
</ClientProvider>;
}
+627
View File
@@ -0,0 +1,627 @@
import { expect, test, type Locator } from "@playwright/test";
async function settledMotion(target: Locator) {
await target.evaluate(() => document.fonts.ready);
await expect.poll(() => target.evaluate(async node => {
await new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)));
return node.getAnimations({ subtree: true }).filter(animation =>
animation.effect?.getTiming().iterations !== Infinity && (animation.pending || animation.playState === "running")).length;
})).toBe(0);
}
for (const width of [1440, 390]) {
test(`keeps subtasks reachable through long replies, independent list scrolling and detail handoff at ${width}px`, async ({ page }, info) => {
const errors: string[] = [];
page.on("pageerror", error => errors.push(error.message));
await page.setViewportSize({ width, height: 900 });
await page.goto("/browser/fixture.html?case=subagent-dock");
const trigger = page.getByTestId("subagent-task-dock-trigger");
const messages = page.getByTestId("thread-message-region");
await expect(trigger).toContainText("Running: 3");
await settledMotion(page.getByTestId("subagent-task-dock"));
const original = (await trigger.boundingBox())!;
const composer = page.locator(".thread-composer-surface");
const composerBounds = (await composer.boundingBox())!;
const corner = await composer.evaluate(node => Number.parseFloat(getComputedStyle(node).borderTopLeftRadius));
expect(original.x - composerBounds.x).toBeGreaterThanOrEqual(corner);
expect(composerBounds.x + composerBounds.width - original.x - original.width).toBeGreaterThanOrEqual(corner);
expect(original.y + original.height).toBeCloseTo(composerBounds.y, 0);
await page.screenshot({ path: info.outputPath("attached-handle-closed.png") });
expect(await messages.locator('[data-testid="subagent-task-dock"]').count()).toBe(0);
await page.getByRole("button", { name: "追加长回复", exact: true }).click();
await expect(messages.getByText(/主助手继续输出较长的说明/).first()).toBeAttached();
await messages.evaluate(node => { node.scrollTop = 0; });
await expect.poll(async () => Math.abs((await trigger.boundingBox())!.y - original.y)).toBeLessThan(1);
await expect(trigger).toBeInViewport();
await trigger.click({ position: { x: original.width - 8, y: original.height / 2 } });
const tree = page.getByTestId("subagent-task-tree");
await expect(tree).toBeVisible();
const dock = page.getByTestId("subagent-task-dock");
const panel = dock.getByRole("region", { name: "Subtasks", exact: true });
await settledMotion(panel);
const bounds = (await panel.boundingBox())!;
const anchor = (await dock.boundingBox())!;
expect(bounds.y).toBeGreaterThanOrEqual(0);
expect(bounds.y + bounds.height).toBeCloseTo(anchor.y + anchor.height, 0);
expect(bounds.y + bounds.height).toBeCloseTo((await composer.boundingBox())!.y, 0);
expect(bounds.width).toBeCloseTo(original.width, 0);
expect(bounds.height).toBeLessThanOrEqual(448);
await expect(panel).toHaveAccessibleDescription("0 of 3 completed");
await page.mouse.move(1, 1);
await page.screenshot({ path: info.outputPath("subtask-tree.png") });
const row = tree.locator('[data-subagent-id="preview-0"]');
await row.click();
const detail = page.getByRole("dialog", { name: "检查项目实现", exact: true });
await expect(detail).toBeVisible();
await expect(detail).toBeFocused();
await settledMotion(detail);
const headerStop = detail.getByRole("button", { name: "Stop 检查项目实现", exact: true });
await expect(detail).toHaveAccessibleDescription("Running");
await expect(detail.getByText("Running", { exact: true }).locator("..")).toHaveClass(/\bsr-only\b/);
await expect(headerStop.locator('[data-action-icon="stop"][data-active] .loading-ring-arc')).toBeVisible();
const headerTitle = detail.getByRole("heading", { name: "检查项目实现", exact: true });
const stopBounds = (await headerStop.boundingBox())!;
const closeBounds = (await detail.getByRole("button", { name: "Close", exact: true }).boundingBox())!;
expect(Math.abs(stopBounds.y + stopBounds.height / 2 - closeBounds.y - closeBounds.height / 2)).toBeLessThanOrEqual(1);
expect((await headerTitle.boundingBox())!.x + (await headerTitle.boundingBox())!.width).toBeLessThanOrEqual(stopBounds.x);
expect(stopBounds.x + stopBounds.width).toBeLessThanOrEqual(closeBounds.x);
if (width === 390) {
expect(stopBounds.width).toBeGreaterThanOrEqual(44);
expect(stopBounds.height).toBeGreaterThanOrEqual(44);
}
await headerTitle.locator("..").screenshot({ path: info.outputPath("running-detail-header-stop.png") });
await detail.getByRole("button", { name: "Close", exact: true }).click();
await expect(detail).toHaveCount(0);
await expect(tree).toBeVisible();
await expect(row).toBeFocused();
await page.keyboard.press("Escape");
await expect(tree).toHaveCount(0);
await expect(trigger).toBeFocused();
await page.getByRole("button", { name: "增加任务", exact: true }).click();
await trigger.click();
await expect(tree.locator("[data-subagent-id]")).toHaveCount(23);
const beforeScroll = await messages.evaluate(node => node.scrollTop);
await tree.hover();
await page.mouse.wheel(0, 3000);
await expect.poll(() => tree.evaluate(node => node.scrollTop)).toBeGreaterThan(0);
await expect(tree.locator('[data-subagent-id="preview-22"]')).toBeInViewport();
expect(await messages.evaluate(node => node.scrollTop)).toBe(beforeScroll);
await page.keyboard.press("Escape");
await expect(tree).toHaveCount(0);
await page.getByRole("button", { name: "全部完成", exact: true }).click();
await expect(trigger).toContainText("Completed: 23");
await trigger.click();
await expect(tree.locator('[data-task-state="done"]')).toHaveCount(23);
await page.keyboard.press("Escape");
await expect(tree).toHaveCount(0);
const input = page.getByRole("textbox").first();
await input.fill("The main conversation is still usable");
await expect(input).toHaveValue("The main conversation is still usable");
expect(await page.locator("body").evaluate(node => getComputedStyle(node).pointerEvents)).not.toBe("none");
expect(errors).toEqual([]);
});
}
for (const width of [1440, 390]) {
test(`renders complete result Markdown without clipping inside the task drawer at ${width}px`, async ({ page }, info) => {
await page.setViewportSize({ width, height: 844 });
await page.goto(`/browser/fixture.html?case=subagent-dock&markdown-result${width === 390 ? "&dark" : ""}`);
const trigger = page.getByTestId("subagent-task-dock-trigger");
const tree = page.getByTestId("subagent-task-tree");
const messages = page.getByTestId("thread-message-region");
await trigger.click();
const row = tree.locator('[data-subagent-id="preview-0"]');
const panel = page.getByTestId("subagent-task-dock").getByRole("region", { name: "Subtasks", exact: true });
await expect(tree).toBeVisible();
await expect.poll(async () => Math.abs((await panel.boundingBox())!.height - (await tree.boundingBox())!.height)).toBeLessThan(1);
const task = row.locator("xpath=ancestor::li[1]");
await expect(task.locator(".loading-ring-arc")).toHaveCount(1);
const labelX = (await row.locator(":scope > span").nth(1).boundingBox())!.x;
const statusSlot = (await row.locator(":scope > span").first().boundingBox())!;
await page.mouse.move(1, 1);
await page.screenshot({ path: info.outputPath("one-task-ring-running.png") });
// Finish through the existing control without dismissing the reading view.
await page.getByRole("button", { name: "全部完成", exact: true }).evaluate(node => (node as HTMLButtonElement).click());
const heading = tree.getByRole("heading", { level: 2, name: "天气结果" });
await expect(heading).toBeVisible();
await expect(row).toHaveAccessibleName(/检查项目实现 Completed/);
await expect(row.locator("svg")).toHaveCount(0);
expect((await row.locator(":scope > span").nth(1).boundingBox())!.x).toBeCloseTo(labelX, 1);
const completedSlot = (await row.locator(":scope > span").first().boundingBox())!;
expect(completedSlot.width).toBeCloseTo(statusSlot.width, 1);
expect(completedSlot.height).toBeCloseTo(statusSlot.height, 1);
await expect(tree.locator("strong").filter({ hasText: "10°C" })).toBeVisible();
await settledMotion(page.getByTestId("subagent-task-dock"));
const dimensions = await tree.evaluate(node => ({ clientWidth: node.clientWidth, scrollWidth: node.scrollWidth, clientHeight: node.clientHeight, scrollHeight: node.scrollHeight }));
expect(dimensions.scrollWidth).toBe(dimensions.clientWidth);
expect(dimensions.scrollHeight).toBeGreaterThan(dimensions.clientHeight);
await page.screenshot({ path: info.outputPath("result-markdown-start.png") });
const beforeScroll = await messages.evaluate(node => node.scrollTop);
const tail = tree.getByText("最后一条完整结论:以上结果均可继续核对。", { exact: true });
await tail.scrollIntoViewIfNeeded();
await expect(tail).toBeInViewport();
await expect(tree.getByRole("link", { name: "天气来源", exact: true })).toHaveAttribute("href", "https://example.com/weather");
await expect(tree.locator("pre")).toContainText("checked_at: 2026-10-25T20:52:00+08:00");
expect(await messages.evaluate(node => node.scrollTop)).toBe(beforeScroll);
await page.screenshot({ path: info.outputPath("result-markdown-end.png") });
const input = page.getByRole("textbox").first();
await input.fill("继续阅读完整结果,同时输入下一条消息");
await expect(trigger).toHaveAttribute("aria-expanded", "true");
await row.click();
const detail = page.getByRole("dialog", { name: "检查项目实现", exact: true });
await expect(detail.getByRole("heading", { level: 2, name: "天气结果" })).toBeVisible();
await expect(detail).toHaveAccessibleDescription("Completed");
const title = detail.getByRole("heading", { name: "检查项目实现", exact: true });
await settledMotion(detail);
const closeButton = await detail.getByRole("button", { name: "Close", exact: true }).elementHandle();
const { titleBounds, closeBounds } = await title.evaluate((node, close) => ({
titleBounds: node.getBoundingClientRect().toJSON(),
closeBounds: close!.getBoundingClientRect().toJSON(),
}), closeButton);
expect(Math.abs(titleBounds.y + titleBounds.height / 2 - closeBounds.y - closeBounds.height / 2)).toBeLessThanOrEqual(1);
expect(titleBounds.x + titleBounds.width).toBeLessThanOrEqual(closeBounds.x);
await expect(title.locator("..")).not.toContainText(/\d+s/);
await title.locator("..").screenshot({ path: info.outputPath("completed-detail-header.png") });
await page.keyboard.press("Escape");
await expect(row).toBeFocused();
});
}
test("keeps the portaled dock scoped to the active conversation and honors reduced motion", async ({ page }) => {
await page.emulateMedia({ reducedMotion: "reduce", colorScheme: "dark" });
await page.goto("/browser/fixture.html?case=subagent-dock&portal&dark");
const portal = page.getByTestId("preview-composer-portal");
const trigger = portal.getByTestId("subagent-task-dock-trigger");
await expect(trigger).toContainText("Running: 3");
await trigger.click();
const tree = page.getByTestId("subagent-task-tree");
await expect(tree).toBeVisible();
await expect(tree.locator(".loading-ring-arc").first()).toHaveCSS("animation-name", "none");
await expect(portal.getByRole("region", { name: "Subtasks", exact: true })).toHaveCSS("transition-property", "none");
await page.keyboard.press("Escape");
await page.getByRole("button", { name: "切换活动面板", exact: true }).click();
await expect(portal.getByTestId("subagent-task-dock")).toHaveCount(0);
await expect(tree).toHaveCount(0);
await page.getByRole("button", { name: "切换活动面板", exact: true }).click();
await expect(trigger).toBeVisible();
await expect(trigger).toHaveAttribute("aria-expanded", "false");
await page.getByRole("button", { name: "切换会话", exact: true }).click();
await expect(portal.getByTestId("subagent-task-dock")).toHaveCount(0);
await page.getByRole("button", { name: "切换会话", exact: true }).click();
await expect(trigger).toContainText("Running: 3");
await page.getByRole("button", { name: "模拟失败", exact: true }).click();
await expect(trigger).toContainText("Running: 2");
const results = page.getByTestId("thread-message-region").getByRole("region", { name: "Subtasks", exact: true });
await results.getByRole("button", { name: /Review needed: 1/ }).click();
const failedRow = results.getByRole("button", { name: /核对回归测试 Failed/ });
expect((await failedRow.getByText("Failed", { exact: true }).boundingBox())!.width).toBeGreaterThan(16);
await failedRow.click();
await expect(page.getByRole("dialog", { name: "核对回归测试", exact: true }).getByRole("alert")).toHaveText("演示:测试执行失败,请打开详情检查。");
});
test("keeps the composer editable while the task drawer stays open", async ({ page }) => {
await page.goto("/browser/fixture.html?case=subagent-dock");
await page.getByTestId("subagent-task-dock-trigger").click();
await expect(page.getByTestId("subagent-task-tree")).toBeVisible();
const input = page.getByRole("textbox").first();
await input.click();
await expect(page.getByTestId("subagent-task-tree")).toBeVisible();
await expect(input).toBeFocused();
await page.keyboard.type("Continue the conversation");
await expect(input).toHaveValue("Continue the conversation");
const imeEscapeAllowed = await input.evaluate(node => node.dispatchEvent(new KeyboardEvent("keydown", {
key: "Escape", isComposing: true, bubbles: true, cancelable: true,
})));
expect(imeEscapeAllowed).toBe(true);
await expect(page.getByTestId("subagent-task-dock-trigger")).toHaveAttribute("aria-expanded", "true");
});
for (const width of [1440, 390]) {
test(`preserves the top detail layer and its opener across a breakpoint change from ${width}px`, async ({ page }) => {
await page.setViewportSize({ width, height: 900 });
await page.goto("/browser/fixture.html?case=subagent-dock");
await page.getByTestId("subagent-task-dock-trigger").click();
const row = page.getByTestId("subagent-task-tree").locator('[data-subagent-id="preview-1"]');
await row.click();
const detail = page.getByRole("dialog", { name: "核对回归测试", exact: true });
await expect(detail).toBeFocused();
await page.setViewportSize({ width: width > 639 ? 390 : 1440, height: 900 });
await expect(detail).toBeVisible();
await expect(detail).toBeFocused();
await expect(page.getByRole("dialog")).toHaveCount(1);
await detail.getByRole("button", { name: "Close", exact: true }).click();
await expect(detail).toHaveCount(0);
await expect(page.getByTestId("subagent-task-tree")).toBeVisible();
await expect(row).toBeFocused();
await page.keyboard.press("Escape");
await expect(page.getByTestId("subagent-task-tree")).toHaveCount(0);
await expect(page.getByTestId("subagent-task-dock-trigger")).toBeFocused();
});
}
test("keeps the task drawer above the composer inside a shortened visual viewport", async ({ page }) => {
await page.setViewportSize({ width: 390, height: 844 });
await page.emulateMedia({ reducedMotion: "reduce" });
await page.goto("/browser/fixture.html?case=subagent-dock");
await page.evaluate(() => {
document.documentElement.style.setProperty("--app-viewport-top", "0px");
document.documentElement.style.setProperty("--app-viewport-height", "500px");
});
await page.getByTestId("subagent-task-dock-trigger").click();
const panel = page.getByTestId("subagent-task-dock").getByRole("region", { name: "Subtasks", exact: true });
const bounds = (await panel.boundingBox())!;
const input = page.getByRole("textbox").first();
const inputBounds = (await input.boundingBox())!;
expect(bounds.y).toBeGreaterThanOrEqual(0);
expect(bounds.y + bounds.height).toBeLessThanOrEqual(inputBounds.y);
expect(inputBounds.y + inputBounds.height).toBeLessThanOrEqual(500);
await input.fill("Keyboard viewport remains usable");
await expect(panel).toBeVisible();
await page.keyboard.press("Escape");
await expect(panel).toBeHidden();
await expect(input).toBeFocused();
});
for (const width of [1440, 390]) {
test(`retires completed live work into the conversation and restores only active tasks at ${width}px`, async ({ page }) => {
await page.setViewportSize({ width, height: 900 });
await page.goto("/browser/fixture.html?case=subagent-dock&saved&past");
const trigger = page.getByTestId("subagent-task-dock-trigger");
await trigger.click();
const tree = page.getByTestId("subagent-task-tree");
await expect(tree.locator("[data-subagent-id]")).toHaveCount(3);
await expect(tree).toContainText("检查项目实现");
await page.keyboard.press("Escape");
await page.getByRole("button", { name: "完成第一项", exact: true }).click();
await expect(trigger).toContainText("Running: 2");
await page.getByRole("button", { name: "新一轮消息", exact: true }).click();
await expect(trigger).toContainText("Running: 2");
await trigger.click();
await expect(tree.locator("[data-subagent-id]")).toHaveCount(2);
await expect(tree).toContainText("核对回归测试");
await expect(tree).toContainText("整理交互建议");
await page.keyboard.press("Escape");
await page.getByRole("button", { name: "全部完成", exact: true }).click();
await expect(trigger).toContainText("Completed: 2");
await expect(trigger).toHaveCount(0, { timeout: 7000 });
const results = page.getByTestId("thread-message-region").getByRole("region", { name: "Subtasks", exact: true });
await results.getByRole("button", { name: /Subtasks/ }).click();
await expect(results.locator("[data-subagent-id]")).toHaveCount(3);
await results.getByRole("button", { name: /检查项目实现 Completed/ }).click();
const detail = page.getByRole("dialog", { name: "检查项目实现", exact: true });
await expect(detail).toContainText("第一项已完成并归档。");
await detail.getByRole("button", { name: "Close", exact: true }).click();
await expect(results.getByRole("button", { name: /检查项目实现 Completed/ })).toBeFocused();
await page.reload();
await expect(page.getByTestId("thread-message-region").getByText("随时查看,不必回翻聊天", { exact: true })).toBeAttached();
await expect(trigger).toHaveCount(0);
const restoredResults = page.getByTestId("thread-message-region").getByRole("region", { name: "Subtasks", exact: true });
await restoredResults.getByRole("button", { name: /Subtasks/ }).click();
await expect(restoredResults.getByRole("button", { name: /检查项目实现 Completed/ })).toBeVisible();
});
}
test("does not retire a completed list or detail while it is being read", async ({ page }) => {
await page.goto("/browser/fixture.html?case=subagent-dock");
await page.getByRole("button", { name: "模拟运行", exact: true }).click();
const trigger = page.getByTestId("subagent-task-dock-trigger");
await trigger.click();
const tree = page.getByTestId("subagent-task-tree");
await tree.locator('[data-subagent-id="preview-1"]').click();
const detail = page.getByRole("dialog", { name: "核对回归测试", exact: true });
await expect(detail).toContainText("保留详情与单任务停止", { timeout: 12000 });
await detail.getByRole("button", { name: "Close", exact: true }).click();
await expect(tree.locator('[data-subagent-id="preview-1"]')).toBeFocused();
await expect(tree.locator('[data-task-state="done"]')).toHaveCount(3);
await page.keyboard.press("Escape");
await expect(tree).toHaveCount(0);
await expect(trigger).toHaveCount(0);
await expect(page.getByRole("textbox").first()).toBeFocused();
});
for (const width of [1440, 390]) {
test(`keeps the reading position when results are archived and the live entry retires at ${width}px`, async ({ page }) => {
await page.setViewportSize({ width, height: 900 });
await page.goto("/browser/fixture.html?case=subagent-dock");
const body = page.getByTestId("thread-message-region");
const paragraphs = body.getByText("主对话仍然可以正常输出和滚动。任务列表与消息区分别滚动,展开详情也不会取消正在执行的任务。", { exact: true });
await expect(paragraphs).toHaveCount(12);
await settledMotion(body);
const anchor = paragraphs.nth(6);
await anchor.scrollIntoViewIfNeeded();
await body.hover();
await page.mouse.wheel(0, -160);
await expect.poll(() => body.evaluate(node => node.scrollHeight - node.clientHeight - node.scrollTop)).toBeGreaterThan(100);
await expect(anchor).toBeInViewport();
await settledMotion(body);
await expect.poll(() => body.evaluate(node => node.scrollHeight - node.clientHeight - node.scrollTop)).toBeGreaterThan(100);
const before = (await anchor.boundingBox())!.y;
await page.getByRole("button", { name: "完成第一项", exact: true }).click();
await expect(page.getByTestId("subagent-task-dock-trigger")).toContainText("Running: 2");
await expect.poll(async () => Math.abs((await anchor.boundingBox())!.y - before)).toBeLessThan(1);
await page.getByRole("button", { name: "全部完成", exact: true }).click();
await expect(page.getByTestId("subagent-task-dock-trigger")).toHaveCount(0, { timeout: 7000 });
await expect.poll(async () => Math.abs((await anchor.boundingBox())!.y - before)).toBeLessThan(1);
});
}
test("returns to the composer when completed work is dismissed on desktop blank space", async ({ page }) => {
await page.goto("/browser/fixture.html?case=subagent-dock");
await page.getByRole("button", { name: "模拟运行", exact: true }).click();
await page.getByTestId("subagent-task-dock-trigger").click();
const tree = page.getByTestId("subagent-task-tree");
await expect(tree.locator('[data-task-state="done"]')).toHaveCount(3, { timeout: 12000 });
await page.locator("main").click({ position: { x: 4, y: 65 } });
await expect(tree).toHaveCount(0);
await expect(page.getByTestId("subagent-task-dock-trigger")).toHaveCount(0);
await expect(page.getByRole("textbox").first()).toBeFocused();
});
test("keeps long task names, stop controls and detail handoff usable on a narrow screen", async ({ page }, info) => {
await page.setViewportSize({ width: 320, height: 844 });
await page.goto("/browser/fixture.html?case=subagent-dock&long-labels");
await page.getByTestId("subagent-task-dock-trigger").click();
const panel = page.getByTestId("subagent-task-dock").getByRole("region", { name: "Subtasks", exact: true });
const tree = page.getByTestId("subagent-task-tree");
await expect(tree).toBeVisible();
expect(await tree.evaluate(node => node.scrollWidth)).toBe(await tree.evaluate(node => node.clientWidth));
const label = "核对多轮任务完成后的归档位置、长标题换行与独立详情入口";
const row = tree.locator('[data-subagent-id="preview-0"]');
await expect(row).toHaveAccessibleName(new RegExp(label));
const stop = panel.getByRole("button", { name: `Stop ${label}`, exact: true });
const stopBounds = (await stop.boundingBox())!;
expect(stopBounds.width).toBeGreaterThanOrEqual(44);
expect(stopBounds.height).toBeGreaterThanOrEqual(44);
await row.click();
const detail = page.getByRole("dialog", { name: label, exact: true });
await expect(detail).toBeFocused();
await settledMotion(detail);
const close = detail.getByRole("button", { name: "Close", exact: true });
const closeBounds = (await close.boundingBox())!;
expect(closeBounds.width).toBeGreaterThanOrEqual(44);
expect(closeBounds.height).toBeGreaterThanOrEqual(44);
const title = detail.getByRole("heading", { name: label, exact: true });
await expect(title).toHaveAttribute("title", label);
await expect(detail).toHaveAccessibleDescription("Running");
const titleBounds = (await title.boundingBox())!;
expect(titleBounds.height).toBeLessThan(30);
expect(Math.abs(titleBounds.y + titleBounds.height / 2 - closeBounds.y - closeBounds.height / 2)).toBeLessThanOrEqual(1);
expect(titleBounds.x + titleBounds.width).toBeLessThanOrEqual(closeBounds.x);
const detailStop = detail.getByRole("button", { name: `Stop ${label}`, exact: true });
const detailStopBounds = (await detailStop.boundingBox())!;
expect(detailStopBounds.width).toBeGreaterThanOrEqual(44);
expect(detailStopBounds.height).toBeGreaterThanOrEqual(44);
expect(Math.abs(detailStopBounds.y + detailStopBounds.height / 2 - closeBounds.y - closeBounds.height / 2)).toBeLessThanOrEqual(1);
expect(titleBounds.x + titleBounds.width).toBeLessThanOrEqual(detailStopBounds.x);
expect(detailStopBounds.x + detailStopBounds.width).toBeLessThanOrEqual(closeBounds.x);
await title.locator("..").screenshot({ path: info.outputPath("long-running-detail-header.png") });
await detailStop.click();
await expect(detail).toHaveAccessibleDescription("Cancelled");
await close.click();
await expect(row).toBeFocused();
});
test("follows the mouse before release and snaps without double toggling", async ({ page }, info) => {
await page.goto("/browser/fixture.html?case=subagent-dock");
const trigger = page.getByTestId("subagent-task-dock-trigger");
const tree = page.getByTestId("subagent-task-tree");
await expect(trigger).toHaveAttribute("aria-expanded", "false");
await page.getByRole("button", { name: "增加任务", exact: true }).click();
await expect(trigger).toContainText("Running: 23");
await expect(trigger).toHaveAttribute("aria-expanded", "false");
await expect(tree).toHaveCount(0);
await trigger.focus();
await page.keyboard.press("Tab");
await expect(page.getByRole("textbox").first()).toBeFocused();
const swipe = async (dx: number, dy: number) => {
const bounds = (await trigger.boundingBox())!;
const x = bounds.x + 8;
const y = bounds.y + bounds.height / 2;
await page.mouse.move(x, y);
await page.mouse.down();
await page.mouse.move(x + dx / 2, y + dy / 2, { steps: 4 });
if (Math.abs(dy) > Math.abs(dx)) {
await expect.poll(async () => (await trigger.boundingBox())!.y).toBeCloseTo(bounds.y + dy / 2, 0);
const panel = page.getByTestId("subagent-task-dock").getByRole("region", { name: "Subtasks", exact: true });
const panelBounds = (await panel.boundingBox())!;
const composerBounds = (await page.locator(".thread-composer-surface").boundingBox())!;
expect(panelBounds.y + panelBounds.height).toBeCloseTo(composerBounds.y, 0);
await page.screenshot({ path: info.outputPath(dy < 0 ? "mouse-drag-opening.png" : "mouse-drag-closing.png") });
}
await page.mouse.move(x + dx, y + dy, { steps: 4 });
await page.mouse.up();
};
await swipe(40, 2);
await expect(trigger).toHaveAttribute("aria-expanded", "false");
await swipe(0, -60);
await expect(tree).toBeVisible();
await settledMotion(page.getByTestId("subagent-task-dock"));
await swipe(0, 60);
await expect(tree).toHaveCount(0);
await expect(trigger).toBeFocused();
const bounds = (await trigger.boundingBox())!;
const x = bounds.x + 8;
const y = bounds.y + bounds.height / 2;
await page.mouse.move(x, y);
await page.mouse.down();
await page.mouse.move(x, y + 30, { steps: 4 });
await page.keyboard.press("Escape");
await page.mouse.move(x, y - 60, { steps: 6 });
await page.mouse.up();
await expect(trigger).toHaveAttribute("aria-expanded", "false");
await page.keyboard.press("Space");
await expect(tree).toBeVisible();
});
test.describe("touch task drawer", () => {
test.use({ hasTouch: true, isMobile: true, viewport: { width: 390, height: 844 } });
test("follows touch movement, restores a cancelled drag, and keeps list scrolling independent", async ({ page }, info) => {
await page.goto("/browser/fixture.html?case=subagent-dock");
const trigger = page.getByTestId("subagent-task-dock-trigger");
const tree = page.getByTestId("subagent-task-tree");
const cdp = await page.context().newCDPSession(page);
const swipe = async (target: typeof trigger, dy: number, cancel = false) => {
await settledMotion(page.getByTestId("subagent-task-dock"));
const bounds = (await target.boundingBox())!;
const x = bounds.x + bounds.width / 2;
const y = bounds.y + bounds.height / 2;
await cdp.send("Input.dispatchTouchEvent", { type: "touchStart", touchPoints: [{ x, y }] });
for (let step = 1; step <= 6; step++) {
await cdp.send("Input.dispatchTouchEvent", { type: "touchMove", touchPoints: [{ x, y: y + dy * step / 6 }] });
if (step === 3 && target === trigger) {
await expect.poll(async () => (await trigger.boundingBox())!.y).toBeCloseTo(bounds.y + dy / 2, 0);
await page.screenshot({ path: info.outputPath(cancel ? "touch-drag-before-cancel.png" : dy < 0 ? "touch-drag-opening.png" : "touch-drag-closing.png") });
}
}
await cdp.send("Input.dispatchTouchEvent", { type: cancel ? "touchCancel" : "touchEnd", touchPoints: [] });
};
await swipe(trigger, -60, true);
await expect(trigger).toHaveAttribute("aria-expanded", "false");
await swipe(trigger, -60);
await expect(tree).toBeVisible();
await settledMotion(page.getByTestId("subagent-task-dock"));
await swipe(trigger, 60, true);
await expect(trigger).toHaveAttribute("aria-expanded", "true");
await settledMotion(page.getByTestId("subagent-task-dock"));
await swipe(trigger, 60);
await expect(tree).toHaveCount(0);
await page.getByRole("button", { name: "增加任务", exact: true }).click();
await trigger.tap();
await expect(tree.locator("[data-subagent-id]")).toHaveCount(23);
await settledMotion(page.getByTestId("subagent-task-dock"));
await swipe(tree, -100);
await expect.poll(() => tree.evaluate(node => node.scrollTop)).toBeGreaterThan(0);
await expect(trigger).toHaveAttribute("aria-expanded", "true");
await cdp.detach();
});
test("preserves completion feedback when an opening drag is cancelled", async ({ page }) => {
await page.emulateMedia({ reducedMotion: "reduce", colorScheme: "dark" });
await page.goto("/browser/fixture.html?case=subagent-dock&dark");
const trigger = page.getByTestId("subagent-task-dock-trigger");
await trigger.focus();
const bounds = (await trigger.boundingBox())!;
const x = bounds.x + 12;
const y = bounds.y + bounds.height / 2;
const cdp = await page.context().newCDPSession(page);
await cdp.send("Input.dispatchTouchEvent", { type: "touchStart", touchPoints: [{ x, y }] });
await cdp.send("Input.dispatchTouchEvent", { type: "touchMove", touchPoints: [{ x, y: y - 40 }] });
await expect.poll(async () => (await trigger.boundingBox())!.y).toBeCloseTo(bounds.y - 40, 0);
await page.getByRole("button", { name: "全部完成", exact: true }).evaluate(node => (node as HTMLButtonElement).click());
await expect(page.getByTestId("subagent-task-tree").locator('[data-task-state="done"]')).toHaveCount(3);
await cdp.send("Input.dispatchTouchEvent", { type: "touchCancel", touchPoints: [] });
await expect(trigger).toHaveAttribute("aria-expanded", "false");
await expect(trigger).toContainText("Completed: 3");
await expect(page.getByTestId("subagent-task-tree")).toHaveCount(0);
await cdp.detach();
});
});
for (const width of [1440, 390, 320]) {
test(`aligns archived task columns with their disclosure at ${width}px`, async ({ page }, info) => {
await page.setViewportSize({ width, height: 900 });
await page.goto(`/browser/fixture.html?case=subagent-dock&archived${width === 320 ? "&long-labels" : ""}`);
if (width === 1440) await page.evaluate(() => { document.documentElement.style.zoom = "1.25"; });
const archive = page.locator("[data-subagent-results]").first();
const header = archive.locator("[data-subagent-results-summary]");
const logo = header.locator("img");
await expect(logo).toHaveAttribute("src", "/brand/nanobot_mark.svg");
await expect.poll(() => logo.evaluate(node => (node as HTMLImageElement).naturalWidth)).toBeGreaterThan(0);
const rows = archive.locator('[data-subagent-surface="archive"]');
await expect(rows.first()).toBeHidden();
await header.click();
await expect(rows).toHaveCount(3);
await expect(rows.first()).toBeVisible();
await settledMotion(archive);
const geometry = await archive.evaluate(node => {
const header = node.querySelector<HTMLElement>("[data-subagent-results-summary]")!;
const bounds = (element: Element) => element.getBoundingClientRect();
return {
overflow: node.scrollWidth > node.clientWidth,
header: [header.children[0], header.children[1]].map(element => bounds(element).x),
headerCenters: [...header.children].map(element => {
const rect = bounds(element);
return rect.y + rect.height / 2;
}),
trailingEdge: bounds(header.lastElementChild!).right,
rows: [...node.querySelectorAll('[data-subagent-surface="archive"]')].map(row => ({
columns: [row.children[0], row.children[1]].map(element => bounds(element).x),
elapsedRight: bounds(row.children[3]).right,
})),
};
});
expect(geometry.overflow).toBe(false);
expect(Math.max(...geometry.headerCenters) - Math.min(...geometry.headerCenters)).toBeLessThan(0.5);
for (const row of geometry.rows) {
row.columns.forEach((position, index) => expect(Math.abs(position - geometry.header[index])).toBeLessThan(0.5));
expect(Math.abs(row.elapsedRight - geometry.trailingEdge)).toBeLessThan(0.5);
}
await archive.screenshot({ path: info.outputPath("archive-logo-light.png") });
await page.getByRole("button", { name: "切换主题", exact: true }).click();
await expect(logo).toBeVisible();
await archive.screenshot({ path: info.outputPath("archive-logo-dark.png") });
await rows.first().click();
await expect(page.getByRole("dialog")).toBeFocused();
await page.keyboard.press("Escape");
await expect(rows.first()).toBeFocused();
await header.click();
await expect(rows.first()).toBeHidden();
});
}
for (const width of [1440, 390]) {
test(`keeps composer palettes reachable above an open task drawer at ${width}px`, async ({ page }) => {
await page.setViewportSize({ width, height: 900 });
await page.goto("/browser/fixture.html?case=subagent-dock");
const trigger = page.getByTestId("subagent-task-dock-trigger");
await trigger.click();
await settledMotion(page.getByTestId("subagent-task-dock"));
const input = page.getByRole("textbox").first();
for (const [query, inserted] of [["/", "/history"], ["@ref", "@reference "]]) {
await input.fill(query);
const option = page.getByRole("option").first();
await expect(option).toBeVisible();
expect(await option.evaluate(node => {
const bounds = node.getBoundingClientRect();
const hit = document.elementFromPoint(bounds.x + bounds.width / 2, bounds.y + bounds.height / 2);
return !!hit && node.contains(hit);
})).toBe(true);
await option.click();
await expect(input).toHaveValue(inserted);
await expect(trigger).toHaveAttribute("aria-expanded", "true");
await expect(page.getByTestId("subagent-task-tree")).toBeVisible();
}
});
test(`keeps result image portals owned by the task drawer at ${width}px`, async ({ page }) => {
await page.setViewportSize({ width, height: 900 });
await page.route("https://example.com/dock-result.svg", route => route.fulfill({
contentType: "image/svg+xml",
body: '<svg xmlns="http://www.w3.org/2000/svg" width="1200" height="800"><rect width="1200" height="800" fill="#7788aa" /></svg>',
}));
await page.goto("/browser/fixture.html?case=subagent-dock&image-result");
const trigger = page.getByTestId("subagent-task-dock-trigger");
await trigger.click();
await page.getByRole("button", { name: "全部完成", exact: true }).evaluate(node => (node as HTMLButtonElement).click());
const tree = page.getByTestId("subagent-task-tree");
const thumbnail = tree.getByRole("button", { name: "View image: Result image", exact: true });
await thumbnail.click();
const viewer = page.getByRole("dialog", { name: "Result image", exact: true });
await expect(viewer).toBeVisible();
await viewer.getByRole("button", { name: "Zoom in", exact: true }).click();
await expect(viewer.getByRole("button", { name: "Fit image", exact: true })).toHaveText("150%");
await viewer.getByRole("img", { name: "Result image", exact: true }).click();
await expect(viewer).toBeVisible();
await page.keyboard.press("Escape");
await expect(viewer).toHaveCount(0);
await expect(thumbnail).toBeFocused();
await expect(trigger).toHaveAttribute("aria-expanded", "true");
await page.locator("main").click({ position: { x: 4, y: 65 } });
await expect(tree).toHaveCount(0);
await expect(trigger).toHaveCount(0);
await expect(page.getByRole("textbox").first()).toBeFocused();
});
}