Skip to content

A local-first multi-agent app development platform, built on PenguinHarness

test(web): measure the docks and the pop-in panels once they stop moving (7.17)

lmliheng40620042d5c3
diff --git a/packages/web/e2e/dock.spec.mjs b/packages/web/e2e/dock.spec.mjs
index d798b9e2..306426e1 100644
--- a/packages/web/e2e/dock.spec.mjs
+++ b/packages/web/e2e/dock.spec.mjs
@@ -22,6 +22,7 @@
*/
import { test, expect } from "@playwright/test";
import { provisionAndLogin } from "./auth.mjs";
+import { settledBox } from "./settle.mjs";
const BASE = process.env.BASE_URL;
const MOCK = process.env.MOCK_URL;
@@ -232,17 +233,10 @@ test("full screen is a dock at its largest below the toolbar — by its button o
await openViaPicker(page, "right", "trace");
const right = dockAt(page, "right");
await expect(right.locator('[data-tab-id="trace"][data-active="true"]')).toBeVisible();
- // The composer measures the conversation column; wait out the dock's expand transition.
+ // The composer measures the conversation column; wait out the dock's expand transition (the
+ // column shrinks 746 → 428 as the 512 px panel arrives).
const composer = page.getByPlaceholder(/输入消息/);
- let settled = null;
- await expect
- .poll(async () => {
- const box = await composer.boundingBox();
- const same = settled !== null && box !== null && box.width === settled.width;
- settled = box;
- return same;
- })
- .toBe(true);
+ const settled = await settledBox(composer);
const rowBox = () => page.locator("[data-dock-row]").boundingBox();
const headerBox = (dock) => dock.getByTestId("dock-header").boundingBox();
@@ -403,8 +397,12 @@ test("sizes and the arrangement survive a reload; hidden stays hidden", async ({
const bottom = dockAt(page, "bottom");
await expect(bottom.locator('[data-tab-id="trace"][data-active="true"]')).toBeVisible();
- // Drag the bottom boundary up ~120px: the height ratio grows and persists.
- const before = (await bottom.boundingBox()).height;
+ // Drag the bottom boundary up ~120px: the height ratio grows and persists. Measured settled
+ // first: the dock is still sliding open when the tab turns visible (its own box, sampled every
+ // frame: 1 → 6.03 → 29.75 → 82.33 → 159.27 → … → 333.92 → 342.22 → 346.66 → 348 at ~289 ms), so
+ // a `before` read a round trip earlier could be a quarter of the real height — and the delta
+ // this assertion reads would then be the slide's own growth rather than the drag's.
+ const before = (await settledBox(bottom)).height;
const resizer = bottom.getByTestId("dock-resizer");
const rb = await resizer.boundingBox();
await page.mouse.move(rb.x + rb.width / 2, rb.y + rb.height / 2);
@@ -437,11 +435,13 @@ test("sizes and the arrangement survive a reload; hidden stays hidden", async ({
dockAt(page, "bottom").locator('[data-tab-id="trace"][data-active="true"]'),
).toBeVisible();
await expect(dockAt(page, "right")).toHaveCount(0);
- // Polled: the initial restore slides the dock in, so a one-shot measure can catch the
- // entrance transition mid-flight.
- await expect
- .poll(async () => Math.abs((await dockAt(page, "bottom").boundingBox()).height - after))
- .toBeLessThan(24);
+ // The initial restore slides the dock in (29.61 → 82.3 → 159.23 → … → 346.66 → 348, its last
+ // ~70 ms flat), so wait for it to arrive and then compare: the 24 px slack this used to carry
+ // let a restore still 21 px away — or one that settled that far short — read as "at its size".
+ // The 2 px is the settle helper's own tail: 0 in a normal run, 1.78 with the motion slowed 7×
+ // (measured in round 95), against 21.34 px of slack the old bound allowed.
+ const restored = await settledBox(dockAt(page, "bottom"));
+ expect(Math.abs(restored.height - after)).toBeLessThanOrEqual(2);
await page.getByTestId("dock-toggle-right").click();
await expect(
dockAt(page, "right").locator('[data-tab-id="workspace"][data-active="true"]'),
diff --git a/packages/web/e2e/layout.spec.mjs b/packages/web/e2e/layout.spec.mjs
index d09e4108..439379f0 100644
--- a/packages/web/e2e/layout.spec.mjs
+++ b/packages/web/e2e/layout.spec.mjs
@@ -40,6 +40,7 @@
*/
import { test, expect } from "@playwright/test";
import { provisionAndLogin } from "./auth.mjs";
+import { settledBox } from "./settle.mjs";
const BASE = process.env.BASE_URL;
const MOCK = process.env.MOCK_URL;
@@ -576,7 +577,9 @@ test("layout: mobile chat dropdowns stay inside the viewport", async ({ page })
/** Assert the one open menu panel and the page itself stay inside the viewport. */
const checkPanel = async (name) => {
await expect(panel, `${name}: menu open`).toHaveCount(1);
- await page.waitForTimeout(200); // let the pop-in scale animation settle before measuring
+ // The panel arrives with a 170 ms scale-in; measuring before it lands reads a smaller box in
+ // a shifted place — and `.anim-pop`'s duration is the panel's to change, not this spec's.
+ await settledBox(panel);
const m = await panel.evaluate((el) => {
const r = el.getBoundingClientRect();
// A horizontally scrolled ancestor is the old failure mode: the menu's autofocused
@@ -648,8 +651,7 @@ test("layout: mobile chat dropdowns stay inside the viewport", async ({ page })
const picker = page.getByRole("dialog", { name: "Choose model" });
await expect(picker, `model @${vp.width}: dialog open`).toBeVisible();
await page.getByRole("button", { name: /without a key/ }).click();
- await page.waitForTimeout(200); // let the pop-in animation settle before measuring
- const box = await picker.boundingBox();
+ const box = await settledBox(picker); // the dialog's own scale-in (see checkPanel)
expect(box.x, `model @${vp.width}: dialog left edge`).toBeLessThanOrEqual(0.5);
expect(box.width, `model @${vp.width}: dialog full width`).toBeGreaterThanOrEqual(vp.width - 1);
expect(box.y, `model @${vp.width}: dialog top edge`).toBeLessThanOrEqual(0.5);
@@ -668,8 +670,7 @@ test("layout: mobile chat dropdowns stay inside the viewport", async ({ page })
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();
+ const fb = await settledBox(finder); // the modal's own scale-in (see checkPanel)
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,
diff --git a/packages/web/e2e/settle.mjs b/packages/web/e2e/settle.mjs
new file mode 100644
index 00000000..70437082
--- /dev/null
+++ b/packages/web/e2e/settle.mjs
@@ -0,0 +1,79 @@
+/**
+ * "Read it once it has stopped moving" — the general form of the rail lesson (`rail.mjs`,
+ * round 94), for the boxes that animate rather than for the one column: measure a box that is
+ * still in flight and the number is true for that frame only, while whatever the assertion
+ * compares it with was placed at the settled layout.
+ *
+ * Sampled on the real page (`getBoundingClientRect()` once per animation frame, 1280×900):
+ *
+ * - the right dock opening: width 1 → 8.88 → 43.78 → 121.13 → … → 491.09 → 503.44 → 510 → 512
+ * in ~300 ms, and the conversation column beside it shrinks with it (composer 746 → 428);
+ * - the bottom dock opening into a fresh conversation: height 1 → 6.03 → 29.75 → 82.33 → 159.27 →
+ * … → 333.92 → 342.22 → 346.66 → 348, the last stretch reached at ~289 ms;
+ * - the restore of the same dock after a reload: the same slide (29.61 → 82.3 → … → 348), so a
+ * wait that stops at the first sample within 24 px of the target — the shape `dock.spec`
+ * carried — returns at 333.84, while the box is still moving (and would equally pass for a
+ * restore that *settled* 20 px short).
+ *
+ * A one-shot `boundingBox()` right after "the tab is visible" can land anywhere in that range —
+ * `boundingBox()` itself waits for the element to be attached, not for it to stop moving; so can
+ * a `waitForTimeout(200)` written beside a 170 ms pop-in, which stays true only while the
+ * animation's own duration does. Both are guesses about the motion. This waits for the motion to
+ * be over instead: two consecutive frames whose boxes agree within `tolerance` mean the element
+ * has arrived, however long it took. It does not promise the last pixel: an easing tail measured
+ * 1.78 px short under a 1.4 s slowed-down restore, so callers compare with a couple of pixels of
+ * slack rather than demanding equality.
+ *
+ * What it is NOT for: a box that keeps changing on its own (a streaming view re-rendering under
+ * the pointer). Such a box never agrees with itself and the call fails loudly at the timeout
+ * rather than hanging — that is the signal to assert something stable instead (see
+ * `path-hints.spec.mjs`, which reloads and reads the settled card).
+ */
+
+/**
+ * The box of `locator` once it has stopped moving, as `{ x, y, width, height }` (the same shape
+ * `boundingBox()` returns, so it can stand in for it). Rejects if the element is detached
+ * (zeros would otherwise look perfectly settled) or does not settle within `timeout` ms.
+ */
+export async function settledBox(locator, { tolerance = 0.5, timeout = 10_000 } = {}) {
+ return locator.evaluate(
+ (el, { tolerance, timeout }) =>
+ new Promise((resolve, reject) => {
+ const started = performance.now();
+ const read = () => {
+ const r = el.getBoundingClientRect();
+ return { x: r.x, y: r.y, width: r.width, height: r.height };
+ };
+ let previous = null;
+ const frame = () => {
+ if (!el.isConnected) {
+ reject(new Error("settledBox: the element left the DOM before it settled"));
+ return;
+ }
+ const box = read();
+ const still =
+ previous !== null &&
+ Math.abs(box.x - previous.x) <= tolerance &&
+ Math.abs(box.y - previous.y) <= tolerance &&
+ Math.abs(box.width - previous.width) <= tolerance &&
+ Math.abs(box.height - previous.height) <= tolerance;
+ if (still) {
+ resolve(box);
+ return;
+ }
+ if (performance.now() - started > timeout) {
+ reject(
+ new Error(
+ `settledBox: still moving after ${timeout} ms (last ${JSON.stringify(box)})`,
+ ),
+ );
+ return;
+ }
+ previous = box;
+ requestAnimationFrame(frame);
+ };
+ requestAnimationFrame(frame);
+ }),
+ { tolerance, timeout },
+ );
+}