From d617b723aaf0c8b842fac95f058714844e1f370f Mon Sep 17 00:00:00 2001 From: chengyongru <61816729+chengyongru@users.noreply.github.com> Date: Wed, 21 Oct 2026 15:10:09 +0800 Subject: [PATCH] test(webui): respect history top-edge tolerance (#6362) * fix(webui): wait for native scrolling before loading history * test(webui): align loading checks with the top-edge tolerance --- webui/browser/history-boundary.spec.ts | 32 +++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/webui/browser/history-boundary.spec.ts b/webui/browser/history-boundary.spec.ts index 18420d6df..2bbade887 100644 --- a/webui/browser/history-boundary.spec.ts +++ b/webui/browser/history-boundary.spec.ts @@ -199,9 +199,16 @@ async function expectHeaderInsideSlot(body: Locator) { async function expectHeld(body: Locator, text: string) { await expect(body.locator(".thread-history-slot")).toHaveCSS("height", "48px"); await expect.poll(() => displacement(body)).toBe(0); - await expect.poll(async () => (await historyGeometry(body, text)).visibleHeight).toBeCloseTo(48, 0); + let held = await historyGeometry(body, text); + // The runtime accepts <=1px as the top; account for that actual scroll, not extra clipping. + await expect.poll(async () => { + held = await historyGeometry(body, text); + return held.visibleHeight + held.scrollTop; + }).toBeCloseTo(48, 0); + expect(held.scrollTop).toBeGreaterThanOrEqual(0); + expect(held.scrollTop).toBeLessThanOrEqual(1); await expectHeaderInsideSlot(body); - return historyGeometry(body, text); + return held; } function expectSameScroll(before: HistoryGeometry, after: HistoryGeometry, delta: number) { @@ -921,6 +928,25 @@ test("cross-path older errors never float after latest or a loaded rail jump, bu }); +test("loading retains its slot and reading anchor at the tolerated top pixel", async ({ page }) => { + const history = await installHistory(page); + const { body, header } = await openSettledHistory(page); + // Home can reach the existing <=1px boundary before its native scroll reaches zero. + await body.evaluate((node) => { + node.dispatchEvent(new PointerEvent("pointerdown", { bubbles: true, button: 0 })); + node.scrollTop = 1; + node.dispatchEvent(new Event("scroll")); + }); + await expect.poll(() => history.reads.length).toBe(1); + await expect(header).toHaveAttribute("data-state", "loading"); + const held = await expectHeld(body, "Question 40"); + expect(held.scrollTop).toBe(1); + expect(held.visibleHeight).toBeCloseTo(47, 0); + expect(held.headerTop).toBeCloseTo(held.frameTop - 1, 0); + await completePrepend(history, body, "Question 28", "Question 40", held.anchorTop); +}); + + test("bounded navigation retains three pages and reclaims each completed wheel or keyboard boundary slot", async ({ page }) => { const history = await installHistory(page); await page.setViewportSize({ width: 1440, height: 900 }); @@ -1022,7 +1048,7 @@ test("bounded navigation retains three pages and reclaims each completed wheel o await expect(header).toHaveAttribute("data-state", "loading"); const keyboardHeld = await expectHeld(body, "Question 2"); expect(keyboardHeld.slotBeforeKey).toBe("u2"); - expect(keyboardHeld.anchorTop - atKeyboardHead.anchorTop - atKeyboardHead.scrollTop).toBeCloseTo(48, 0); + expect(keyboardHeld.anchorTop - atKeyboardHead.anchorTop - atKeyboardHead.scrollTop + keyboardHeld.scrollTop).toBeCloseTo(48, 0); history.complete(); await expect(body.getByText("Question 0", { exact: true })).toBeAttached(); await stableLayout(body);