fix(client): read walls snapshot with the frame scene (#87)

The snapshot is {t:'walls', scene, walls:[{id, a, b, ...}]} per DESIGN 6.1:
scene lives on the frame, entries carry only the wall record. The client
required scene on each entry and dropped every snapshot wall, so a GM
reload/reconnect showed canvas.dataset.walls==='0' while the server still
blocked player sight.

Pass the enclosing frame's scene into wallViewFromFrame and keep an entry's
own scene as the tolerant fallback. The server already matched DESIGN, so
no wall wire shape changed.

Tests: client reducer from a real snapshot frame, WS pin that a snapshot
entry equals a wall delta record, and e2e reload plus server-restart.
The old e2e missed it because every wall test built walls in-session.
This commit is contained in:
2026-11-21 23:44:37 +01:00
parent 7379d450d5
commit b938e6f256
4 changed files with 144 additions and 8 deletions
+38
View File
@@ -111,6 +111,44 @@ test('wall.add: the typed record, raw-switch defaults and the derived kind', asy
})
})
test('walls snapshot entries have the same wall-record shape as a wall delta (6.1)', async () => {
await withGmServer(async (s, gmKey) => {
const gm = await gmConnect(s.origin, gmKey)
const plain = await addWall(gm, { a: [10, 10], b: [400, 10], thickness: 8,
position: 'right', height: 2.5, label: 'railing',
flags: { side: 'north' } })
const door = await addWall(gm, { a: [10, 300], b: [400, 300], door: true })
assert.equal((await gm.ws.request({ t: 'door.set', scene: gm.scene, id: door.id,
open: true })).ok, true)
const deltas = new Map()
deltas.set(plain.id, await wallEffect(gm.ws, m => m.t === 'wall' && m.id === plain.id))
deltas.set(door.id, await wallEffect(gm.ws, m => m.t === 'wall' && m.id === door.id &&
m.open === true))
// A second GM connection is the reload/reconnect: the server sends the `walls` snapshot.
const reload = await openAs(s.origin, gmKey)
await reload.ws.waitText('hello')
const snap = await reload.ws.waitText('walls')
assert.equal(snap.scene, gm.scene, 'the frame carries the scene')
assert.equal(typeof snap.n, 'number', 'the frame carries its own n')
assert.deepEqual(snap.walls.map(w => w.id), [plain.id, door.id])
const wallKeys = [...WALL_FIELDS].sort()
for (const entry of snap.walls) {
// DESIGN 6.1: `scene` sits on the `walls` frame; the entry is exactly the wall record a
// `wall` delta carries beside its frame-level `t`/`scene`/`n`.
assert.ok(!('scene' in entry), `a walls entry carries scene: ${JSON.stringify(entry)}`)
assert.deepEqual(Object.keys(entry).sort(), wallKeys)
const delta = deltas.get(entry.id)
const record = Object.fromEntries(
Object.entries(delta).filter(([key]) => !['t', 'scene', 'n'].includes(key)),
)
assert.deepEqual(entry, record, `snapshot and delta disagree for wall ${entry.id}`)
}
reload.ws.close(); gm.ws.close()
})
})
test('wall ids: monotonic per scene and never reused after removal', async () => {
await withGmServer(async (s, gmKey) => {
const gm = await gmConnect(s.origin, gmKey)