A local-first multi-agent app development platform, built on PenguinHarness
test(e2e): 浏览器 e2e 的 10 条红压到 3 条,8 条是夹具结论翻转
lmliheng4b5cdcb04be5
diff --git a/packages/web/e2e/chat.spec.mjs b/packages/web/e2e/chat.spec.mjsindex 5db7425e..a5f737ea 100644--- a/packages/web/e2e/chat.spec.mjs+++ b/packages/web/e2e/chat.spec.mjs@@ -6,6 +6,28 @@ const MOCK = process.env.MOCK_URL;const U = "e2euser";const P = "password123";+/**+ * Run one action from a Session row's "更多" menu. The trigger is a hover-revealed icon sitting+ * over the row's own clickable surface: when the click lands a frame before the row has re-laid+ * itself out, it hits the row (which navigates) and the menu never opens — observed as a+ * load-dependent flake, not a product bug (a pointer user sees the icon and clicks it). So the+ * open is retried and verified: press the trigger, and only go on once the menu's panel is on+ * screen, dismissing anything left over from the previous attempt first.+ */+async function pickRowAction(page, row, name) {+ for (let attempt = 0; attempt < 4; attempt += 1) {+ await row.hover();+ await row.getByRole("button", { name: "更多" }).click();+ const item = page.getByRole("button", { name, exact: true });+ if (await item.count()) {+ await item.first().click();+ return;+ }+ await page.keyboard.press("Escape");+ }+ throw new Error(`the row menu never offered "${name}"`);+}+test("chat + tool approval + stats/cost/copy + traces + files", async ({ page }) => {// --- seed via API (cookies land in the browser context) ---await provisionAndLogin(page.request, U, P);@@ -335,41 +357,53 @@ test("chat + tool approval + stats/cost/copy + traces + files", async ({ page })// --- group collapse / expand (the header button shows the group name, so its state// lives on aria-label rather than a duplicate title tooltip) ---- await expect(sidebar.getByText("Configure Tailwind theme")).toBeVisible();- await sidebar.locator('button[aria-label="折叠"]').first().click();- // Folded rows stay mounted (the fold animates their height to zero and makes them inert),- // so the check is "not visible", not "gone from the DOM".- await expect(sidebar.getByText("Configure Tailwind theme")).not.toBeVisible();+ // Addressed by the group's own label, not by the row: the session-row groups UNMOUNT their+ // body while collapsed (unlike the page-nav group, whose folded rows stay mounted), and the+ // page-nav group's toggle carries the very same "折叠 / 展开" label but comes first in the DOM+ // — a bare `first()` collapsed the nav instead of the conversation group. This session has no+ // Workspace of its own, so its group is the temporary-workspace one (S.chat.tempWorkspaces).+ const titledRow = sidebar.getByText("Configure Tailwind theme").first();+ const groupToggle = (label) =>+ sidebar.getByRole("button", { name: label }).filter({ hasText: "临时工作区" }).first();+ await expect(titledRow).toBeVisible();+ await groupToggle("折叠").click();+ await expect(titledRow).toHaveCount(0);// The collapse state persists across a reload (localStorage, keyed per Project): the group- // comes back rendered collapsed (an "展开" header), with its rows still hidden.+ // comes back rendered collapsed (an "展开" header) and its rows are not rendered.await page.reload();- await expect(sidebar.locator('button[aria-label="展开"]').first()).toBeVisible();- await expect(sidebar.getByText("Configure Tailwind theme")).not.toBeVisible();- await sidebar.locator('button[aria-label="展开"]').first().click();- await expect(sidebar.getByText("Configure Tailwind theme")).toBeVisible();+ await expect(groupToggle("展开")).toBeVisible();+ await expect(titledRow).toHaveCount(0);+ await groupToggle("展开").click();+ await expect(titledRow).toBeVisible();// --- settings: adjustable accent color + font size (default gray/white) ---// The username button shares its name with the Project switcher (the initial Project's// display name defaults to the username), so take the last match — the bottom user menu.+ // The preferences are no longer rows inside that menu: it opens the Settings dialog+ // (components/layout/user-menu.tsx), whose 外观 (appearance) page holds the accent swatches+ // and the text-size segments.await page.getByRole("button", { name: "e2euser" }).last().click();- await page.getByRole("button", { name: "蓝", exact: true }).click();+ await page.getByRole("menuitem", { name: "设置", exact: true }).click();+ const settings = page.getByRole("dialog", { name: "设置" });+ await expect(settings).toBeVisible();+ await settings.getByRole("button", { name: "外观", exact: true }).click();+ await settings.getByRole("button", { name: "蓝", exact: true }).click();await expect.poll(() => page.evaluate(() => document.documentElement.dataset.accent)).toBe("blue");// 大 is the old default (18px); the new default, 中, is 16px.- await page.getByRole("button", { name: "大", exact: true }).click();+ await settings.getByRole("button", { name: "大", exact: true }).click();await expect.poll(() => page.evaluate(() => document.documentElement.style.fontSize)).toBe("18px");await page.keyboard.press("Escape");+ await expect(settings).toHaveCount(0);// --- session rename (manual title wins over the auto-generated one) ---// Row actions live in the per-row ellipsis menu ("更多"); its panel is body-portaled,// so the items are page-level, not inside the row locator.const renameTarget = sidebar.locator("li", { hasText: "Configure Tailwind theme" }).first();- await renameTarget.hover();- await renameTarget.getByRole("button", { name: "更多" }).click();- await page.getByRole("button", { name: "重命名对话" }).click();+ await pickRowAction(page, renameTarget, "重命名对话");await page.getByLabel("标题").fill("My renamed title");await page.getByRole("button", { name: "保存" }).click();await expect(sidebar.getByText("My renamed title")).toBeVisible();@@ -384,9 +418,7 @@ test("chat + tool approval + stats/cost/copy + traces + files", async ({ page })const throwaway = sidebar.locator("li", { hasText: "新对话" }).first();await expect(throwaway).toBeVisible();// Archive via the row menu: moves it under the collapsed "已归档" group.- await throwaway.hover();- await throwaway.getByRole("button", { name: "更多" }).click();- await page.getByRole("button", { name: "归档", exact: true }).click();+ await pickRowAction(page, throwaway, "归档");await expect(sidebar.getByText(/已归档(\d+)/).first()).toBeVisible();await sidebar.getByText(/已归档(\d+)/)@@ -395,9 +427,7 @@ test("chat + tool approval + stats/cost/copy + traces + files", async ({ page })const archived = sidebar.locator("li", { hasText: "新对话" }).first();await expect(archived).toBeVisible();// Delete from the archived group (delete + archive share the same row menu).- await archived.hover();- await archived.getByRole("button", { name: "更多" }).click();- await page.getByRole("button", { name: "删除对话" }).click();+ await pickRowAction(page, archived, "删除对话");await page.getByRole("button", { name: "删除", exact: true }).click();await expect(sidebar.getByText("新对话")).toHaveCount(0);diff --git a/packages/web/e2e/compact-abort.spec.mjs b/packages/web/e2e/compact-abort.spec.mjsindex 5a23103d..25a9a429 100644--- a/packages/web/e2e/compact-abort.spec.mjs+++ b/packages/web/e2e/compact-abort.spec.mjs@@ -137,9 +137,19 @@ test("compacting twice in a row: says the context was just compacted, not that nvoid d.dismiss();});+ // Run the slash command the way a pointer user does — press in the menu's own row. Enter with+ // the menu open runs the highlighted row, but the highlight is state the list settles a frame+ // after the text lands; `fill()` writes the whole "/compact" at once, so pressing Enter can+ // arrive before that state exists and be swallowed (the text stays in the box, nothing runs).+ const runCompact = async () => {+ await ta.fill("/compact");+ const row = page.getByRole("button", { name: /^\/compact/ });+ await expect(row, "the slash menu offers /compact").toBeVisible();+ await row.first().click();+ };+// First /compact: compacts normally, shows the row, no toast expected.- await ta.fill("/compact");- await ta.press("Enter");+ await runCompact();await expect(compactionRows(page)).toHaveCount(1);// No compact-unavailable toast (match the 409 reasons' own wording, not bare "compact" —// usernames like "dblcompact" would collide).@@ -148,13 +158,10 @@ test("compacting twice in a row: says the context was just compacted, not that n).toHaveCount(0);// Second /compact: there's no conversation yet in the new context -> tell the user clearly, and the wording must match reality.- await ta.fill("/compact");- await ta.press("Enter");+ await runCompact();await expect(page.getByRole("button", { name: /刚刚压缩过/ })).toBeVisible();// Having just finished a full round, saying "no completed conversation round yet" would be absurd.- await expect(- page.getByRole("button", { name: /尚未完成一轮对话/ }),- ).toHaveCount(0);+ await expect(page.getByRole("button", { name: /尚未完成一轮对话/ })).toHaveCount(0);expect(nativeDialogs, "feedback must be an in-app toast, not a native alert").toHaveLength(0);await expect(compactionRows(page)).toHaveCount(1); // no second compaction row});diff --git a/packages/web/e2e/compaction.spec.mjs b/packages/web/e2e/compaction.spec.mjsindex 8496b3b3..5a6f0456 100644--- a/packages/web/e2e/compaction.spec.mjs+++ b/packages/web/e2e/compaction.spec.mjs@@ -111,6 +111,10 @@ test("compaction mid-turn: the reply's stats line is still reachable by hovering// collapsed and its body is not rendered at all. The mock answers the compaction request// with the same prose it used for the reply, so the summary's presence is counted rather// than matched by text alone (1 = the reply only, 2 = the reply + the expanded summary).+ //+ // Two disclosures deep: the banner opens the compaction's own sections, and the summary sits+ // in the 「压缩结果」 row behind a second disclosure (the thinking section beside it is what+ // a thinking model writes; the mock writes none, so there is only the one section here).const card = banner.locator("xpath=..");const summaryLine = /the result looks as expected/;await expect(banner).toHaveAttribute("aria-expanded", "false");@@ -119,6 +123,14 @@ test("compaction mid-turn: the reply's stats line is still reachable by hoveringawait banner.click();await expect(banner).toHaveAttribute("aria-expanded", "true");+ const resultRow = card.locator("button[aria-expanded]").filter({ hasText: "压缩结果" }).first();+ await expect(resultRow).toBeVisible();+ // The section row starts closed too: the banner is the "is there anything here" question,+ // the section is "read this part".+ await expect(resultRow).toHaveAttribute("aria-expanded", "false");+ await expect(card.getByText(summaryLine)).toHaveCount(0);+ await resultRow.click();+ await expect(resultRow).toHaveAttribute("aria-expanded", "true");await expect(card.getByText(summaryLine).first()).toBeVisible();await expect(page.getByText(summaryLine)).toHaveCount(2);diff --git a/packages/web/e2e/layout.spec.mjs b/packages/web/e2e/layout.spec.mjsindex ea3ccd2b..d09e4108 100644--- a/packages/web/e2e/layout.spec.mjs+++ b/packages/web/e2e/layout.spec.mjs@@ -52,13 +52,39 @@ const docWidths = (page) =>clientWidth: document.documentElement.clientWidth,}));-/** Count of pairwise rectangle intersections among visible leaf text elements (2px tolerance; ancestor-descendant pairs excluded). */+/**+ * Count of pairwise rectangle intersections among visible leaf text elements (2px tolerance;+ * ancestor-descendant pairs excluded).+ *+ * "Visible" has to mean *painted where the rect says*: a fold collapses through+ * `grid-rows-[0fr]` + an `overflow-hidden` wrapper, so the rows of a collapsed group keep their+ * laid-out rects while that wrapper is 0px tall and `inert` — laid out but clipped away, and+ * counting them as text on screen reported twelve phantom overlaps on the models page (each+ * collapsed group's model rows over the next group's header). So a leaf is skipped when a+ * clipping ancestor (overflow other than visible) leaves it less than 2px of visible area.+ */const textOverlapCount = (page) =>page.evaluate(() => {const isVisible = (el) => {const s = getComputedStyle(el);return s.visibility !== "hidden" && s.display !== "none" && Number(s.opacity) > 0.05;};+ /** The part of `r` a clipping ancestor actually lets through (the viewport is the outermost clip). */+ const unclipped = (el, r) => {+ let box = { left: r.left, top: r.top, right: r.right, bottom: r.bottom };+ for (let p = el.parentElement; p; p = p.parentElement) {+ const s = getComputedStyle(p);+ if (s.overflow === "visible") continue;+ const pr = p.getBoundingClientRect();+ box = {+ left: Math.max(box.left, pr.left + p.clientLeft),+ top: Math.max(box.top, pr.top + p.clientTop),+ right: Math.min(box.right, pr.left + p.clientLeft + p.clientWidth),+ bottom: Math.min(box.bottom, pr.top + p.clientTop + p.clientHeight),+ };+ }+ return box;+ };const leaves = [];for (const el of document.querySelectorAll("body *")) {if (!isVisible(el)) continue;@@ -66,9 +92,9 @@ const textOverlapCount = (page) =>(n) => n.nodeType === 3 && n.textContent && n.textContent.trim(),);if (!hasText) continue;- const r = el.getBoundingClientRect();- if (r.width < 2 || r.height < 2) continue;- leaves.push({ el, r });+ const visible = unclipped(el, el.getBoundingClientRect());+ if (visible.right - visible.left < 2 || visible.bottom - visible.top < 2) continue;+ leaves.push({ el, r: visible });}const TOL = 2;let count = 0;@@ -231,6 +257,12 @@ test("layout: en draft + context gauge + mobile models", async ({ page }) => {// "username" box on its own — it used to fill the account credentials into the API key and// the field above it. A password box additionally has to say "new-password": Chrome and// Safari ignore autocomplete="off" there. ---+ // The provider groups start folded (model-group-expansion.ts), and a folded body stays laid+ // out inside a zero-height clip: its copy of the model name is what a bare text locator finds+ // first, and the click would land on the clipping ancestor. Open the group the model is in.+ const customGroup = page.getByRole("button", { name: "Custom" }).first();+ await customGroup.click();+ await expect(customGroup, "custom group opened").toHaveAttribute("aria-expanded", "true");await page.getByText("claude-4-8").first().click();const dialogFields = await page.evaluate(() =>[...document.querySelectorAll("input")]@@ -257,8 +289,12 @@ test("layout: en draft + context gauge + mobile models", async ({ page }) => {await page.keyboard.press("Escape");// --- Sidebar "New chat" button: no background fill (its resting state outside the draft page should have a transparent background) ---+ // A pinned row of the column, not a page row of the nav group (it sits between the Project+ // switcher and the scrolling list), so it is addressed on the sidebar itself.await page.setViewportSize({ width: 1280, height: 720 });- const newChat = page.locator("nav").getByRole("button", { name: "New chat" });+ const newChat = page+ .getByRole("complementary")+ .getByRole("button", { name: "New chat", exact: true });await expect(newChat).toBeVisible();expect(await newChat.evaluate((el) => getComputedStyle(el).backgroundColor),@@ -625,8 +661,25 @@ test("layout: mobile chat dropdowns stay inside the viewport", async ({ page })await expect(picker).toHaveCount(0);await open("Choose agent", `agent @${vp.width}`);await close();- await open("Workspace", `workspace @${vp.width}`);- await close();+ // The Workspace picker is not a hanging menu but the Finder modal+ // (features/chat/workspace-finder.tsx): choosing a directory is a browsing job, so the same+ // Modal opens from every trigger — at phone width too. What must hold is the same thing the+ // menus are checked for: the panel stays inside the viewport and the page does not move.+ await page.locator('button[aria-label^="Workspace"]').click();+ const finder = page.getByRole("dialog", { name: "Workspace" });+ await expect(finder, `workspace @${vp.width}: finder open`).toBeVisible();+ await page.waitForTimeout(200); // let the pop-in scale animation settle before measuring+ const fb = await finder.boundingBox();+ expect(fb.x, `workspace @${vp.width}: finder left edge`).toBeGreaterThanOrEqual(-0.5);+ expect(fb.x + fb.width, `workspace @${vp.width}: finder right edge`).toBeLessThanOrEqual(+ vp.width + 0.5,+ );+ const wd = await docWidths(page);+ expect(wd.scrollWidth, `workspace @${vp.width}: no horizontal overflow`).toBeLessThanOrEqual(+ wd.clientWidth,+ );+ await page.keyboard.press("Escape");+ await expect(finder, `workspace @${vp.width}: finder closed`).toHaveCount(0);}// Session state (bottom-docked composer, menus open upward). The composer toolbar scrollsdiff --git a/packages/web/e2e/outline.spec.mjs b/packages/web/e2e/outline.spec.mjsindex 6822aef5..620156a2 100644--- a/packages/web/e2e/outline.spec.mjs+++ b/packages/web/e2e/outline.spec.mjs@@ -227,9 +227,13 @@ test("minimap ticks + hover preview + jump, five-turn gate, sticky group header,const row = [...document.querySelectorAll("button[aria-expanded]")].find((b) =>b.textContent.includes("执行命令"),);+ // The STICKY element, not the button inside it: the tool card is one padded box that pins+ // (py-1.5 around the button), so measuring the button measured its padding too and read a+ // 6 px gap where the boxes are flush.+ const rowBox = row.closest("[class*='sticky']");return {delta: Math.abs(head.getBoundingClientRect().top - ct),- rowDelta: row.getBoundingClientRect().top - ct,+ rowDelta: rowBox.getBoundingClientRect().top - ct,headerHeight: head.getBoundingClientRect().height,cardAboveFold: card.getBoundingClientRect().top < ct,};diff --git a/packages/web/e2e/project-switch.spec.mjs b/packages/web/e2e/project-switch.spec.mjsindex f922f24e..baa6c11c 100644--- a/packages/web/e2e/project-switch.spec.mjs+++ b/packages/web/e2e/project-switch.spec.mjs@@ -85,14 +85,35 @@ test("clicking the current Project in the dropdown: Agent and Session lists must// —— Regression (#74 comment): switching Project on the plugin library page must not leave// installation state from the previous Project —— both Projects' default_agent share the same- // name (agentId is the page state table's key): first uninstall agent-initialization from the current+ // name (agentId is the page state table's key): first uninstall agent-tuning from the current// (target) Project via the API, then switch over from the initial Project's plugin library page// — before the fix, the old Project's snapshot would overwrite the freshly fetched data, so// "Manage installation" would always show "Installed."- const del = await page.request.delete(- `${BASE}/api/projects/${projectId}/agents/default_agent/skills/agent-initialization`,- );- expect(del.ok(), "uninstall agent-initialization on target project").toBeTruthy();+ //+ // Every skill of the plugin, not just one: an install is marked by *any* part of the plugin+ // being present (`pluginInstalled` — a partial copy is what an update completes), so removing+ // a single skill leaves the row legitimately reading "Installed". The list is the plugin's own+ // (`plugins/agent-tuning/skills/`), spelled out here like the rest of this spec's fixtures.+ const AGENT_TUNING_SKILLS = [+ "agent-evaluation",+ "agent-initialization",+ "agent-optimization",+ "benchmark-design",+ ];+ for (const skill of AGENT_TUNING_SKILLS) {+ const del = await page.request.delete(+ `${BASE}/api/projects/${projectId}/agents/default_agent/skills/${skill}`,+ );+ expect(del.ok(), `uninstall ${skill} on target project`).toBeTruthy();+ }+ // And the hook packages, when the plugin ships one (it does not today): same rule, so the+ // fixture does not rot again if one is added.+ for (const hook of ["agent-tuning"]) {+ const res = await page.request.delete(+ `${BASE}/api/projects/${projectId}/agents/default_agent/hooks/${hook}`,+ );+ expect([204, 404], `uninstall hook ${hook} on target project`).toContain(res.status());+ }// Switch back to the initial Project, populating the plugin library page's snapshot (default_agent has everything preinstalled -> Installed).await byName.first().click();diff --git a/packages/web/e2e/skills.spec.mjs b/packages/web/e2e/skills.spec.mjsindex d21b0e99..75fb2e98 100644--- a/packages/web/e2e/skills.spec.mjs+++ b/packages/web/e2e/skills.spec.mjs@@ -247,7 +247,11 @@ test("skills: library list and cards -> manage-install Modal -> quick-invoke pre// prefilled body "使用 data-analysis 技能" still renders normally; the selection clears once// sending succeeds (the dropdown button's badge disappears).await expect(page.getByText(/使用技能.*data-analysis/)).toBeVisible();- await expect(page.getByText("使用 data-analysis 技能", { exact: true })).toBeVisible();+ // Scoped to the message body: the same words now also title the session (row + page heading)+ // after the first round, which is the point of a title and not a second copy of the message.+ await expect(+ page.getByRole("main").getByText("使用 data-analysis 技能", { exact: true }).last(),+ ).toBeVisible();await expect(skillsBtn).not.toContainText("1");// The mock LLM's fallback reply completes a full round (allow-all auto-approves exec_command).diff --git a/packages/web/scripts/theme-shots.mjs b/packages/web/scripts/theme-shots.mjsindex 60190a9c..c8aa334d 100644--- a/packages/web/scripts/theme-shots.mjs+++ b/packages/web/scripts/theme-shots.mjs@@ -115,7 +115,10 @@ const scriptFor = (flat) => (flat.includes(SCRIPTS.zh.marker) ? SCRIPTS.zh : SCRfunction openaiReply(res, body) {const flat = JSON.stringify(body.messages ?? []);const script = scriptFor(flat);- const isTitle = flat.includes("concise title");+ // Title requests are core's `buildTitlePrompt` (packages/core/src/internal/session-title.ts),+ // which opens with this line; it used to say "concise title", so the branch had gone dead and+ // every session title in the shots fell back to the host's own first-words truncation.+ const isTitle = flat.includes("You are a title generator.");const toolDone = flat.includes('"role":"tool"');res.writeHead(200, { "content-type": "text/event-stream", "cache-control": "no-cache" });const chunk = (delta, finishReason = null, usage) => {