A local-first multi-agent app development platform, built on PenguinHarness
test(web): wait for the resize's transition instead of its duration (7.18)
lmlihengd3bde8077d5e
diff --git a/packages/web/e2e/chat.spec.mjs b/packages/web/e2e/chat.spec.mjsindex a5f737ea..2702a690 100644--- a/packages/web/e2e/chat.spec.mjs+++ b/packages/web/e2e/chat.spec.mjs@@ -1,5 +1,6 @@import { test, expect } from "@playwright/test";import { provisionAndLogin } from "./auth.mjs";+import { settledTransitions } from "./settle.mjs";const BASE = process.env.BASE_URL;const MOCK = process.env.MOCK_URL;@@ -100,7 +101,11 @@ test("chat + tool approval + stats/cost/copy + traces + files", async ({ page })// stay expanded and the shrinkable stats row then painted its Token chip over that label.// Keep the status dot and the live stats, but their rendered boxes must remain disjoint.await page.setViewportSize({ width: 877, height: 438 });- await page.waitForTimeout(200);+ // The sidebar is `w-64 lg:w-72` with a 200 ms width transition, and 877 crosses the `lg` rung:+ // the toolbar's left content slides 32 px for the whole of that transition while its+ // right-aligned chips jump at once. A flat `waitForTimeout(200)` was exactly the transition's+ // own duration, so the boxes below could be read mid-slide. Wait for the transition instead.+ await settledTransitions(page);const runningStatus = page.locator('span[data-tooltip="运行中"]').filter({ hasText: "运行中" })@@ -117,7 +122,9 @@ test("chat + tool approval + stats/cost/copy + traces + files", async ({ page })Math.max(runningBox.x, tokenBox.x);expect(overlap, "running status and Token total do not overlap @877").toBeLessThanOrEqual(0);await page.setViewportSize({ width: 1280, height: 720 });- await page.waitForTimeout(200);+ // Same slide in reverse (256 → 288) — settle it before the clicks below re-find the work group+ // in the desktop layout.+ await settledTransitions(page);// The user takes control of the running work group (toggle = userToggled), keeps it open, and// opens the exec_command card to watch the arguments. Both must survive the end of the turn.//diff --git a/packages/web/e2e/settle.mjs b/packages/web/e2e/settle.mjsindex 70437082..f673dbf1 100644--- a/packages/web/e2e/settle.mjs+++ b/packages/web/e2e/settle.mjs@@ -13,7 +13,12 @@* - 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).+ * restore that *settled* 20 px short);+ * - a viewport resize: the sidebar is `w-64 lg:w-72` with `transition … width 0.2s`, so+ * 1280×900 → 877×438 crosses the `lg` rung and the column slides 288 → 256 over the full+ * 200 ms (280.39 → 273.34 → … → 256.11 → 256 measured once per frame), dragging the chat+ * toolbar's left content with it (the title's x 304 → 272) while the right-aligned chips jump+ * at once. A flat `waitForTimeout(200)` there sat exactly on the transition's own duration.** 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@@ -77,3 +82,51 @@ export async function settledBox(locator, { tolerance = 0.5, timeout = 10_000 }{ tolerance, timeout },);}++/**+ * Wait until the CSS transitions the last action started have finished — for the boxes that move+ * because something *else* changed width. The viewport-resize case is the reason this exists+ * (numbers in the file header): the sidebar is `w-64 lg:w-72` with a 0.2 s width transition, so+ * `setViewportSize({ width: 877 })` crosses the `lg` rung and the chat toolbar slides with it for+ * the whole 200 ms. `settledBox` cannot be trusted there: its first frames can both read the+ * *pre*-resize column while the transition is still in its easing head (288 → 280.39 after+ * ~50 ms), so "two frames that agree" would call that settled. A transition is a real signal, so+ * wait for exactly that instead of guessing the duration:+ *+ * - `document.getAnimations()` flushes style, so the resize's transition is already listed at the+ * call (measured: `width@aside` present with `currentTime 0` right after `setViewportSize`).+ * - Only `CSSTransition`s are awaited. `CSSAnimation`s are left alone on purpose: the running+ * label's pulse, the activity spinners and `anim-*` entrances either loop forever or belong to+ * the content, not to the layout this is about.+ * - A transition can only be finite, so this either returns or fails loudly at `timeout`; a+ * transition that keeps being restarted (a class toggling every frame) is a test bug worth+ * seeing, not something to wait out.+ */+export async function settledTransitions(page, { timeout = 10_000 } = {}) {+ await page.evaluate(async (timeout) => {+ const deadline = performance.now() + timeout;+ const running = () =>+ document+ .getAnimations()+ .filter((a) => a instanceof CSSTransition && a.playState === "running");+ // One frame first, so a transition started by the action lands in the list even when the+ // action only changed the style (a resize, a media query going over its rung).+ await new Promise((resolve) => requestAnimationFrame(resolve));+ for (;;) {+ const list = running();+ if (list.length === 0) return;+ if (performance.now() > deadline) {+ throw new Error(+ `settledTransitions: ${list.length} transition(s) still running after ${timeout} ms (` ++ list+ .map((a) => `${a.transitionProperty} on ${a.effect?.target?.tagName?.toLowerCase()}`)+ .join(", ") ++ ")",+ );+ }+ // `finished` rejects when a transition is cancelled (say, a second resize); that one is+ // gone, and the next pass reads whatever replaced it.+ await Promise.all(list.map((a) => a.finished.catch(() => {})));+ }+ }, timeout);+}