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
+58 -1
View File
@@ -12,7 +12,7 @@
import test from 'node:test'
import assert from 'node:assert/strict'
import { createPlayer, namePlayer, sleep } from '../../tools/lib.mjs'
import { openAs } from '../../tools/withserver.mjs'
import { openAs, startServer, stopServer } from '../../tools/withserver.mjs'
import { writeTileGrid } from '../../tools/tilefixture.mjs'
import {
launchBrowser,
@@ -290,6 +290,63 @@ test('GM wall editor: presets, label, door, secret/locked, advanced, undo, drag
})
})
test('GM walls survive a reload and a server restart: drawn, selectable, door toggles',
{ timeout: 240000 }, async () => {
await withStack(async ({ origin, gmKey, stateDir, server }) => {
const { gm } = await worldWithPlayer(origin, gmKey)
const browser = await launchBrowser()
let restarted = null
try {
const { page, errors } = await gmPage(browser, origin, gmKey)
await drawPreset(page, 'wall', [2112, 1920], [2112, 2144])
await nextWall(gm, message => message.a[0] === 2112 && message.b[1] === 2144)
await drawPreset(page, 'door', [1920, 1920], [1920, 2144])
const door = await nextWall(gm, message => message.a[0] === 1920 && message.door === true)
await waitWalls(page, 2)
async function doorStillWorks(client) {
await waitWalls(page, 2)
await clickWorld(page, [1920, 2025])
await waitForText(page, '#wall-kind', /^door$/)
await page.click('#wall-open')
await nextWall(client, message => message.id === door.id && message.open === true)
await page.click('#wall-open')
await nextWall(client, message => message.id === door.id && message.open === false)
}
// Reload is the regression: the GM reconnects and must get the `walls` snapshot back in a
// shape the client accepts (DESIGN 6.1: scene on the frame, entries without it).
await page.reload()
await waitForVisible(page, '#stage canvas')
await waitForVisible(page, '#gm-walls')
await doorStillWorks(gm)
// Restart variant: same state dir, same port, nginx untouched. The client reconnects by
// itself and the same two walls must come back and stay editable.
restarted = await startServer({
stateDir,
port: server.port,
publicOrigin: server.publicOrigin ?? origin,
})
const gmAfter = await openAs(origin, gmKey)
await gmAfter.ws.waitText('hello')
await gmAfter.ws.waitText('walls')
try {
await waitWalls(page, 2, 60000)
await doorStillWorks(gmAfter)
} finally {
gmAfter.ws.close()
}
assert.deepEqual(errors, [])
await page.context().close()
} finally {
if (restarted) await stopServer(restarted)
await browser.close()
gm.ws.close()
}
})
})
async function fogState(page) {
return page.evaluate(() => {
const canvas = document.querySelector('#stage canvas')