Files
openbot/scripts/task-plan-e2e.ts
T
NBandClaude Opus 5.5 7ff90ccd1c Show the cards above the message box as one card (#3045)
* Show the cards above the message box as one card

The waiting block, open waits, queue, reply preview and notices are now in one
stack. The stack draws one border and one radius and goes under the input. The
parts in it have no gaps and no corners of their own, and a 1px line divides
them. Before, the queue slot clip cut the lower edge of each card flat, and a
card edge showed through the notice below it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Check the one composer stack and keep its narrow and exit behavior

The task plan e2e check now finds the cards in the stack. It checks that
each card sits flush on the card above with one shared line, and that the
cards fill the stack's width. It also checks the story with notices.

On a narrow pane the stack keeps the 2px side inset that the queue had.
When the last card is a compaction notice that leaves, the frame drops
behind the input with it, so no empty frame stays.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Remove the attachment exceptions that the stack made dead

The queue and the last waiting block did not go under the message box when it
held an attachment. In the stack these cards have no bottom margin, so the two
rules did nothing. The stack always goes under the message box, as the notices
already did. The attachment row is in the opaque message box, which paints
above the stack, so the stack cannot hide it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-24 19:02:33 +02:00

240 lines
11 KiB
TypeScript

// Checks the agent plan block and the waiting block in a running Storybook, which renders the real
// conversation timeline and composer against the preview mock. Read-only. Pass the Storybook URL
// that `bun run storybook` reports: `bun scripts/task-plan-e2e.ts --storybook=http://localhost:6006`.
// It also checks the panels above the input: each panel goes under the next one, the lower panel
// paints over the shared edge, and the top of each panel stays visible. The cards in the one stack
// above the input sit flush, with one shared line between them, and fill the stack's width.
// Writes .openbot-build/task-plan-e2e/report.json and one screenshot per story.
import assert from "node:assert/strict";
import { mkdirSync, writeFileSync } from "node:fs";
import { resolve } from "node:path";
import { translateFor } from "@openbot/i18n";
import { chromium, type Page } from "playwright-core";
const OUT = resolve(import.meta.dirname, "../.openbot-build/task-plan-e2e");
const t = translateFor("en");
const storybook = process.argv.find((arg) => arg.startsWith("--storybook="))?.slice("--storybook=".length);
assert.ok(storybook, "Pass --storybook=<url> with the URL that `bun run storybook` reports.");
interface Report {
waitingForReplies?: {
planSteps: number;
waitingRows: number;
agentReplyInQueue: boolean;
waitingAboveQueue: boolean;
};
planInProgress?: { expanded: boolean; done: number; total: number };
awaitingStates?: string[];
stacks?: Record<string, ComposerStack>;
passed: boolean;
}
const report: Report = { passed: false };
async function openStory(page: Page, id: string) {
await page.goto(`${storybook}/iframe.html?id=${id}&viewMode=story`);
await page.locator("#storybook-root").waitFor();
}
interface StackSeam {
pair: string;
overlap: number;
lowerPaintsOver: boolean;
upperTopVisible: boolean;
}
interface CardSeam {
pair: string;
overlap: number;
}
interface ComposerStack {
seams: StackSeam[];
cards: CardSeam[];
cardsFillStack: boolean;
}
/** The seams between the panels above the input, from the top to the composer, and the cards in the stack. */
async function composerStack(page: Page): Promise<ComposerStack> {
// The panels slide in once; the shimmer and spinner animations run forever.
await page.waitForFunction(() =>
document
.getAnimations()
.every((animation) => animation.playState !== "running" || animation.effect?.getTiming().iterations === Infinity),
);
return page.evaluate(() => {
const wrap = document.querySelector(".composer-wrap");
if (!wrap) return { seams: [], cards: [], cardsFillStack: false };
const visible = (node: Element) => node.getBoundingClientRect().height > 0;
const label = (node: Element) => [...node.classList].find((name) => !name.startsWith("task-list")) ?? node.tagName;
const panels = [...wrap.children].filter(visible);
const stack = wrap.querySelector(":scope > .composer-stack");
const cards = stack
? [...stack.querySelectorAll(":scope > *, :scope > .agent-queue-slot > .agent-queue-slot-inner > *")].filter(
(node) => !node.classList.contains("agent-queue-slot") && visible(node),
)
: [];
const frame = stack?.getBoundingClientRect();
const border = stack ? Number.parseFloat(getComputedStyle(stack).borderLeftWidth) : 0;
const cardsFillStack =
frame !== undefined &&
cards.every((card) => {
const box = card.getBoundingClientRect();
return (
Math.round(box.left) === Math.round(frame.left + border) &&
Math.round(box.right) === Math.round(frame.right - border)
);
});
const cardSeams = cards.slice(1).flatMap((lower, index) => {
const upper = cards[index];
if (!upper) return [];
return [
{
pair: `${label(upper)} > ${label(lower)}`,
overlap: Math.round(upper.getBoundingClientRect().bottom - lower.getBoundingClientRect().top),
},
];
});
const seams = panels.slice(1).flatMap((lower, index) => {
const upper = panels[index];
if (!upper) return [];
const top = upper.getBoundingClientRect();
const bottom = lower.getBoundingClientRect();
const overlap = Math.round(top.bottom - bottom.top);
const seam = document.elementFromPoint(bottom.left + 60, (top.bottom + bottom.top) / 2);
const head = document.elementFromPoint(top.left + 40, top.top + 8);
return [
{
pair: `${label(upper)} > ${label(lower)}`,
overlap,
lowerPaintsOver: overlap <= 0 || Boolean(seam && lower.contains(seam)),
upperTopVisible: Boolean(head && upper.contains(head)),
},
];
});
return { seams, cards: cardSeams, cardsFillStack };
});
}
function header(page: Page, title: string) {
return page.getByRole("button", { name: new RegExp(`^${title}`) });
}
mkdirSync(OUT, { recursive: true });
const browser = await chromium.launch({ channel: "chrome" });
try {
const page = await browser.newPage({ viewport: { width: 1200, height: 860 } });
// The agent asked Research and Sales Outbound. Research replied; its answer waits in the queue.
await openStory(page, "conversation-conversation--waiting-for-replies");
const plan = header(page, t("chat.taskList.title"));
await plan.waitFor();
assert.equal(await plan.count(), 1, "One plan turn gives one task list.");
assert.match((await plan.textContent()) ?? "", /4 of 4 tasks done/u);
assert.equal(await plan.getAttribute("aria-expanded"), "false", "A plan from an earlier turn starts closed.");
await plan.click();
assert.equal(await plan.getAttribute("aria-expanded"), "true");
const planPanel = page.locator(`[id="${await plan.getAttribute("aria-controls")}"]`);
assert.equal(await planPanel.getByRole("img", { name: t("chat.taskList.state.done") }).count(), 4);
const waiting = header(page, t("chat.awaiting.title"));
await waiting.waitFor();
assert.match((await waiting.textContent()) ?? "", /1 of 2 replies in/u);
const waitingBlock = page.locator("section").filter({ has: waiting });
const research = waitingBlock.getByRole("listitem").filter({ hasText: "Research" });
assert.match((await research.textContent()) ?? "", new RegExp(t("chat.awaiting.state.replied")));
assert.match((await research.textContent()) ?? "", /All four sources check out/u);
// Chief reads the answers only when Sales Outbound is done too.
assert.doesNotMatch(
(await research.textContent()) ?? "",
new RegExp(t("chat.awaiting.readsNext", { name: "Chief" })),
);
const sales = waitingBlock.getByRole("listitem").filter({ hasText: "Sales Outbound" });
assert.match((await sales.textContent()) ?? "", new RegExp(t("chat.awaiting.state.working")));
const queue = page.getByRole("region", { name: t("queue.label") });
await queue.waitFor();
assert.equal(await queue.getByText("All four sources check out", { exact: false }).count(), 0);
const waitingAboveQueue = await waitingBlock.evaluate(
(block, queueNode) =>
Boolean(queueNode && block.compareDocumentPosition(queueNode) & Node.DOCUMENT_POSITION_FOLLOWING),
await queue.elementHandle(),
);
assert.equal(waitingAboveQueue, true, "The waiting block is above the queue.");
await page.screenshot({ path: resolve(OUT, "conversation-waiting.png") });
report.waitingForReplies = { planSteps: 4, waitingRows: 2, agentReplyInQueue: false, waitingAboveQueue };
// A plan in the running turn is open and names the step that runs.
await openStory(page, "conversation-conversation--plan-in-progress");
const live = header(page, t("chat.taskList.title"));
await live.waitFor();
assert.equal(await live.getAttribute("aria-expanded"), "true", "The plan of the running turn is open.");
assert.match((await live.textContent()) ?? "", /1 of 3 tasks done/u);
const livePanel = page.locator(`[id="${await live.getAttribute("aria-controls")}"]`);
const active = livePanel
.getByRole("listitem")
.filter({ has: page.getByRole("img", { name: t("chat.taskList.state.active") }) });
assert.match((await active.textContent()) ?? "", /Adding the column for the saved provider/u);
await page.screenshot({ path: resolve(OUT, "conversation-plan-live.png") });
report.planInProgress = { expanded: true, done: 1, total: 3 };
// All four states of a waiting row, and the closed header that names the agent that works.
await openStory(page, "conversation-awaiting-replies--waiting");
const rows = page.getByRole("listitem");
assert.equal(await rows.count(), 3);
for (const [name, state] of [
["Research", "chat.awaiting.state.replied"],
["Sales Outbound", "chat.awaiting.state.working"],
["Support", "chat.awaiting.state.asked"],
] as const) {
assert.match((await rows.filter({ hasText: name }).textContent()) ?? "", new RegExp(t(state)));
}
const opened = header(page, t("chat.awaiting.title"));
// A closed header shows the agent that works in place of the title, so its name changes.
const block = page.locator(`[aria-controls="${await opened.getAttribute("aria-controls")}"]`);
await block.click();
assert.equal(await block.getAttribute("aria-expanded"), "false");
await page.getByText(t("chat.awaiting.working", { name: "Sales Outbound" })).waitFor();
await openStory(page, "conversation-awaiting-replies--one-failed");
assert.match(
(await page.getByRole("listitem").first().textContent()) ?? "",
new RegExp(t("chat.awaiting.state.failed")),
);
report.awaitingStates = ["replied", "working", "asked", "failed"];
// Waiting + queue, waiting + queue + notices, waiting alone, waiting + notice, and a channel's
// waiting + stopped task.
report.stacks = {};
for (const id of [
"conversation-conversation--waiting-for-replies",
"conversation-conversation--waiting-for-replies-with-usage-limit",
"conversation-conversation--plan-in-progress",
"conversation-conversation--provider-sign-in-required",
"conversation-channel--waiting-subtasks-above-stopped-task",
]) {
await openStory(page, id);
await page.locator(".composer-wrap .awaiting-replies").waitFor();
const stack = await composerStack(page);
const { seams } = stack;
assert.ok(seams.length > 0, `${id}: no panel above the input.`);
for (const seam of seams) {
assert.ok(seam.overlap > 0, `${id}: ${seam.pair} does not go under the next panel.`);
assert.ok(seam.lowerPaintsOver, `${id}: ${seam.pair} covers the next panel.`);
assert.ok(seam.upperTopVisible, `${id}: the top of ${seam.pair} is hidden.`);
}
// One pixel is the shared line: each card covers the line above it with its own top line.
for (const card of stack.cards) {
assert.equal(card.overlap, 1, `${id}: ${card.pair} does not sit flush on the card above.`);
}
assert.ok(stack.cardsFillStack, `${id}: a card in the stack does not fill its width.`);
await page.locator(".composer-wrap").screenshot({ path: resolve(OUT, `stack-${id.split("--")[1]}.png`) });
report.stacks[id] = stack;
}
report.passed = true;
writeFileSync(resolve(OUT, "report.json"), `${JSON.stringify(report, null, 2)}\n`);
process.stdout.write(`${JSON.stringify(report)}\n`);
} finally {
await browser.close();
}