From 07949fb80d1e9a2cacb81d7992af9d52819754f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel?= Date: Sun, 22 Nov 2026 23:59:23 +0000 Subject: [PATCH] test(studio): the edit bench reads an undo once Studio says its reload is done (#8542) --- .../tests/e2e/edit-accuracy/sequences.mjs | 20 +++++++++++++++++-- .../tests/e2e/edit-accuracy/settle.test.mjs | 12 ++++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/packages/studio/tests/e2e/edit-accuracy/sequences.mjs b/packages/studio/tests/e2e/edit-accuracy/sequences.mjs index bb58cc735b..cb8ad7aeaa 100644 --- a/packages/studio/tests/e2e/edit-accuracy/sequences.mjs +++ b/packages/studio/tests/e2e/edit-accuracy/sequences.mjs @@ -469,6 +469,12 @@ export async function restedFor( throw new Error("an edit was still waiting or saving"); } +/** The box once Studio says the preview is done, and the ms until it said so: an undo's reload shows only then. */ +export async function shownOnceRested(busy, frame, settle, options) { + const shownMs = await restedFor(busy, frame, options); + return { box: await settle(), shownMs }; +} + // A sealed press waits for the previous save, then replays, and a sealed undo shows only once the preview applies it. const studioBusy = (page) => page.evaluate( @@ -610,7 +616,14 @@ async function measureSequence({ spec, dir, files, evidence }, session, control, ); // The file the steps should have left: the last surviving save's, or the original when all were undone. const expected = spec.settle ? (stack.at(-1)?.after ?? versions[0]) : versions.at(-1); - const undone = await settled(ctx.A); + const rested = () => + shownOnceRested( + () => studioBusy(page), + () => nextFrame(page), + () => settled(ctx.A), + ); + const undoneAt = await rested(); + const undone = undoneAt.box; await shoot("undone"); const redo = undo.ok ? await walk( @@ -624,7 +637,8 @@ async function measureSequence({ spec, dir, files, evidence }, session, control, history, ) : { ok: false, landed: [] }; - const redone = undo.ok ? await settled(ctx.A) : null; + const redoneAt = undo.ok ? await rested() : null; + const redone = redoneAt?.box ?? null; // A late write must not land under the reload. await waitForFiles(ctx.A, { timeout: 15_000 }); @@ -691,6 +705,8 @@ async function measureSequence({ spec, dir, files, evidence }, session, control, // The slowest write of each walk, judged by the single-case undo rule. ms: slowest(undo.writes), redoMs: slowest(redo.writes), + shownMs: undoneAt.shownMs, + redoShownMs: redoneAt?.shownMs ?? null, }, undoTimeout: saveFault([ ...undo.writes.map((w) => ["undo", w]), diff --git a/packages/studio/tests/e2e/edit-accuracy/settle.test.mjs b/packages/studio/tests/e2e/edit-accuracy/settle.test.mjs index ee8d652f3a..bf241e61ed 100644 --- a/packages/studio/tests/e2e/edit-accuracy/settle.test.mjs +++ b/packages/studio/tests/e2e/edit-accuracy/settle.test.mjs @@ -13,7 +13,7 @@ import { swapPending, unsettledBy, } from "./case.mjs"; -import { heldSize, keyedBy, restedFor } from "./sequences.mjs"; +import { heldSize, keyedBy, restedFor, shownOnceRested } from "./sequences.mjs"; describe("settling on the shown preview", () => { const read = (pending, x = 0, frames = "a") => ({ @@ -315,6 +315,16 @@ describe("the end of a sequence", () => { expect(await restedFor(busy, frame, { now })).toBe(20); }); + // fails without the fix: the undo was read while its reload was on the way, 240-329 px from where it landed. + it("reads an undo's box once Studio says its reload is done, and how long that took", async () => { + const { busy, frame, now, read } = reads([true, true, true, false, false]); + const settle = async () => (read() > 3 ? "undone" : "before"); + expect(await shownOnceRested(busy, frame, settle, { now })).toEqual({ + box: "undone", + shownMs: 30, + }); + }); + it("gives up with a reason when an edit never stops saving", async () => { const { busy, frame, now } = reads([true]); await expect(restedFor(busy, frame, { now, timeout: 30 })).rejects.toThrow(