refactor: remove redundant comments and docstrings (#6527)
* refactor: remove redundant comments and docstrings * fix(signal): annotate async context manager as a generator
This commit is contained in:
1 parent
cb3ba45317
commit
a4d2430140
922 files changed
+406
-7738
No files matched your search
@@ -1,6 +1,5 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
|
||||
// Opaque and transparent artwork exercise both common brand-image layouts offline.
|
||||
const tile = '<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32"><rect width="32" height="32" fill="#171717"/><circle cx="16" cy="16" r="10" fill="white"/></svg>';
|
||||
const mark = '<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32"><circle cx="16" cy="16" r="12" fill="#E87D0D"/></svg>';
|
||||
|
||||
|
||||
@@ -6,8 +6,6 @@ import { NanobotClient } from "@/lib/nanobot-client";
|
||||
import { ThreadMessageCache } from "@/lib/thread-message-cache";
|
||||
import { ClientProvider } from "@/providers/ClientProvider";
|
||||
|
||||
// The browser spec controls HTTP and WebSocket frames; all projection and caching
|
||||
// run through the real client and thread, without model calls or saved user data.
|
||||
export function AnswerOrderFixture() {
|
||||
const [client] = useState(() => new NanobotClient({
|
||||
url: `ws://${location.host}/answer-order-socket`, reconnect: false,
|
||||
|
||||
@@ -156,7 +156,6 @@ test.describe("answer order", () => {
|
||||
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();
|
||||
|
||||
@@ -7,7 +7,6 @@ import { useLocalPreferences } from "@/hooks/useLocalPreferences";
|
||||
import { ThemeProvider, useTheme } from "@/hooks/useTheme";
|
||||
import { readLocalPreferences, writeLocalPreferences, type LocalPreferences } from "@/lib/local-preferences";
|
||||
|
||||
/** Actual appearance controls in a browser-local harness, without a gateway. */
|
||||
export function AppearanceFixture() {
|
||||
const { t } = useTranslation();
|
||||
const { theme, preference, setTheme } = useTheme();
|
||||
|
||||
@@ -49,7 +49,6 @@ async function expectFileDetails(page: Page, card: Locator, filename: string, wi
|
||||
for (const width of [1024, 360]) {
|
||||
for (const theme of ["light", "dark"]) {
|
||||
test(`mixed attachments stay compact, aligned and readable at ${width}px in ${theme}`, async ({ page }, testInfo) => {
|
||||
// The two widths also cover both localized download names, without a second matrix.
|
||||
const chinese = width === 360;
|
||||
await page.route("**/fixture/retry.webm", (route) => route.fulfill({ status: 503, body: "Temporarily unavailable" }));
|
||||
await openAttachments(page, width, theme, chinese ? "zh-CN" : "en");
|
||||
|
||||
@@ -17,7 +17,6 @@ const messages: UIMessage[] = [{
|
||||
createdAt: 1_700_000_000_000,
|
||||
}];
|
||||
|
||||
// Real components with controlled state. No model calls or saved user data.
|
||||
export function ChatFailureFixture({ parameters }: { parameters: URLSearchParams }) {
|
||||
useReadingTypography();
|
||||
const [visible, setVisible] = useState(true);
|
||||
|
||||
@@ -72,7 +72,6 @@ for (const width of [1440, 390]) {
|
||||
const imageBox = (await image.boundingBox())!;
|
||||
expect(imageBox.y + imageBox.height).toBeLessThan(bubbleBox.y);
|
||||
if (width === 390) {
|
||||
// Narrow screens use a touch action row below the message, not a hover rail.
|
||||
await expect(page.locator("[data-message-mobile-actions]")).toBeVisible();
|
||||
expect(triggerBox.y).toBeGreaterThanOrEqual(bubbleBox.y + bubbleBox.height);
|
||||
expect(triggerBox.height).toBeGreaterThanOrEqual(44);
|
||||
|
||||
@@ -48,7 +48,6 @@ for (const width of [1280, 390]) {
|
||||
expect(await action.boundingBox()).toEqual(bounds);
|
||||
expect(await model.boundingBox()).toEqual(modelBounds);
|
||||
|
||||
// Reverse mid-transition, then send before the new icon has settled.
|
||||
await input.fill("");
|
||||
await input.fill("A newer draft");
|
||||
await action.click();
|
||||
|
||||
@@ -175,7 +175,6 @@ test("an enlarged diagram keeps its camera through resize and recoloring", async
|
||||
await expect(dialog).toBeVisible();
|
||||
await expect(fit).toHaveText("150%");
|
||||
await expect(dialog.locator("img")).toHaveAttribute("src", before!);
|
||||
// Change the trusted document palette without closing the reader.
|
||||
await page.evaluate(() => document.documentElement.classList.toggle("dark"));
|
||||
await expect(dialog.locator("img")).not.toHaveAttribute("src", before!);
|
||||
await expect(fit).toHaveText("150%");
|
||||
|
||||
@@ -22,7 +22,6 @@ for (const width of [360, 1024]) {
|
||||
const longPath = references.first();
|
||||
await expect(longPath).toContainText("…");
|
||||
await expect(references.nth(1)).not.toContainText("…");
|
||||
// The last filename stays inside the clipping viewport, without reversing text direction.
|
||||
const filename = longPath.locator(".font-semibold");
|
||||
await expect(filename).toHaveCSS("color", "rgb(3, 105, 161)");
|
||||
const tail = await filename.evaluate((element) => {
|
||||
|
||||
@@ -289,7 +289,6 @@ test("wheel loading hands off to a retained 48px slot; prepend and delayed layou
|
||||
await expect(body.locator(".thread-history-slot")).toHaveCount(0);
|
||||
await page.screenshot({ path: test.info().outputPath("history-prepend-stable.png") });
|
||||
|
||||
// The reclaimed boundary scrolls as ordinary message flow, with no retained spacer.
|
||||
const beforeScroll = await body.evaluate((node) => node.scrollTop);
|
||||
const anchorBeforeScroll = await anchorTop(body, "Question 40");
|
||||
await body.hover();
|
||||
@@ -953,7 +952,6 @@ test("failed Blocks animate without visible error text; pulling retries once and
|
||||
await expectCoordinates(body, "Question 40", held);
|
||||
expect(history.reads).toHaveLength(1);
|
||||
|
||||
// This is a fresh pull at the failed boundary, not a ready-button-only path.
|
||||
await requestOlderWithWheel(body, history, 2);
|
||||
await expect(header).toHaveAttribute("data-state", "loading");
|
||||
await page.mouse.wheel(0, -120);
|
||||
@@ -1127,7 +1125,6 @@ test("bounded navigation retains three pages and reclaims each completed wheel o
|
||||
const header = page.locator(".thread-history-status");
|
||||
const slot = body.locator(".thread-history-slot");
|
||||
const approachNextHead = async (text: string) => {
|
||||
// Real scrolling stops just short of the boundary, before it can request.
|
||||
const scrollTop = await body.evaluate((node) => node.scrollTop);
|
||||
expect(scrollTop).toBeGreaterThan(120);
|
||||
await body.hover();
|
||||
@@ -1145,7 +1142,6 @@ test("bounded navigation retains three pages and reclaims each completed wheel o
|
||||
await stableLayout(body);
|
||||
expect(history.reads).toHaveLength(0);
|
||||
|
||||
// An unloaded rail destination replaces latest with P0 (38..49).
|
||||
await jumpViaRail(page, 38);
|
||||
await expect.poll(() => history.reads.length).toBe(1);
|
||||
history.complete();
|
||||
@@ -1162,7 +1158,6 @@ test("bounded navigation retains three pages and reclaims each completed wheel o
|
||||
expect((await historyGeometry(body, "Question 38")).slotBeforeKey).toBeNull();
|
||||
await expect(body.locator('[data-thread-display-unit^="u"]')).toHaveCount(24);
|
||||
|
||||
// Reach each prepended page head instead of loading from the old reading slot.
|
||||
const atSecondHead = await approachNextHead("Question 26");
|
||||
expect(atSecondHead.firstKey).toBe("u26");
|
||||
expect(atSecondHead.slotBeforeKey).toBeNull();
|
||||
@@ -1177,7 +1172,6 @@ test("bounded navigation retains three pages and reclaims each completed wheel o
|
||||
expect((await historyGeometry(body, "Question 26")).slotBeforeKey).toBeNull();
|
||||
await expect(body.locator('[data-thread-display-unit^="u"]')).toHaveCount(36);
|
||||
|
||||
// Completed feedback is removed and cannot add a fourth cached page.
|
||||
await expect(header).toHaveCount(0);
|
||||
await stableLayout(body);
|
||||
await expect(page.getByText("No earlier messages", { exact: true })).toHaveCount(0);
|
||||
@@ -1209,7 +1203,6 @@ test("bounded navigation retains three pages and reclaims each completed wheel o
|
||||
await expect(page.getByText("No earlier messages", { exact: true })).toHaveCount(0);
|
||||
expect(history.reads).toEqual(["?limit=24&after=38", "?limit=24&before=38", "?limit=24&before=26", "?limit=24&before=14"]);
|
||||
|
||||
// A real Home key reaches the next boundary and rebinds without a wheel pull.
|
||||
const atKeyboardHead = await approachNextHead("Question 2");
|
||||
expect(atKeyboardHead.firstKey).toBe("u2");
|
||||
expect(atKeyboardHead.slotBeforeKey).toBeNull();
|
||||
|
||||
@@ -15,7 +15,6 @@ const sessions: ChatSummary[] = ["a", "b"].map((suffix) => ({
|
||||
preview: "",
|
||||
}));
|
||||
|
||||
// Synthetic backend-boundary reproduction, not an original user recording.
|
||||
export function HistoryHydrationFixture() {
|
||||
const [client] = useState(() => new NanobotClient({
|
||||
url: `${location.protocol === "https:" ? "wss:" : "ws:"}//${location.host}/nan311-fixture-ws`,
|
||||
|
||||
@@ -2,8 +2,6 @@ import { expect, test, type Locator, type Page, type Route, type WebSocketRoute
|
||||
|
||||
import type { InboundEvent, ThreadProjectionEvent, UITurnPhase, WebuiThreadPersistedPayload } from "../src/lib/types";
|
||||
|
||||
// Controlled synthetic backend traffic, not a replay of an original user recording.
|
||||
// Every body assertion goes through the real socket/client/provider/ThreadShell path.
|
||||
const A = "nan311-a";
|
||||
const B = "nan311-b";
|
||||
const TURN = "nan311-active-turn";
|
||||
@@ -81,7 +79,6 @@ async function installBackend(page: Page) {
|
||||
const url = new URL(route.request().url());
|
||||
reads.push({ chatId: decodeURIComponent(url.pathname.split("/")[3]!).slice("websocket:".length),
|
||||
before: url.searchParams.get("before"), after: url.searchParams.get("after"), route });
|
||||
// Deliberately leave this request pending until the test releases this exact page.
|
||||
});
|
||||
await page.routeWebSocket((url) => url.pathname === "/nan311-fixture-ws", (wire) => {
|
||||
socket = wire;
|
||||
|
||||
@@ -46,7 +46,6 @@ test("complete rail scrolls independently, jumps to unloaded history and returns
|
||||
await expect.poll(() => rail.evaluate((node) => node.scrollTop)).toBeLessThan(25000);
|
||||
expect(await body.evaluate((node) => node.scrollTop)).toBe(initialBodyTop);
|
||||
expect(await rail.getByRole("button").count()).toBeLessThan(70);
|
||||
// Keyboard navigation reaches the beginning without mounting the whole list.
|
||||
await rail.getByRole("button").first().focus();
|
||||
await page.keyboard.press("Home");
|
||||
const first = rail.getByRole("button", { name: "Jump to message: Question 0", exact: true });
|
||||
@@ -72,7 +71,6 @@ test("complete rail scrolls independently, jumps to unloaded history and returns
|
||||
await expect(rail.locator('[aria-current="location"]')).toBeInViewport();
|
||||
expect(await rail.evaluate((node) => getComputedStyle(node).maskImage)).toContain("linear-gradient");
|
||||
await page.screenshot({ path: "test-results/prompt-rail-long.png" });
|
||||
// Short lists remain centered in the same viewport-relative space.
|
||||
await page.goto("/browser/fixture.html?case=rail&short=1&workbench=1");
|
||||
const markers = page.getByTestId("prompt-rail-marker");
|
||||
await expect(markers).toHaveCount(5);
|
||||
@@ -81,7 +79,6 @@ test("complete rail scrolls independently, jumps to unloaded history and returns
|
||||
const middle = await markers.nth(2).boundingBox();
|
||||
expect(Math.abs(middle!.y + middle!.height / 2 - (bounds!.y + bounds!.height / 2))).toBeLessThan(2);
|
||||
await page.screenshot({ path: "test-results/prompt-rail-short.png" });
|
||||
// A taller composer in a shorter window must not push navigation above center.
|
||||
await page.setViewportSize({ width: 1440, height: 640 });
|
||||
await page.goto("/browser/fixture.html?case=rail&short=1&tall-composer=1&workbench=1");
|
||||
await expect(markers).toHaveCount(5);
|
||||
|
||||
@@ -122,7 +122,6 @@ for (const width of [1440, 390]) {
|
||||
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();
|
||||
|
||||
@@ -152,7 +152,6 @@ for (const width of [1440, 390]) {
|
||||
expect(middle.paint[index], `${selector} must not snap to the target palette`).not.toBe(after[index]);
|
||||
expect(middle.paint[index], `${selector} must leave the old palette`).not.toBe(before[index]);
|
||||
}
|
||||
// These in-flow wrappers now reveal their painted parent instead of adding a second canvas.
|
||||
expect(middle.footer).toBe("rgba(0, 0, 0, 0)");
|
||||
expect(middle.sidebarFooter).toBe("rgba(0, 0, 0, 0)");
|
||||
expect(middle.gradient).toBe(middle.paint[0]);
|
||||
@@ -216,7 +215,6 @@ for (const width of [1440, 390]) {
|
||||
await expect(toggle).toBeFocused();
|
||||
expect(await input.boundingBox()).toEqual(box);
|
||||
await page.screenshot({ path: test.info().outputPath(`crossfade-${width}-${initial}-mid.png`), animations: "allow" });
|
||||
// Keyboard input still reaches the live DOM while the native snapshots are paused.
|
||||
await page.keyboard.press("Space");
|
||||
for (let step = 0; step < 20 && !await input.evaluate(node => node === document.activeElement); step++) {
|
||||
await page.keyboard.press("Tab");
|
||||
|
||||
Reference in new issue
Block a user