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
+39
View File
@@ -0,0 +1,39 @@
// Wall-editor control synchronisation (#73, #76 deflake).
//
// Both a server `wall` frame and the editor's own dispatch (undo bookkeeping after an ack) re-render
// the panel. The panel must copy the server's record into its controls only when that record
// actually changed: the ack dispatch still carries the previous record, so repopulating from it
// would revert the checkbox the GM just toggled for the round trip until the `wall` frame lands.
// That revert is visible on a real connection and, on a slow host, can land before the browser has
// even observed the click (Playwright's `check` then fails as "did not change its state").
//
// Kept pure so the reducer-level test suite can pin it without a DOM.
import type { WallView } from '../slices/walls.ts'
export interface PopulatedWall {
id: number
signature: string
}
/** Every control `populate` writes, in a fixed order: the record, not its object identity. */
export function wallFieldsSignature(wall: WallView): string {
const s = wall.switches
return JSON.stringify([
wall.id,
wall.label,
s.blocksSight,
s.blocksMovement,
s.sightDir,
s.playerMarker,
s.door,
s.open,
s.secret,
s.locked,
])
}
/** True when the panel's controls no longer match the server record and must be repopulated. */
export function shouldPopulate(populated: PopulatedWall | null, wall: WallView): boolean {
return populated === null || populated.id !== wall.id || populated.signature !== wallFieldsSignature(wall)
}
+21 -10
View File
@@ -17,6 +17,8 @@ import { sendIntent } from '../intents.ts'
import type { WallView } from '../slices/walls.ts'
import { restoreOf, selectedWallOf, undoOf, wallsOf } from '../slices/walls.ts'
import type { SightDir, WallPreset, WallSwitches, WallUndo } from '../wallEditor.ts'
import type { PopulatedWall } from './wallSync.ts'
import { shouldPopulate, wallFieldsSignature } from './wallSync.ts'
import {
PRESETS,
buildAddFields,
@@ -225,7 +227,8 @@ export function mountWallPanel(
let armed = false
let first: Vec2 | null = null
let snapEnabled = true
let populatedFor = -1
/** The server record last copied into the controls (id + field signature), or null. */
let populated: PopulatedWall | null = null
let advancedOpen = false
/** The last rendered wall record, so a field edit uses exactly what the GM saw. */
let shown: WallView | null = null
@@ -371,7 +374,7 @@ export function mountWallPanel(
// Clearing `door` is the one patch that also closes/de-secrets server-side (6.1), so it is sent
// alone rather than as a contradictory full switch set.
if (key === 'door' && value === false) {
await patch({ door: false }, prior)
if (!(await patch({ door: false }, prior))) populate(prior)
return
}
const merged = mergedSwitches({ [key]: value } as Partial<WallSwitches>)
@@ -396,6 +399,9 @@ export function mountWallPanel(
flags: { ...prior.flags },
},
})
} else {
// The server refused: put the control back to the record the GM last saw.
populate(prior)
}
}
@@ -585,7 +591,7 @@ export function mountWallPanel(
armed = false
first = null
shown = null
populatedFor = -1
populated = null
root.hidden = true
selected.hidden = true
setError(null)
@@ -596,7 +602,7 @@ export function mountWallPanel(
}
if (!active) {
active = true
populatedFor = -1
populated = null
}
root.hidden = false
@@ -604,15 +610,15 @@ export function mountWallPanel(
shown = wall
if (wall === null) {
selected.hidden = true
populatedFor = -1
populated = null
undoButton.textContent = undoLabel(undoOf(state))
undoButton.disabled = undoOf(state) === null
return
}
selected.hidden = false
selectedTitle.textContent = `${wall.kind}`
if (populatedFor !== wall.id) {
populatedFor = wall.id
if (populated?.id !== wall.id) {
populated = null
advancedOpen = false
advanced.hidden = true
advancedToggle.setAttribute('aria-expanded', 'false')
@@ -620,9 +626,14 @@ export function mountWallPanel(
unlockButton.hidden = true
setError(null)
}
// Do not overwrite a field the GM is typing in; the server's record still drives every other
// control and the derived kind.
if (document.activeElement !== labelInput.node) populate(wall)
// Repopulate only when the server record changed: an ack dispatch carries the previous record
// and must not undo the switch the GM just made while the authoritative frame is in flight.
// Do not overwrite a field the GM is typing in either; the server's record still drives every
// other control and the derived kind.
if (shouldPopulate(populated, wall) && document.activeElement !== labelInput.node) {
populate(wall)
populated = { id: wall.id, signature: wallFieldsSignature(wall) }
}
kindHint.textContent = `Derived kind: ${wall.kind}`
openButton.textContent = wall.switches.open ? 'Close door' : 'Open door'
openButton.disabled = !wall.switches.door