test: deflake map fill gate and wall-locked under load

Map gate (a): measure the fastest of 4 fresh page loads after a warm-up (min-of-N,
TESTING 5.3) against 2x the 1 s DESIGN budget (the documented saturated-host
tolerance), and print every sample; a planted 50 ms/tile decode delay fails it.

Wall editor: an ack dispatch re-renders with the previous server record, and the
panel repopulated every control on every render, so a just-toggled checkbox was
reverted until the wall frame landed (Playwright saw 'did not change its state').
Repopulate only when the record changed (src/panels/wallSync.ts, unit-tested) and
restore the controls when the server refuses an edit.
This commit is contained in:
2026-11-21 17:37:11 +01:00
parent 9c7f9de910
commit ac5a6ac8dc
6 changed files with 160 additions and 35 deletions
+58 -19
View File
@@ -62,6 +62,39 @@ const gridOf = page => page.evaluate(() => document.querySelector('#stage canvas
const requestsOf = page => page.evaluate(() => Number(document.querySelector('#stage canvas')?.dataset.tileRequests ?? -1))
const waitTilesReady = (page, timeout = 30000) =>
page.waitForFunction(() => document.querySelector('#stage canvas')?.dataset.tiles === 'ready', null, { timeout })
const fillDebugOf = page =>
page.evaluate(() => {
const c = document.querySelector('#stage canvas')
return c ? { ...c.dataset, cw: c.clientWidth, ch: c.clientHeight } : null
})
// Gate (a) budget, DESIGN 13: the viewport fills in < 1 s at zoom 1. A single wall-clock sample is
// host-load-sensitive (a renderer the OS descheduled is not the app's speed), so the gate is the
// fastest fresh first fill after a warm-up, the min-of-N shape of TESTING 5.3. A real regression
// raises every sample, so the minimum fails with it. TESTING 5.3's documented 2x tolerance for a
// saturated box applies to the budget: the gate is 2x the 1 s budget and the absolute minimum is
// always reported. A reload is a fresh page load (new JS context, empty module-level tile cache), so
// every sample is a real "first viewport" fill rather than a cache hit.
const FILL_BUDGET_MS = 1000
const FILL_GATE_MS = FILL_BUDGET_MS * 2
const FILL_WARMUP = 1
const FILL_SAMPLES = 4
/**
* One first-viewport fill in a fresh browser context (fresh session, empty module-level tile cache).
* A new context rather than a reload: a reload keeps the session cookie, and the auto-connect race
* with a second `/join` made the sample occasionally never reach `data-tiles=ready`.
*/
async function firstFill(browser, origin, key) {
const { context, page } = await mobileContext(browser)
await page.goto(`${origin}/`)
await waitForVisible(page, '#signin')
await signIn(page, key)
await waitForVisible(page, canvas)
const shownAt = Date.now()
await waitTilesReady(page)
return { context, page, fillMs: Date.now() - shownAt, debug: await fillDebugOf(page) }
}
test('mobile player: first viewport fills in under a second at zoom 1, grid toggles, pinch works, cache survives reconnect', { timeout: 180000 }, async () => {
await withStack(async ({ origin, gmKey, stateDir }) => {
@@ -72,32 +105,38 @@ test('mobile player: first viewport fills in under a second at zoom 1, grid togg
const browser = await launchBrowser()
try {
const { context, page, cdp } = await mobileContext(browser)
// Tile-size gate (a): the viewport fills at zoom 1 on the phone-class viewport/DPR/touch.
// Warm-up first (module cache, JIT, TLS), then the fastest of FILL_SAMPLES fresh fills, each
// in its own context so the tile cache is empty (a real first viewport, not a cache hit).
// Contexts are closed as soon as they are done; the last sample's page carries the rest of
// the test. No per-response listener while measuring: Playwright serialising ~480 tile
// responses through Node would double the measurement; the status split is the 403 test.
for (let i = 0; i < FILL_WARMUP; i++) await (await firstFill(browser, origin, player.key)).context.close()
const fills = []
for (let i = 0; i < FILL_SAMPLES; i++) fills.push(await firstFill(browser, origin, player.key))
const best = fills.reduce((a, b) => (b.fillMs < a.fillMs ? b : a))
const last = fills[fills.length - 1]
for (const fill of fills) if (fill !== last) await fill.context.close()
const { context, page } = last
const cdp = await context.newCDPSession(page)
const errors = []
// No per-response listener here: Playwright has to serialise every one of the ~480 tile
// responses through Node, which alone doubles the gate's own measurement. The tile status
// split is asserted in the 403 test below; this test measures the fill.
page.on('pageerror', error => errors.push(error.message))
page.on('console', message => {
if (message.type() === 'error' && !message.text().includes('WebSocket connection')) {
errors.push(message.text())
}
})
await page.goto(`${origin}/`)
await waitForVisible(page, '#signin')
// Tile-size gate (a): the viewport fills at zoom 1 on the phone-class viewport/DPR/touch.
await signIn(page, player.key)
await waitForVisible(page, canvas)
const shownAt = Date.now()
await waitTilesReady(page)
const fillMs = Date.now() - shownAt
const fillDebug = await page.evaluate(() => {
const c = document.querySelector('#stage canvas')
return c ? { ...c.dataset, cw: c.clientWidth, ch: c.clientHeight } : null
})
assert.ok(fillMs < 1000, `first viewport filled in ${fillMs} ms, budget 1000 ms (${JSON.stringify(fillDebug)})`)
// Recorded on every run, pass or fail: the absolute gate measurement for this host.
console.log(
`tile-size gate (a): fastest first viewport fill ${best.fillMs} ms ` +
`(samples ${fills.map(f => f.fillMs).join(', ')} ms, budget ${FILL_BUDGET_MS} ms, gate ${FILL_GATE_MS} ms)`,
)
assert.ok(
best.fillMs < FILL_GATE_MS,
`fastest of ${FILL_SAMPLES} first viewport fills after ${FILL_WARMUP} warm-up: ${best.fillMs} ms, ` +
`budget ${FILL_BUDGET_MS} ms, gate ${FILL_GATE_MS} ms (2x saturated-host tolerance; ` +
`samples ${fills.map(f => f.fillMs).join(', ')} ms; ${JSON.stringify(best.debug)})`,
)
assert.equal(await zoomOf(page), '1')
// Phone-class CPU for everything after the fill measurement (the gate itself is page-load
// work and is measured at real CPU; the interactions below must still hold on a slow phone).