From 960bfa9a83bef8551a66f27522c20906cd53ae39 Mon Sep 17 00:00:00 2001 From: chengyongru Date: Tue, 27 Oct 2026 12:06:31 +0800 Subject: [PATCH] test(webui): trim redundant browser coverage --- webui/browser/answer-order.spec.ts | 74 +++++------ webui/browser/compaction-reasons.spec.ts | 74 ++++++----- webui/browser/fixture.tsx | 3 - .../browser/loaded-session-search-fixture.tsx | 17 +-- webui/browser/loaded-session-search.spec.ts | 27 +--- webui/browser/markdown-emphasis-fixture.tsx | 21 --- webui/browser/markdown-emphasis.spec.ts | 23 ---- webui/browser/queued-guidance.spec.ts | 56 ++++---- webui/browser/typography.spec.ts | 122 +++++++++--------- webui/browser/workspace-alignment.spec.ts | 30 +++-- 10 files changed, 187 insertions(+), 260 deletions(-) delete mode 100644 webui/browser/markdown-emphasis-fixture.tsx delete mode 100644 webui/browser/markdown-emphasis.spec.ts diff --git a/webui/browser/answer-order.spec.ts b/webui/browser/answer-order.spec.ts index 5998cd644..d84ecf2c5 100644 --- a/webui/browser/answer-order.spec.ts +++ b/webui/browser/answer-order.spec.ts @@ -46,10 +46,11 @@ async function expectAnswerOrder(page: Page) { .toBeLessThan(texts.findIndex((text) => text.includes("Later answer"))); } -for (const width of [1440, 390]) { +test.describe("answer order", () => { + test.use({ viewport: { width: 1440, height: 1000 } }); + for (const path of ["callback", "cached return"] as const) { - test(`keeps closed answer order through ${path} and textless streams at ${width}px`, async ({ page }, info) => { - await page.setViewportSize({ width, height: 1000 }); + test(`keeps closed answer order through ${path} and textless streams`, async ({ page }, info) => { const { emit, errors } = await openThread(page); emit( { event: "goal_status", ...base, status: "running", started_at: 100 }, @@ -89,8 +90,7 @@ for (const width of [1440, 390]) { }); } - test(`keeps hosted-tool answer segments after a cached return at ${width}px`, async ({ page }) => { - await page.setViewportSize({ width, height: 1000 }); + test("keeps hosted-tool answer segments after a cached return", async ({ page }) => { const { emit, errors } = await openThread(page); emit( { event: "goal_status", ...base, status: "running", started_at: 100 }, @@ -117,36 +117,37 @@ for (const width of [1440, 390]) { expect(errors).toEqual([]); }); - test(`replays legacy cumulative answers on both sides of a hosted tool at ${width}px`, async ({ page }) => { - await page.setViewportSize({ width, height: 1000 }); - const { errors } = await openThread(page, [ - { event: "stream_end", ...base, stream_id: "legacy", turn_seq: 2, text: "First ", resuming: true, merge_next: true }, - { event: "message", ...base, turn_seq: 3, kind: "tool_hint", text: "web_search(query)" }, - { event: "stream_end", ...base, stream_id: "legacy", turn_seq: 5, text: "First last" }, - { event: "turn_end", ...base, turn_seq: 6 }, - ]); - const first = page.getByText("First", { exact: true }); - const last = page.getByText("last", { exact: true }); - await expect(first).toHaveCount(1); - await expect(last).toHaveCount(1); - await expect(page.getByRole("button", { name: "Stop response" })).toHaveCount(0); - // Completed activity is folded into the answer block, not lost or still running. - const lastBlock = last.locator("xpath=ancestor::*[@data-thread-display-unit]"); - await lastBlock.hover(); - await lastBlock.getByRole("button", { name: "Message actions" }).click(); - await page.locator("[data-message-block-activity-action]").click(); - const tool = page.getByText(/Searched the web/).first(); - await expect(tool).toBeVisible(); - const [firstNode, lastNode] = await Promise.all([first.elementHandle(), last.elementHandle()]); - expect(await tool.evaluate((node, [before, after]) => ( - !!(before.compareDocumentPosition(node) & Node.DOCUMENT_POSITION_FOLLOWING) - && !!(node.compareDocumentPosition(after) & Node.DOCUMENT_POSITION_FOLLOWING) - ), [firstNode!, lastNode!])).toBe(true); - expect(errors).toEqual([]); - }); + for (const width of [1440, 390]) { + test(`replays legacy cumulative answers on both sides of a hosted tool at ${width}px`, async ({ page }) => { + await page.setViewportSize({ width, height: 1000 }); + const { errors } = await openThread(page, [ + { event: "stream_end", ...base, stream_id: "legacy", turn_seq: 2, text: "First ", resuming: true, merge_next: true }, + { event: "message", ...base, turn_seq: 3, kind: "tool_hint", text: "web_search(query)" }, + { event: "stream_end", ...base, stream_id: "legacy", turn_seq: 5, text: "First last" }, + { event: "turn_end", ...base, turn_seq: 6 }, + ]); + const first = page.getByText("First", { exact: true }); + const last = page.getByText("last", { exact: true }); + await expect(first).toHaveCount(1); + await expect(last).toHaveCount(1); + await expect(page.getByRole("button", { name: "Stop response" })).toHaveCount(0); + // Completed activity is folded into the answer block, not lost or still running. + const lastBlock = last.locator("xpath=ancestor::*[@data-thread-display-unit]"); + await lastBlock.hover(); + await lastBlock.getByRole("button", { name: "Message actions" }).click(); + await page.locator("[data-message-block-activity-action]").click(); + const tool = page.getByText(/Searched the web/).first(); + await expect(tool).toBeVisible(); + const [firstNode, lastNode] = await Promise.all([first.elementHandle(), last.elementHandle()]); + expect(await tool.evaluate((node, [before, after]) => ( + !!(before.compareDocumentPosition(node) & Node.DOCUMENT_POSITION_FOLLOWING) + && !!(node.compareDocumentPosition(after) & Node.DOCUMENT_POSITION_FOLLOWING) + ), [firstNode!, lastNode!])).toBe(true); + expect(errors).toEqual([]); + }); + } - test(`keeps a rewritten image intact before a hosted tool at ${width}px`, async ({ page }, info) => { - await page.setViewportSize({ width, height: 1000 }); + test("keeps a rewritten image intact before a hosted tool", async ({ page }, info) => { const { emit, errors } = await openThread(page); await page.route("**/api/media/**", (route) => route.fulfill({ contentType: "image/png", body: Buffer.from( "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+j5hUAAAAASUVORK5CYII=", "base64", @@ -177,8 +178,7 @@ for (const width of [1440, 390]) { expect(errors).toEqual([]); }); - test(`resumes merge_next with cumulative HTTP snapshots at ${width}px`, async ({ page }) => { - await page.setViewportSize({ width, height: 1000 }); + test("resumes merge_next with cumulative HTTP snapshots", async ({ page }) => { const events: ThreadProjectionEvent[] = [ { event: "stream_end", ...base, stream_id: "answer", turn_seq: 2, text: "First ", resuming: true, merge_next: true, projection_id: "http-first" }, { event: "reasoning_end", ...base, stream_id: "answer", turn_seq: 3, text: "More reasoning", projection_id: "http-reasoning" }, @@ -199,4 +199,4 @@ for (const width of [1440, 390]) { await expect(page.getByText("First last", { exact: true })).toHaveCount(0); expect(errors).toEqual([]); }); -} +}); diff --git a/webui/browser/compaction-reasons.spec.ts b/webui/browser/compaction-reasons.spec.ts index 08662fecd..352828813 100644 --- a/webui/browser/compaction-reasons.spec.ts +++ b/webui/browser/compaction-reasons.spec.ts @@ -6,10 +6,20 @@ import type { ThreadProjectionEvent } from "../src/lib/types"; const reasons = ["idle", "context_pressure", "manual", "provider_native"] as const; const phases = ["started", "succeeded", "failed", "cancelled"] as const; -// Synthetic HTTP history and WebSocket delivery through the production client, -// projection, cache, and thread. No model/provider execution is involved. +const legacy: ThreadProjectionEvent = { event: "context_compaction", chat_id: "answer-order", + compaction_id: "legacy", phase: "succeeded", created_at_ms: 100, + projection_id: "legacy", turn_id: "legacy-turn", turn_seq: 1 }; +const samples = reasons.map((reason, index) => { + const start: ThreadProjectionEvent = { event: "context_compaction", chat_id: "answer-order", + compaction_id: reason, phase: "started", reason, + projection_id: `${reason}-start`, turn_id: `${reason}-turn`, turn_seq: 1 }; + const phase = phases[index === 3 ? 1 : index + 1]!; + return { reason, start, finish: { ...start, phase, projection_id: `${reason}-finish`, turn_seq: 2 } }; +}); + for (const { code } of supportedLocales) { - test(`compaction reasons survive live updates and session reentry in ${code}`, async ({ page }, info) => { + const lifecycle = code === "en"; + test(`${lifecycle ? "compaction reasons survive live updates and session reentry" : "localized compaction history fits the thread"} in ${code}`, async ({ page }, info) => { await page.setViewportSize({ width: 390, height: 900 }); const messages: typeof import("../src/i18n/locales/en/common.json") = JSON.parse( readFileSync(new URL(`../src/i18n/locales/${code}/common.json`, import.meta.url), "utf8"), @@ -18,9 +28,8 @@ for (const { code } of supportedLocales) { await page.addInitScript((locale) => localStorage.setItem("nanobot.locale", locale), code); const errors: string[] = []; page.on("pageerror", (error) => errors.push(error.message)); - let history: ThreadProjectionEvent[] = [{ event: "context_compaction", chat_id: "answer-order", - compaction_id: "legacy", phase: "succeeded", created_at_ms: 100, - projection_id: "legacy", turn_id: "legacy-turn", turn_seq: 1 }]; + const history: ThreadProjectionEvent[] = [legacy, + ...(lifecycle ? [] : samples.flatMap(({ start, finish }) => [start, finish]))]; await page.route("**/api/**", (route) => route.fulfill({ status: 404, json: {} })); await page.route("**/api/commands", (route) => route.fulfill({ json: { commands: [] } })); await page.route("**/api/sessions/*/webui-thread?*", (route) => route.fulfill({ json: { @@ -42,34 +51,33 @@ for (const { code } of supportedLocales) { await page.goto("/browser/fixture.html?case=answer-order"); await expect.poll(() => attached.has("answer-order")).toBe(true); const notices = page.locator("[data-context-compaction]"); - await expect(notices).toHaveCount(1); - await expect(notices.first()).toHaveText(copy.succeeded); - await expect(notices.first()).not.toHaveAttribute("role", "status"); - for (const [index, reason] of reasons.entries()) { - const start: ThreadProjectionEvent = { event: "context_compaction", chat_id: "answer-order", - compaction_id: reason, phase: "started", reason, - projection_id: `${reason}-start`, turn_id: `${reason}-turn`, turn_seq: 1 }; - socket.send(JSON.stringify(start)); - const notice = notices.nth(index + 1); - await expect(notices).toHaveCount(index + 2); - await expect(notice).toHaveText(copy.reasons[reason].started); - await expect(notice).toHaveAttribute("aria-busy", "true"); - const handle = await notice.elementHandle(); - const phase = phases[index === 3 ? 1 : index + 1]!; - const finish = { ...start, phase, projection_id: `${reason}-finish`, turn_seq: 2 }; - socket.send(JSON.stringify(finish)); - await expect(notice).toHaveText(copy.reasons[reason][phase]); - await expect(notice).toHaveAttribute("aria-busy", "false"); - expect(await notice.evaluate((node, original) => node === original, handle)).toBe(true); - await expect(notices).toHaveCount(index + 2); - history = [...history, start, finish]; + if (lifecycle) { + await expect(notices).toHaveCount(1); + await expect(notices.first()).toHaveText(copy.succeeded); + await expect(notices.first()).not.toHaveAttribute("role", "status"); + for (const [index, { reason, start, finish }] of samples.entries()) { + socket.send(JSON.stringify(start)); + const notice = notices.nth(index + 1); + await expect(notices).toHaveCount(index + 2); + await expect(notice).toHaveText(copy.reasons[reason].started); + await expect(notice).toHaveAttribute("aria-busy", "true"); + const handle = await notice.elementHandle(); + socket.send(JSON.stringify(finish)); + await expect(notice).toHaveText(copy.reasons[reason][finish.phase]); + await expect(notice).toHaveAttribute("aria-busy", "false"); + expect(await notice.evaluate((node, original) => node === original, handle)).toBe(true); + await expect(notices).toHaveCount(index + 2); + history.push(start, finish); + } + const text = await notices.allTextContents(); + await page.getByRole("button", { name: "Switch topic" }).click(); + await expect(notices).toHaveCount(0); + await page.getByRole("button", { name: "Switch topic" }).click(); + await expect(notices).toHaveText(text); + await page.reload(); + await expect(notices).toHaveText(text); } - const text = await notices.allTextContents(); - await page.getByRole("button", { name: "Switch topic" }).click(); - await expect(notices).toHaveCount(0); - await page.getByRole("button", { name: "Switch topic" }).click(); - await expect(notices).toHaveText(text); - await page.reload(); + const text = [copy.succeeded, ...samples.map(({ reason, finish }) => copy.reasons[reason][finish.phase])]; await expect(notices).toHaveText(text); await expect(page.locator('[data-context-compaction][role="status"]')).toHaveCount(0); for (const theme of ["light", "dark"]) { diff --git a/webui/browser/fixture.tsx b/webui/browser/fixture.tsx index 34859f72f..b44e8e82b 100644 --- a/webui/browser/fixture.tsx +++ b/webui/browser/fixture.tsx @@ -25,7 +25,6 @@ import "../src/globals.css"; import { DiagramFixture } from "./diagram-fixture"; import { TypographyFixture } from "./typography-fixture"; import { InlineReferencesFixture } from "./inline-references-fixture"; -import { MarkdownEmphasisFixture } from "./markdown-emphasis-fixture"; import { HistoryBoundaryFixture } from "./history-boundary-fixture"; import { ChatFailureFixture } from "./chat-failure-fixture"; import { ThreadLoadingFixture } from "./thread-loading-fixture"; @@ -252,8 +251,6 @@ createRoot(document.getElementById("root")!).render( ? : parameters.get("case") === "display-math" ? - : parameters.get("case") === "markdown-emphasis" - ? : parameters.get("case") === "typography" ? : parameters.get("case") === "inline-references" diff --git a/webui/browser/loaded-session-search-fixture.tsx b/webui/browser/loaded-session-search-fixture.tsx index 26a7e744c..fdbbb7ae1 100644 --- a/webui/browser/loaded-session-search-fixture.tsx +++ b/webui/browser/loaded-session-search-fixture.tsx @@ -1,14 +1,13 @@ -import { useEffect, useState } from "react"; +import { useState } from "react"; import { SessionSearchDialog } from "@/components/SessionSearchDialog"; import { useAppViewport } from "@/hooks/useAppViewport"; import { ThreadMessageCache } from "@/lib/thread-message-cache"; import { ThreadTranscript } from "@/lib/thread-transcript"; import type { ChatSummary } from "@/lib/types"; -const sessions: ChatSummary[] = Array.from({ length: 1000 }, (_, index) => ({ +const sessions: ChatSummary[] = Array.from({ length: 2 }, (_, index) => ({ key: `websocket:topic-${index}`, chatId: `topic-${index}`, channel: "websocket", title: `Topic ${index}`, preview: `Preview ${index}`, createdAt: null, updatedAt: null, - ...(index === 1 ? { handle: { id: "handle_00000000000000000000000000000001", name: "betu" } } : {}), })); export function LoadedSessionSearchFixture() { @@ -19,23 +18,11 @@ export function LoadedSessionSearchFixture() { const value = new ThreadMessageCache(() => false); value.set("topic-1", new ThreadTranscript([ { id: "user", role: "user", content: "我们讨论权限与配对", createdAt: 1 }, - { id: "answer", role: "assistant", content: `${"Earlier notes. ".repeat(500)}Use Full Access at 25% in session_history.py`, createdAt: 2 }, ]).save()); return value; }); - useEffect(() => { - const shortcut = (event: KeyboardEvent) => { - if ((event.ctrlKey || event.metaKey) && event.key.toLowerCase() === "k") { - event.preventDefault(); - setOpen(true); - } - }; - window.addEventListener("keydown", shortcut); - return () => window.removeEventListener("keydown", shortcut); - }, []); return
-