tests: time demo claim stage holds on the page's own clock
TestDemoClaimUXHeadlessFast390 failed on CI with stage 1 to 2 held 638.9 ms against 640 ms of allowance. The page held its 650 ms; the test timed each stage from when its MutationObserver callback ran, which a loaded worker delays by an arbitrary amount. The slack had already been widened twice for the same reason (#897). demo_claim.js now records each hold as data-stage-held on #claim-progress: the stage left, the performance.now() its hold counted from, and the reading as the next state shows. It changes nothing users see and no timing. The browser test asserts each hold from those readings at 650 - 1 ms (setTimeout drops the fraction of the delay) - 0.2 ms (two coarsened performance.now() readings), and still checks the stages show in order. The observer keeps only the stage order and the blank-frame check.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 files changed,
+52
−36
internal/console/static/demo_claim.js+7 −0internal/console/testdata/demo_claim_browser.mjs+31 −18internal/console/testdata/demo_claim_layout.mjs+14 −18
diff --git a/internal/console/static/demo_claim.js b/internal/console/static/demo_claim.js| index 209233e6e..33a1f14f4 100644 |
| --- a/internal/console/static/demo_claim.js |
| +++ b/internal/console/static/demo_claim.js |
| @@ -152,6 +152,10 @@ |
| let stage = Number(progress.dataset.stage), since = performance.now(), failures = 0; |
| const setStatus = text => { if (status.textContent !== text) status.textContent = text; }; |
| const hold = async () => { await wait(Math.max(0, minimum - (performance.now() - since))); }; |
| + // Records the stage being left, the clock reading its hold counted from |
| + // and now, the moment the next state shows. Only the browser tests read |
| + // it: they check the hold on the page's own clock. |
| + const held = () => { progress.dataset.stageHeld = `${stage} ${since} ${performance.now()}`; }; |
| // Reassurance while the server works. The bar is honest: each stage owns |
| // a band ending at the next stage's mark, and within it the bar eases |
| @@ -239,6 +243,7 @@ |
| timers.push(setInterval(draw, 500), setInterval(rotate, 4500)); |
| const setStage = async n => { |
| + held(); |
| stage = n; |
| entered = performance.now(); |
| shown = Math.max(shown, marks[Math.min(n, 3)]); |
| @@ -283,6 +288,7 @@ |
| for (const text of claim.querySelectorAll(".claim-open-address")) text.textContent = url.origin; |
| const address = claim.querySelector(".claim-address .claim-new"); |
| if (address) address.textContent = url.host; |
| + held(); |
| settle(); |
| heading.textContent = claim.dataset.completeHeading; |
| claim.dataset.state = "claimed"; |
| @@ -307,6 +313,7 @@ |
| (result.committed !== undefined && typeof result.committed !== "boolean")) throw new Error(); |
| if (result.state === "stopping" || result.state === "aborted") { |
| await hold(); |
| + held(); |
| settle(); |
| progress.querySelector(".claim-bar")?.remove(); |
| elapsed?.remove(); |
diff --git a/internal/console/testdata/demo_claim_browser.mjs b/internal/console/testdata/demo_claim_browser.mjs| index aa7aeba68..eae7967ca 100644 |
| --- a/internal/console/testdata/demo_claim_browser.mjs |
| +++ b/internal/console/testdata/demo_claim_browser.mjs |
| @@ -4,15 +4,35 @@ import {writeFile} from 'node:fs/promises'; |
| import {captureClaim, watchClaimCSP} from './demo_claim_layout.mjs'; |
| import {checkClaimMotion} from './demo_claim_motion.mjs'; |
| -// The page holds each stage, and a working button, for 650 ms by its own |
| -// timers. Chromium runs timers in whole milliseconds and coarsens |
| -// performance.now() (about 0.1 ms, with jitter), so a hold the page kept |
| -// can measure a little under 650 here: 649.8 ms on CI, and 648.5 ms on a |
| -// loaded CI worker later the same day (2026-11-11, #897). Ten milliseconds |
| -// of slack absorbs that. A page that skipped its hold would still come up |
| -// hundreds of milliseconds short, and one that shortened it noticeably |
| -// still fails. |
| -const heldAtLeast = 640; |
| +// The page holds each stage, and a working button, at least 650 ms by its |
| +// own timers. Each stage's hold is checked on the page's own clock: the page |
| +// records the reading its hold counted from and the reading as the next |
| +// state showed (data-stage-held). Timing the stages from a MutationObserver |
| +// here measured when the observer ran, which a loaded CI worker delays by an |
| +// arbitrary amount: 649.8 ms and 648.5 ms (2026-11-11, #897), then 638.9 ms |
| +// against 10 ms of slack (2026-11-19). What remains is the page's own |
| +// rounding: setTimeout drops the fraction of the delay the page asks for |
| +// (under 1 ms), and Chromium coarsens performance.now() to 100 µs with |
| +// jitter, under 0.1 ms on each of the two readings that do not cancel out. |
| +// The working button's hold is a whole 650 ms timer, bracketed by readings |
| +// taken before the submit and in it, so the same bound holds there. |
| +const minimum = 650; |
| +const heldAtLeast = minimum - 1 - 0.2; |
| + |
| +// assertHeld checks the page showed stages 1 to 4 in order and held each of |
| +// the first three for the minimum by its own clock. |
| +async function assertHeld() { |
| + const stages = await evaluate('window.claimStages'); |
| + const holds = await evaluate('window.claimHolds'); |
| + const report = JSON.stringify({stages, holds}); |
| + for (const stage of [1,2,3]) { |
| + const at = stages.indexOf(stage); |
| + assert(at >= 0 && stages[at+1] === stage+1, report); |
| + const hold = holds.find(row => row.stage === stage); |
| + assert(hold && Number.isFinite(hold.held), report); |
| + assert(hold.held >= heldAtLeast, report); |
| + } |
| +} |
| const [binary, profile, target, screenshots, expectedError] = process.argv.slice(2); |
| const chrome = spawn(binary, ['--headless', '--no-sandbox', '--disable-gpu', |
| @@ -172,13 +192,7 @@ async function runUX(scenes) { |
| } |
| if (scene.Name === 'fast') { |
| await until('document.getElementById("claim").dataset.state === "claimed"'); |
| - const stages = await evaluate('window.claimStageTimes'); |
| - for (const stage of [1,2,3]) { |
| - const a = stages.find(row => row.stage === stage); |
| - const b = stages.find(row => row.stage === stage+1); |
| - assert(a && b,JSON.stringify(stages)); |
| - assert(b.time-a.time >= heldAtLeast,JSON.stringify(stages)); |
| - } |
| + await assertHeld(); |
| assert.equal(await evaluate('window.claimBlankFrames'),0,'blank progress frame'); |
| await captureClaim(call,evaluate,screenshots,'live-done',[390,1280]); |
| await call('Page.reload'); |
| @@ -228,8 +242,7 @@ async function liveMotion(scene) { |
| } else { |
| assert.equal(await evaluate(`document.getAnimations().some(a=>a.animationName==='claim-burst')`),true); |
| } |
| - const stages = await evaluate('window.claimStageTimes'); |
| - for (const n of [1,2,3]) assert(stages.find(s=>s.stage===n+1).time-stages.find(s=>s.stage===n).time>=heldAtLeast,JSON.stringify(stages)); |
| + await assertHeld(); |
| assert.equal(await evaluate('window.claimBlankFrames'),0); |
| await new Promise(resolve=>setTimeout(resolve,450)); |
| if (screenshots) { |
diff --git a/internal/console/testdata/demo_claim_layout.mjs b/internal/console/testdata/demo_claim_layout.mjs| index 0d2ae4eeb..7eb01d9ca 100644 |
| --- a/internal/console/testdata/demo_claim_layout.mjs |
| +++ b/internal/console/testdata/demo_claim_layout.mjs |
| @@ -67,34 +67,30 @@ export async function captureClaim(call, evaluate, screenshots, state, widths = |
| export const watchClaimCSP = ` |
| window.claimCSPViolations = []; |
| - window.claimStageTimes = []; |
| + window.claimStages = []; |
| + window.claimHolds = []; |
| window.claimBlankFrames = 0; |
| document.addEventListener('DOMContentLoaded', () => { |
| const claim = document.getElementById('claim'); |
| const progress = document.getElementById('claim-progress'); |
| if (!progress) return; |
| - let last; |
| + // The order of the stages shown, not their timing: an observer runs |
| + // some time after the page changed, later the more loaded the machine, |
| + // so holds timed here came up short on CI (demo_claim_browser.mjs). |
| const record = () => { |
| const stage = claim.dataset.state === 'claimed' ? 4 : Number(progress.dataset.stage); |
| - if (stage === last) return; |
| - // The first stage is timed from when the document finished parsing |
| - // (domInteractive), which is always before the page's script starts |
| - // its own 650 ms clock. This event can fire after the page has |
| - // already painted and started that clock, and the first-paint entry |
| - // may not be posted yet, so timing from here, or from first paint |
| - // when it is missing, shorted the stage (644.9 ms and 648.4 ms on CI, |
| - // 2026-11-10/11). |
| - let time = performance.now(); |
| - if (last === undefined) { |
| - const nav = performance.getEntriesByType('navigation')[0]; |
| - const paint = performance.getEntriesByName('first-contentful-paint')[0]; |
| - time = Math.min(time, nav?.domInteractive || time, paint?.startTime ?? time); |
| - } |
| - window.claimStageTimes.push({stage,time}); |
| - last = stage; |
| + if (stage !== window.claimStages.at(-1)) window.claimStages.push(stage); |
| }; |
| record(); |
| new MutationObserver(record).observe(claim,{attributes:true,subtree:true,attributeFilter:['data-stage','data-state']}); |
| + // Each hold as the page timed it (data-stage-held, demo_claim.js): the |
| + // stage left, the clock reading its hold counted from, and the reading |
| + // as the next state showed. The page writes it once per change, at |
| + // least a hold apart, so each write gets its own callback. |
| + new MutationObserver(() => { |
| + const [stage, from, to] = progress.dataset.stageHeld.split(' ').map(Number); |
| + window.claimHolds.push({stage, from, to, held:to-from}); |
| + }).observe(progress,{attributes:true,attributeFilter:['data-stage-held']}); |
| const frame = () => { |
| const finished = document.getElementById('claim-finished'); |
| if (progress.getBoundingClientRect().height === 0 && (!finished || finished.getBoundingClientRect().height === 0)) window.claimBlankFrames++; |