feat(walls): proto 2 typed wall record, inert geometry, derived kind (#54)
wall.add/wall.update take thickness, position, height and the eight raw switches; kind is output-only and the GM wall frames echo the full typed record. Geometry is stored but inert (0/full/centre behaviour), and the legacy kind/open wire adapter is gone. proto is bumped to 2 with the harness default, and BannedAlways gains every wall field name with a WALLDATA positive control. Tests: schema-7 migrated scene vs the same walls authored via raw switches gives byte-identical player frames, refusals and per-tile statuses. Nim 382 / Node 113 green.
This commit is contained in:
+188
-78
@@ -1,15 +1,14 @@
|
||||
// M3 slice 4 (#19): walls and doors. Black-box through the real binary (withserver): the GM
|
||||
// `walls` snapshot, wall.add/wall.update/wall.remove and door.set with their 6.5 acks and GM-only
|
||||
// effects, the per-scene never-reused wall ids, the 6.1 validation table, "no wall data reaches a
|
||||
// player" and a restart that leaves walls (and door state) identical (DESIGN 3.1, 6.1, 8, 10.1).
|
||||
// M3 slice 4 (#19) walls and doors, rewritten for the proto-2 typed wall record (#54). Black-box
|
||||
// through the real binary (withserver): the GM `walls` snapshot, wall.add/wall.update/wall.remove
|
||||
// and door.set with their 6.5 acks and GM-only effects, the typed geometry and raw switches, the
|
||||
// derived shape label, the per-scene never-reused wall ids, "no wall data reaches a player" and a
|
||||
// restart that leaves walls (and door state) identical (DESIGN 3.1, 5.8, 6.1, 8, 10.1).
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import fs from 'node:fs'
|
||||
import { gmKeyOf, makeStateDir, startServer, stopServer, withGmServer, openAs } from './withserver.mjs'
|
||||
import { createPlayer, sleep } from './lib.mjs'
|
||||
|
||||
const stripN = msg => { const { n, ...rest } = msg; return rest }
|
||||
|
||||
// The GM's first connection: hello, then the wall snapshot (DESIGN 6.1 `walls`, 6.3).
|
||||
async function gmConnect(origin, gmKey) {
|
||||
const conn = await openAs(origin, gmKey)
|
||||
@@ -28,47 +27,85 @@ async function wallEffect(ws, pred, timeoutMs = 5000) {
|
||||
return await ws.waitFor(m => (m.t === 'wall' || m.t === 'wall_gone') && pred(m), timeoutMs)
|
||||
}
|
||||
|
||||
test('wall.add: one ack with the id, then the wall to the GM with the 6.1 shape', async () => {
|
||||
// The full proto-2 GM frame every wall must carry (5.8 + 6.1).
|
||||
const WALL_FIELDS = ['id', 'a', 'b', 'thickness', 'position', 'height', 'kind', 'blocks_sight',
|
||||
'blocks_movement', 'sight_dir', 'player_marker', 'door', 'open', 'secret', 'locked', 'label',
|
||||
'flags']
|
||||
|
||||
function assertTypedWall(wall) {
|
||||
// A `wall` frame also carries `t`/`scene`; a `walls` entry only the wall fields plus `n` on send.
|
||||
for (const key of WALL_FIELDS) assert.ok(key in wall, `wall frame is missing ${key}`)
|
||||
}
|
||||
|
||||
test('wall.add: the typed record, raw-switch defaults and the derived kind', async () => {
|
||||
await withGmServer(async (s, gmKey) => {
|
||||
const gm = await gmConnect(s.origin, gmKey)
|
||||
assert.equal(gm.walls.t, 'walls')
|
||||
assert.equal(typeof gm.scene, 'number')
|
||||
assert.deepEqual(gm.walls.walls, [], 'a fresh scene has no walls')
|
||||
|
||||
const ack = await addWall(gm, { a: [100, 200.5], b: [400, 200.5], kind: 'wall' })
|
||||
const ack = await addWall(gm, { a: [100, 200.5], b: [400, 200.5] })
|
||||
assert.equal(ack.ok, true)
|
||||
assert.equal(ack.id, 1)
|
||||
assert.equal(ack.code, undefined, 'an ok ack carries the result fields only')
|
||||
assert.equal(typeof ack.n, 'number')
|
||||
|
||||
const wall = await wallEffect(gm.ws, m => m.t === 'wall' && m.id === 1)
|
||||
assertTypedWall(wall)
|
||||
assert.equal(wall.scene, gm.scene)
|
||||
assert.deepEqual(wall.a, [100, 200.5])
|
||||
assert.deepEqual(wall.b, [400, 200.5])
|
||||
assert.equal(wall.thickness, 0)
|
||||
assert.equal(wall.position, 'center')
|
||||
assert.equal(wall.height, null)
|
||||
assert.equal(wall.kind, 'wall')
|
||||
assert.equal(wall.open, false) // omitted open = closed
|
||||
assert.deepEqual(wall.flags, {}) // omitted flags = {}
|
||||
assert.equal(typeof wall.n, 'number')
|
||||
assert.equal(wall.blocks_sight, true)
|
||||
assert.equal(wall.blocks_movement, true)
|
||||
assert.equal(wall.sight_dir, 'both')
|
||||
assert.equal(wall.player_marker, false)
|
||||
assert.equal(wall.door, false)
|
||||
assert.equal(wall.open, false)
|
||||
assert.equal(wall.secret, false)
|
||||
assert.equal(wall.locked, false)
|
||||
assert.equal(wall.label, null)
|
||||
assert.deepEqual(wall.flags, {})
|
||||
assert.ok(gm.ws.messages.indexOf(ack) < gm.ws.messages.indexOf(wall),
|
||||
'the ack is enqueued before the effect (DESIGN 4.2)')
|
||||
|
||||
// the flags object round-trips untouched; unknown intent fields are ignored (6.2)
|
||||
const withFlags = await addWall(gm, { a: [10, 10], b: [10, 300], kind: 'door',
|
||||
open: true, flags: { locked: false, note: 'side' },
|
||||
junk: { ignored: true } })
|
||||
assert.equal(withFlags.ok, true)
|
||||
assert.equal(withFlags.id, 2)
|
||||
const door = await wallEffect(gm.ws, m => m.t === 'wall' && m.id === 2)
|
||||
assert.equal(door.kind, 'door')
|
||||
assert.equal(door.open, true)
|
||||
assert.deepEqual(door.flags, { locked: false, note: 'side' })
|
||||
// `kind` is output-only: an input kind is an unknown field and ignored (#54, 6.2)
|
||||
const ignored = await addWall(gm, { a: [10, 10], b: [10, 300], kind: 'door',
|
||||
flags: { note: 'side' }, junk: { ignored: true } })
|
||||
assert.equal(ignored.ok, true)
|
||||
const plain = await wallEffect(gm.ws, m => m.t === 'wall' && m.id === ignored.id)
|
||||
assert.equal(plain.kind, 'wall')
|
||||
assert.equal(plain.door, false, 'an input kind never creates a door')
|
||||
assert.deepEqual(plain.flags, { note: 'side' })
|
||||
|
||||
// a second GM connection gets the snapshot of both walls, in id order
|
||||
// geometry is accepted, stored and echoed; the switch set derives the shape label in 5.8 order
|
||||
const shapes = [
|
||||
[{ blocks_sight: false }, 'window'],
|
||||
[{ sight_dir: 'left' }, 'one_way'],
|
||||
[{ door: true }, 'door'],
|
||||
[{ door: true, blocks_sight: false }, 'window'], // a one-way check first: see-through wall
|
||||
[{ blocks_movement: false }, 'custom'],
|
||||
[{ secret: true, door: true }, 'door'], // secret never changes the label
|
||||
]
|
||||
for (const [switches, kind] of shapes) {
|
||||
const a = await addWall(gm, { a: [5, 5], b: [50, 50], thickness: 12, position: 'left',
|
||||
height: 2.5, label: 'railing', ...switches })
|
||||
assert.equal(a.ok, true, JSON.stringify(switches))
|
||||
const frame = await wallEffect(gm.ws, m => m.t === 'wall' && m.id === a.id)
|
||||
assert.equal(frame.kind, kind, JSON.stringify(switches))
|
||||
assert.equal(frame.thickness, 12)
|
||||
assert.equal(frame.position, 'left')
|
||||
assert.equal(frame.height, 2.5)
|
||||
assert.equal(frame.label, 'railing')
|
||||
}
|
||||
|
||||
// a second GM connection gets the snapshot of every wall, in id order
|
||||
const gm2 = await openAs(s.origin, gmKey)
|
||||
await gm2.ws.waitText('hello')
|
||||
const snap = await gm2.ws.waitText('walls')
|
||||
assert.deepEqual(snap.walls.map(w => w.id), [1, 2])
|
||||
assert.equal(snap.walls[1].open, true)
|
||||
assert.deepEqual(snap.walls.map(w => w.id), [1, 2, 3, 4, 5, 6, 7, 8])
|
||||
for (const w of snap.walls) assertTypedWall(w)
|
||||
gm.ws.close(); gm2.ws.close()
|
||||
})
|
||||
})
|
||||
@@ -77,12 +114,12 @@ test('wall ids: monotonic per scene and never reused after removal', async () =>
|
||||
await withGmServer(async (s, gmKey) => {
|
||||
const gm = await gmConnect(s.origin, gmKey)
|
||||
for (let i = 0; i < 3; i++) {
|
||||
assert.equal((await addWall(gm, { a: [i * 10, 0], b: [i * 10 + 5, 0], kind: 'wall' })).id, i + 1)
|
||||
assert.equal((await addWall(gm, { a: [i * 10, 0], b: [i * 10 + 5, 0] })).id, i + 1)
|
||||
}
|
||||
assert.equal((await gm.ws.request({ t: 'wall.remove', scene: gm.scene, id: 2 })).ok, true)
|
||||
await wallEffect(gm.ws, m => m.t === 'wall_gone' && m.id === 2)
|
||||
// the surviving ids do not renumber, and the next add does not reuse 2
|
||||
const next = await addWall(gm, { a: [0, 50], b: [50, 50], kind: 'wall' })
|
||||
const next = await addWall(gm, { a: [0, 50], b: [50, 50] })
|
||||
assert.equal(next.id, 4)
|
||||
const gm2 = await openAs(s.origin, gmKey)
|
||||
await gm2.ws.waitText('hello')
|
||||
@@ -90,52 +127,97 @@ test('wall ids: monotonic per scene and never reused after removal', async () =>
|
||||
assert.deepEqual(snap.walls.map(w => w.id), [1, 3, 4])
|
||||
// remove the newest and add again: still no reuse
|
||||
assert.equal((await gm.ws.request({ t: 'wall.remove', scene: gm.scene, id: 4 })).ok, true)
|
||||
assert.equal((await addWall(gm, { a: [0, 60], b: [50, 60], kind: 'wall' })).id, 5)
|
||||
assert.equal((await addWall(gm, { a: [0, 60], b: [50, 60] })).id, 5)
|
||||
gm.ws.close(); gm2.ws.close()
|
||||
})
|
||||
})
|
||||
|
||||
test('wall.update: patches a, b, kind and flags; the id and open state stay', async () => {
|
||||
test('wall.update: patches only what it names; open and kind are unknown fields', async () => {
|
||||
await withGmServer(async (s, gmKey) => {
|
||||
const gm = await gmConnect(s.origin, gmKey)
|
||||
const { id } = await addWall(gm, { a: [100, 100], b: [200, 100], kind: 'door' })
|
||||
const { id } = await addWall(gm, { a: [100, 100], b: [200, 100], door: true })
|
||||
await wallEffect(gm.ws, m => m.t === 'wall' && m.id === id)
|
||||
assert.equal((await gm.ws.request({ t: 'door.set', scene: gm.scene, id, open: true })).ok, true)
|
||||
await wallEffect(gm.ws, m => m.t === 'wall' && m.id === id && m.open === true)
|
||||
|
||||
const ack = await gm.ws.request({ t: 'wall.update', scene: gm.scene, id,
|
||||
a: [100, 100], b: [300, 400], flags: { kind: 'thin' } })
|
||||
a: [100, 100], b: [300, 400], thickness: 30,
|
||||
position: 'right', height: 4, label: 'deep',
|
||||
flags: { kind: 'thin' } })
|
||||
assert.equal(ack.ok, true)
|
||||
const updated = await wallEffect(gm.ws, m => m.t === 'wall' && m.id === id &&
|
||||
m.b[1] === 400)
|
||||
assert.deepEqual(updated.a, [100, 100])
|
||||
assert.deepEqual(updated.b, [300, 400])
|
||||
assert.equal(updated.thickness, 30)
|
||||
assert.equal(updated.position, 'right')
|
||||
assert.equal(updated.height, 4)
|
||||
assert.equal(updated.label, 'deep')
|
||||
assert.deepEqual(updated.flags, { kind: 'thin' })
|
||||
assert.equal(updated.open, true, 'wall.update does not touch the open state')
|
||||
assert.equal(updated.kind, 'door')
|
||||
|
||||
// a partial patch keeps the other endpoint
|
||||
// `open` in an update is an unknown field: it neither opens nor closes the door
|
||||
const framesBefore = gm.ws.messages.filter(m => m.t === 'wall' && m.id === id).length
|
||||
assert.equal((await gm.ws.request({ t: 'wall.update', scene: gm.scene, id,
|
||||
open: false })).code, 'invalid',
|
||||
'an update naming only the ignored open has no patch field')
|
||||
await sleep(50)
|
||||
assert.equal(gm.ws.messages.filter(m => m.t === 'wall' && m.id === id).length, framesBefore,
|
||||
'the ignored open produced no frame')
|
||||
|
||||
// a partial patch keeps the other fields; an explicit null clears height and label
|
||||
assert.equal((await gm.ws.request({ t: 'wall.update', scene: gm.scene, id,
|
||||
a: [0, 0] })).ok, true)
|
||||
const partial = await wallEffect(gm.ws, m => m.t === 'wall' && m.id === id && m.a[0] === 0)
|
||||
assert.deepEqual(partial.b, [300, 400])
|
||||
|
||||
// door -> wall closes it (a wall is never open)
|
||||
assert.equal(partial.thickness, 30)
|
||||
assert.equal((await gm.ws.request({ t: 'wall.update', scene: gm.scene, id,
|
||||
kind: 'wall' })).ok, true)
|
||||
const asWall = await wallEffect(gm.ws, m => m.t === 'wall' && m.id === id && m.kind === 'wall')
|
||||
height: null, label: null })).ok, true)
|
||||
const cleared = await wallEffect(gm.ws, m => m.t === 'wall' && m.id === id &&
|
||||
m.height === null)
|
||||
assert.equal(cleared.label, null)
|
||||
|
||||
// clearing the door switch closes and de-secrets it (a non-door stores no door settings)
|
||||
assert.equal((await gm.ws.request({ t: 'wall.update', scene: gm.scene, id,
|
||||
door: false })).ok, true)
|
||||
const asWall = await wallEffect(gm.ws, m => m.t === 'wall' && m.id === id &&
|
||||
m.door === false)
|
||||
assert.equal(asWall.open, false)
|
||||
assert.equal(asWall.secret, false)
|
||||
assert.equal(asWall.locked, false)
|
||||
assert.equal(asWall.kind, 'wall')
|
||||
assert.equal((await gm.ws.request({ t: 'door.set', scene: gm.scene, id, open: true })).code,
|
||||
'invalid', 'the row is a plain wall now')
|
||||
gm.ws.close()
|
||||
})
|
||||
})
|
||||
|
||||
test('wall.update {door:true} on a see-through fixed window yields a closed opening window', async () => {
|
||||
await withGmServer(async (s, gmKey) => {
|
||||
const gm = await gmConnect(s.origin, gmKey)
|
||||
const { id } = await addWall(gm, { a: [100, 100], b: [200, 100],
|
||||
blocks_sight: false, blocks_movement: true })
|
||||
const fixed = await wallEffect(gm.ws, m => m.t === 'wall' && m.id === id)
|
||||
assert.equal(fixed.kind, 'window')
|
||||
assert.equal(fixed.door, false)
|
||||
assert.equal((await gm.ws.request({ t: 'wall.update', scene: gm.scene, id,
|
||||
door: true })).ok, true)
|
||||
const opening = await wallEffect(gm.ws, m => m.t === 'wall' && m.id === id &&
|
||||
m.door === true)
|
||||
assert.equal(opening.kind, 'window')
|
||||
assert.equal(opening.open, false, 'the new door is closed, never silently open')
|
||||
assert.equal(opening.blocks_sight, false)
|
||||
assert.equal(opening.blocks_movement, true)
|
||||
gm.ws.close()
|
||||
})
|
||||
})
|
||||
|
||||
test('wall.remove and door.set: acks, GM effects, and the codes of 6.5', async () => {
|
||||
await withGmServer(async (s, gmKey) => {
|
||||
const gm = await gmConnect(s.origin, gmKey)
|
||||
const { id: wallId } = await addWall(gm, { a: [0, 0], b: [100, 0], kind: 'wall' })
|
||||
const { id: doorId } = await addWall(gm, { a: [0, 100], b: [100, 100], kind: 'door' })
|
||||
const { id: wallId } = await addWall(gm, { a: [0, 0], b: [100, 0] })
|
||||
const { id: doorId } = await addWall(gm, { a: [0, 100], b: [100, 100], door: true })
|
||||
await wallEffect(gm.ws, m => m.t === 'wall' && m.id === doorId)
|
||||
|
||||
// door.set toggles only doors
|
||||
@@ -159,7 +241,7 @@ test('wall.remove and door.set: acks, GM effects, and the codes of 6.5', async (
|
||||
const snap = await gm2.ws.waitText('walls')
|
||||
assert.deepEqual(snap.walls.map(w => w.id), [wallId])
|
||||
|
||||
// door.set on a plain wall, an unknown id, and a missing open flag
|
||||
// door.set on a plain wall, an unknown id, and bad open flags
|
||||
assert.equal((await gm.ws.request({ t: 'door.set', scene: gm.scene, id: wallId, open: true })).code,
|
||||
'invalid')
|
||||
assert.equal((await gm.ws.request({ t: 'door.set', scene: gm.scene, id: 99, open: true })).code,
|
||||
@@ -171,26 +253,34 @@ test('wall.remove and door.set: acks, GM effects, and the codes of 6.5', async (
|
||||
})
|
||||
})
|
||||
|
||||
test('field validation: invalid geometry and shapes are refused, nothing is applied', async () => {
|
||||
test('field validation: geometry, switch shapes and impossible rows are refused', async () => {
|
||||
await withGmServer(async (s, gmKey) => {
|
||||
const gm = await gmConnect(s.origin, gmKey)
|
||||
const scene = gm.scene
|
||||
const invalid = [
|
||||
{ a: [10, 10], b: [10, 10], kind: 'wall' }, // a == b
|
||||
{ a: [10, 10], kind: 'wall' }, // no b
|
||||
{ b: [10, 10], kind: 'wall' }, // no a
|
||||
{ a: [10, 10], b: [20, 20] }, // no kind
|
||||
{ a: [10, 10], b: [20, 20], kind: 'window' }, // kind outside wall|door
|
||||
{ a: [10, 10], b: [20, 20], kind: 'WALL' },
|
||||
{ a: [-1, 10], b: [20, 20], kind: 'wall' }, // out of bounds
|
||||
{ a: [10, 10], b: [4097, 20], kind: 'wall' },
|
||||
{ a: [10], b: [20, 20], kind: 'wall' }, // not a point
|
||||
{ a: [10, 10, 10], b: [20, 20], kind: 'wall' },
|
||||
{ a: ['10', 10], b: [20, 20], kind: 'wall' },
|
||||
{ a: [10, 10], b: [20, 20], kind: 'wall', open: 'yes' }, // open is not a boolean
|
||||
{ a: [10, 10], b: [20, 20], kind: 'wall', open: true }, // a wall is never open
|
||||
{ a: [10, 10], b: [20, 20], kind: 'door', flags: [1, 2] }, // flags is not an object
|
||||
{ a: [10, 10], b: [20, 20], kind: 'door', flags: 7 },
|
||||
{ a: [10, 10], b: [10, 10] }, // a == b
|
||||
{ a: [10, 10] }, // no b
|
||||
{ b: [10, 10] }, // no a
|
||||
{ a: [-1, 10], b: [20, 20] }, // out of bounds
|
||||
{ a: [10, 10], b: [4097, 20] },
|
||||
{ a: [10], b: [20, 20] }, // not a point
|
||||
{ a: [10, 10, 10], b: [20, 20] },
|
||||
{ a: ['10', 10], b: [20, 20] },
|
||||
{ a: [10, 10], b: [20, 20], thickness: -1 }, // ranges (5.10, 5.7)
|
||||
{ a: [10, 10], b: [20, 20], thickness: 257 },
|
||||
{ a: [10, 10], b: [20, 20], thickness: 'thick' },
|
||||
{ a: [10, 10], b: [20, 20], position: 'middle' },
|
||||
{ a: [10, 10], b: [20, 20], height: 0 },
|
||||
{ a: [10, 10], b: [20, 20], height: 101 },
|
||||
{ a: [10, 10], b: [20, 20], height: 'tall' },
|
||||
{ a: [10, 10], b: [20, 20], blocks_sight: 'yes' }, // switches are booleans
|
||||
{ a: [10, 10], b: [20, 20], open: 'yes' }, // open is a boolean on a create
|
||||
{ a: [10, 10], b: [20, 20], sight_dir: 'up' },
|
||||
{ a: [10, 10], b: [20, 20], sight_dir: 'left', blocks_sight: false }, // direction needs sight
|
||||
{ a: [10, 10], b: [20, 20], door: true, secret: true, blocks_sight: false },
|
||||
{ a: [10, 10], b: [20, 20], flags: [1, 2] }, // flags is not an object
|
||||
{ a: [10, 10], b: [20, 20], flags: 7 },
|
||||
{ a: [10, 10], b: [20, 20], label: 7 },
|
||||
]
|
||||
for (const fields of invalid) {
|
||||
const ack = await gm.ws.request({ t: 'wall.add', scene, ...fields })
|
||||
@@ -199,10 +289,10 @@ test('field validation: invalid geometry and shapes are refused, nothing is appl
|
||||
assert.equal(ack.id, undefined, 'a refusal carries no state')
|
||||
}
|
||||
// scene: a wrong id is not-found, a wrongly typed one is invalid
|
||||
assert.equal((await gm.ws.request({ t: 'wall.add', scene: '1', a: [0, 0], b: [1, 1],
|
||||
kind: 'wall' })).code, 'invalid')
|
||||
assert.equal((await gm.ws.request({ t: 'wall.add', scene: scene + 1, a: [0, 0], b: [1, 1],
|
||||
kind: 'wall' })).code, 'not-found')
|
||||
assert.equal((await gm.ws.request({ t: 'wall.add', scene: '1', a: [0, 0], b: [1, 1] })).code,
|
||||
'invalid')
|
||||
assert.equal((await gm.ws.request({ t: 'wall.add', scene: scene + 1, a: [0, 0], b: [1, 1] })).code,
|
||||
'not-found')
|
||||
// fields are checked before the lookup (6.5 steps 7 then 8): no patch field is `invalid`,
|
||||
// whatever the id
|
||||
assert.equal((await gm.ws.request({ t: 'wall.update', scene, id: 1 })).code, 'invalid')
|
||||
@@ -217,20 +307,25 @@ test('field validation: invalid geometry and shapes are refused, nothing is appl
|
||||
})
|
||||
})
|
||||
|
||||
test('wall.update refuses an empty patch, bad fields and bad geometry', async () => {
|
||||
test('wall.update refuses an empty patch, ignored-only fields and bad values', async () => {
|
||||
await withGmServer(async (s, gmKey) => {
|
||||
const gm = await gmConnect(s.origin, gmKey)
|
||||
const { id } = await addWall(gm, { a: [100, 100], b: [200, 100], kind: 'wall' })
|
||||
const { id } = await addWall(gm, { a: [100, 100], b: [200, 100] })
|
||||
await wallEffect(gm.ws, m => m.t === 'wall' && m.id === id)
|
||||
const cases = [
|
||||
[{}, 'invalid'], // no updatable field at all
|
||||
[{ id: 'x' }, 'invalid'], // id is not an integer
|
||||
[{ a: [1] }, 'invalid'],
|
||||
[{ kind: 'window' }, 'invalid'],
|
||||
[{ kind: 'window' }, 'invalid'], // output-only, so no patch field
|
||||
[{ open: true }, 'invalid'], // door.set owns open, so no patch field
|
||||
[{ flags: 'no' }, 'invalid'],
|
||||
[{ open: true }, 'invalid'], // `open` alone is not an update
|
||||
[{ thickness: -1 }, 'invalid'],
|
||||
[{ position: 'up' }, 'invalid'],
|
||||
[{ height: -2 }, 'invalid'],
|
||||
[{ blocks_movement: 0 }, 'invalid'],
|
||||
[{ a: [5, 5], b: [5, 5] }, 'invalid'], // degenerate
|
||||
[{ b: [9999, 5] }, 'invalid'], // out of bounds
|
||||
[{ door: true, secret: true, blocks_sight: false }, 'invalid'],
|
||||
[{ id: 42, a: [0, 0] }, 'not-found'],
|
||||
]
|
||||
for (const [fields, code] of cases) {
|
||||
@@ -253,7 +348,7 @@ test('players get no wall data at all, and every wall intent is refused to them'
|
||||
|
||||
// a marker unique in the whole session: no number of the GM's walls may appear in a player frame
|
||||
const marker = [1234.5, 321.5]
|
||||
const added = await addWall(gm, { a: marker, b: [2345.5, 321.5], kind: 'door' })
|
||||
const added = await addWall(gm, { a: marker, b: [2345.5, 321.5], door: true, height: 3.25 })
|
||||
assert.equal(added.ok, true)
|
||||
await gm.ws.request({ t: 'door.set', scene: gm.scene, id: added.id, open: true })
|
||||
await gm.ws.request({ t: 'wall.update', scene: gm.scene, id: added.id, b: [3456.5, 321.5] })
|
||||
@@ -264,14 +359,22 @@ test('players get no wall data at all, and every wall intent is refused to them'
|
||||
for (const t of ['walls', 'wall', 'wall_gone']) {
|
||||
assert.equal(types.has(t), false, `a player received a ${t} frame`)
|
||||
}
|
||||
// no wall field name may ride a player frame (DESIGN 3.1, 5.8; the leak checker bans them all)
|
||||
const banned = ['thickness', 'position', 'height', 'blocks_sight', 'blocks_movement',
|
||||
'sight_dir', 'player_marker', 'door', 'secret', 'locked', 'label']
|
||||
for (const m of p.ws.messages) {
|
||||
assert.ok(!JSON.stringify(m).includes('1234.5'), `wall coordinates leaked: ${JSON.stringify(m)}`)
|
||||
assert.ok(!JSON.stringify(m).includes('321.5'), `wall coordinates leaked: ${JSON.stringify(m)}`)
|
||||
for (const key of banned) {
|
||||
const deepest = (node) => {
|
||||
if (node === null || typeof node !== 'object') return false
|
||||
if (Array.isArray(node)) return node.some(deepest)
|
||||
return Object.keys(node).some(k => k === key || deepest(node[k]))
|
||||
}
|
||||
assert.equal(deepest(m), false, `wall field ${key} leaked: ${JSON.stringify(m)}`)
|
||||
}
|
||||
}
|
||||
// DESIGN 6.1 roles / 6.5 step 5-6: an unnamed non-GM connection is refused (the named-player
|
||||
// role gate is the same `GmOnlyIntents` check, pinned by tests/tprotocol.nim until slice 8
|
||||
// brings naming).
|
||||
for (const intent of [{ t: 'wall.add', scene: gm.scene, a: [0, 0], b: [1, 1], kind: 'wall' },
|
||||
// DESIGN 6.5 step 6: every wall intent is G-only, whatever the wall's settings
|
||||
for (const intent of [{ t: 'wall.add', scene: gm.scene, a: [0, 0], b: [1, 1] },
|
||||
{ t: 'wall.update', scene: gm.scene, id: 1, a: [0, 0] },
|
||||
{ t: 'wall.remove', scene: gm.scene, id: 1 },
|
||||
{ t: 'door.set', scene: gm.scene, id: 1, open: true }]) {
|
||||
@@ -283,7 +386,7 @@ test('players get no wall data at all, and every wall intent is refused to them'
|
||||
})
|
||||
})
|
||||
|
||||
test('restart: walls, door state and the id counter are identical afterwards', async () => {
|
||||
test('restart: the typed walls, door state and the id counter are identical afterwards', async () => {
|
||||
const stateDir = makeStateDir()
|
||||
try {
|
||||
const gmKey = gmKeyOf(stateDir)
|
||||
@@ -292,13 +395,14 @@ test('restart: walls, door state and the id counter are identical afterwards', a
|
||||
try {
|
||||
const gm = await gmConnect(s.origin, gmKey)
|
||||
scene = gm.scene
|
||||
const w1 = await addWall(gm, { a: [0, 0], b: [4096, 0], kind: 'wall', flags: { side: 'north' } })
|
||||
const w2 = await addWall(gm, { a: [100, 100], b: [400, 100], kind: 'door' })
|
||||
const w3 = await addWall(gm, { a: [0, 500], b: [0, 900], kind: 'wall' })
|
||||
const w1 = await addWall(gm, { a: [0, 0], b: [4096, 0], flags: { side: 'north' },
|
||||
thickness: 20, position: 'left', height: 3 })
|
||||
const w2 = await addWall(gm, { a: [100, 100], b: [400, 100], door: true })
|
||||
const w3 = await addWall(gm, { a: [0, 500], b: [0, 900], blocks_sight: false })
|
||||
assert.deepEqual([w1.id, w2.id, w3.id], [1, 2, 3])
|
||||
assert.equal((await gm.ws.request({ t: 'door.set', scene, id: w2.id, open: true })).ok, true)
|
||||
assert.equal((await gm.ws.request({ t: 'wall.remove', scene, id: w3.id })).ok, true)
|
||||
await gm.ws.request({ t: 'wall.update', scene, id: w1.id, b: [4000, 0] })
|
||||
await gm.ws.request({ t: 'wall.update', scene, id: w1.id, b: [4000, 0], label: 'north' })
|
||||
await sleep(100)
|
||||
gm.ws.close()
|
||||
} finally {
|
||||
@@ -314,12 +418,18 @@ test('restart: walls, door state and the id counter are identical afterwards', a
|
||||
t: 'walls',
|
||||
scene,
|
||||
walls: [
|
||||
{ id: 1, a: [0, 0], b: [4000, 0], kind: 'wall', open: false, flags: { side: 'north' } },
|
||||
{ id: 2, a: [100, 100], b: [400, 100], kind: 'door', open: true, flags: {} },
|
||||
{ id: 1, a: [0, 0], b: [4000, 0], thickness: 20, position: 'left', height: 3,
|
||||
kind: 'wall', blocks_sight: true, blocks_movement: true, sight_dir: 'both',
|
||||
player_marker: false, door: false, open: false, secret: false, locked: false,
|
||||
label: 'north', flags: { side: 'north' } },
|
||||
{ id: 2, a: [100, 100], b: [400, 100], thickness: 0, position: 'center', height: null,
|
||||
kind: 'door', blocks_sight: true, blocks_movement: true, sight_dir: 'both',
|
||||
player_marker: false, door: true, open: true, secret: false, locked: false,
|
||||
label: null, flags: {} },
|
||||
],
|
||||
})
|
||||
// the counter survived the removal of wall 3: the next id is 4, never 3
|
||||
assert.equal((await addWall(gm, { a: [10, 10], b: [20, 20], kind: 'wall' })).id, 4)
|
||||
assert.equal((await addWall(gm, { a: [10, 10], b: [20, 20] })).id, 4)
|
||||
gm.ws.close()
|
||||
} finally {
|
||||
await stopServer(s)
|
||||
|
||||
Reference in New Issue
Block a user