From e103c3ed5cd0263fbfeafe32eda47163046b69a8 Mon Sep 17 00:00:00 2001 From: Davide Cappellini Date: Sun, 15 Nov 2026 11:02:43 +0100 Subject: [PATCH] tools: the details group, the leak scenario's props and three fault classes (#22) tools/details.test.mjs is the slice's WS acceptance: the five intents and their codes, a grow push clear of a wall, a squeeze in a corridor too narrow for the grown token, stuck from a wall and from a GM placement cleared by a removal and by a shrink, the GM source of a status, the caps and who reads which bucket, and a restart that brings size, props and statuses back. Waits use a cursor taken before the intent, so a repeated state cannot be matched by an older frame. The leak scenario gains a token in view with props in all three buckets, a GM-sourced status, a resize, a wall over it and the clears; leakcheck refuses the `gm` bucket (GM_PROP), the `owner` bucket on a non-controller (OWNER_PROP) and any `source` on a player status entry (STATUS_SOURCE), so `fault.test.mjs` now asserts all twelve classes. The schema-version fixtures in smoke/persistence move to 6, and mutation.sh gains am-au plus the renames. --- tools/details.test.mjs | 402 +++++++++++++++++++++++++++++++++++++ tools/fault.test.mjs | 9 +- tools/leak.mjs | 42 ++++ tools/leakcheck.nim | 40 +++- tools/mutation.sh | 27 ++- tools/persistence.test.mjs | 9 +- tools/protocol.test.mjs | 6 +- tools/smoke.test.mjs | 15 +- tools/tokens.test.mjs | 5 +- 9 files changed, 530 insertions(+), 25 deletions(-) create mode 100644 tools/details.test.mjs diff --git a/tools/details.test.mjs b/tools/details.test.mjs new file mode 100644 index 0000000..f3e037a --- /dev/null +++ b/tools/details.test.mjs @@ -0,0 +1,402 @@ +// M3 slice 7 (#22): token details over the real wire - `token.resize` (5.6 grow push / squeeze / +// clear to the default), `status.set`/`status.clear` with the `walls`|`GM` sources (5.5, the source +// is GM-only), `prop.set`/`prop.unset` under the 6.1 caps, the `stuck` a GM placement or a new wall +// gives, the shrink that clears it, and a restart that brings sizes, props and statuses back. +import test from 'node:test' +import assert from 'node:assert/strict' +import fs from 'node:fs' +import { createPlayer, namePlayer, sleep } from './lib.mjs' +import { gmKeyOf, makeStateDir, openAs, startServer, stopServer, withGmServer } from './withserver.mjs' + +async function gmConnect(origin, gmKey) { + const conn = await openAs(origin, gmKey) + const hello = await conn.ws.waitText('hello') + await conn.ws.waitText('walls') + // `scene` is the hello block (defaults and sizes); `sceneId` is the 6.1 `scene` field of an intent + return { ...conn, scene: hello.scene, sceneId: hello.scene.id } +} + +// A mutation plus "the frames it caused": the cursor is taken BEFORE the intent is sent, so a wait +// can never be satisfied by a frame an earlier mutation produced (these tests repeat statuses and +// props, so "the first frame with length 1" would be the wrong one). +async function mutate(client, payload) { + const from = client.messages.length + const ack = await client.request(payload) + return { ack, wait: (pred, ms = 5000) => + client.waitFor((m, i) => i >= from && pred(m), ms) } +} + +async function namedPlayer(stateDir, gm, name) { + const player = await createPlayer(gm.ws) + await namePlayer(stateDir, player.id, name) + return player +} + +const tokenFrames = ws => ws.messages.filter(m => m.t === 'token') +const frameOf = (ws, id) => [...ws.messages].reverse().find(m => m.t === 'token' && m.id === id) + +test('token.resize: a per-token size, null back to the scene default, and the codes of 6.1', async () => { + await withGmServer(async (s, gmKey) => { + const gm = await gmConnect(s.origin, gmKey) + const alice = await namedPlayer(s.stateDir, gm, 'Alice') + const tok = await gm.ws.request({ t: 'token.create', scene: gm.sceneId, kind: 'pc', + pos: [400, 400], descriptive_name: 'Alice', + actual_name: 'Alice', controller: alice.id, + flags: { vision: true } }) + const a = await openAs(s.origin, alice.key) + await a.ws.waitText('hello') + const seen = await a.ws.waitFor(m => m.t === 'token' && m.id === tok.id) + assert.equal(seen.radius, gm.scene.token_radius_default, 'the scene default (#4)') + + // a size reaches every viewer as the effective radius, and only the GM gets radius_own + const grow = await mutate(gm.ws, { t: 'token.resize', id: tok.id, radius: 45 }) + assert.equal(grow.ack.ok, true) + const gmView = await grow.wait(m => m.t === 'token' && m.id === tok.id && m.radius === 45) + assert.equal(gmView.radius_own, 45) + const grown = await a.ws.waitFor(m => m.t === 'token' && m.id === tok.id && m.radius === 45) + assert.equal(grown.radius_own, undefined, 'the own radius is a GM-only field') + + // null clears back to the scene default + const clear = await mutate(gm.ws, { t: 'token.resize', id: tok.id, radius: null }) + assert.equal(clear.ack.ok, true) + const back = await clear.wait(m => m.t === 'token' && m.id === tok.id && + m.radius === gm.scene.token_radius_default) + assert.equal(back.radius, gm.scene.token_radius_default) + assert.equal((await grow.wait(m => m.t === 'token' && m.id === tok.id && + m.radius === 45)) !== null, true) + + // codes: a missing field, a non-positive size, a bad type, an unknown target + for (const patch of [{}, { radius: 0 }, { radius: -3 }, { radius: 'big' }, { radius: [1] }]) { + const ack = await gm.ws.request({ t: 'token.resize', id: tok.id, ...patch }) + assert.equal(ack.ok, false, JSON.stringify(patch)) + assert.equal(ack.code, 'invalid', JSON.stringify(patch)) + } + assert.equal((await gm.ws.request({ t: 'token.resize', id: 'nope', radius: 20 })).code, 'not-found') + // a player may not resize anything (G-only, 6.5 step 6) + assert.equal((await a.ws.request({ t: 'token.resize', id: tok.id, radius: 5 })).code, 'not-allowed') + a.ws.close(); gm.ws.close() + }) +}) + +test('grow push and squeeze (5.6): pushed clear of a wall, or flagged squeezed when there is no room', + async () => { + await withGmServer(async (s, gmKey) => { + const gm = await gmConnect(s.origin, gmKey) + const alice = await namedPlayer(s.stateDir, gm, 'Alice') + // a 40 px corridor at x in [500, 540]: a token of r=15 fits, r=25 does not + const left = await gm.ws.request({ t: 'wall.add', scene: gm.sceneId, a: [500, 0], b: [500, 900], + kind: 'wall' }) + await gm.ws.request({ t: 'wall.add', scene: gm.sceneId, a: [540, 0], b: [540, 900], kind: 'wall' }) + // the token sits mid-corridor: r=15 fits between the walls, so it starts unlocked + const pushee = await gm.ws.request({ t: 'token.create', scene: gm.sceneId, kind: 'pc', + pos: [400, 400], descriptive_name: 'Alice', + actual_name: 'Alice', controller: alice.id, + flags: { vision: true }, radius: 15 }) + assert.ok(left.id > 0) + const centred = await mutate(gm.ws, { t: 'token.move', id: pushee.id, pos: [525, 400] }) + assert.equal(centred.ack.ok, true) + const start = await centred.wait(m => m.t === 'token' && m.id === pushee.id && + m.pos[0] === 525) + assert.deepEqual(start.statuses, [], 'mid-corridor at r=15: nothing overlaps') + // r=15 -> 40 does not fit the 40 px corridor, so the grow is squeezed + const squeezed = await mutate(gm.ws, { t: 'token.resize', id: pushee.id, radius: 40 }) + assert.equal(squeezed.ack.ok, true, 'a grow that fails is still applied (squeezed is the outcome)') + let frame = await squeezed.wait(m => m.t === 'token' && m.id === pushee.id && m.radius === 40) + assert.deepEqual(frame.statuses, [{ status: 'squeezed', source: 'walls' }], + 'no room either side: squeezed, source walls (5.6)') + assert.deepEqual(frame.pos, [525, 400], 'a failed grow does not move the token') + const a = await openAs(s.origin, alice.key) + await a.ws.waitText('hello') + const playerFrame = await a.ws.waitFor(m => m.t === 'token' && m.id === pushee.id) + assert.deepEqual(playerFrame.statuses, [{ status: 'squeezed' }], + 'a player sees the status, never its source (5.5, 6.1 note 6)') + // the player cannot move a squeezed token, and the GM can + const nack = await a.ws.request({ t: 'token.move', id: pushee.id, pos: [530, 400] }) + assert.equal(nack.ok, false) + assert.deepEqual(nack.pos, [525, 400]) + const away = await mutate(gm.ws, { t: 'token.move', id: pushee.id, pos: [2000, 2000] }) + assert.equal(away.ack.ok, true) + frame = await away.wait(m => m.t === 'token' && m.id === pushee.id && + m.statuses.length === 0 && m.pos[0] === 2000) + assert.deepEqual(frame.statuses, [], 'the GM move to a free spot clears the walls entries') + + // a grow in the open is pushed away with the minimal displacement + const free = await gm.ws.request({ t: 'token.create', scene: gm.sceneId, kind: 'pc', + pos: [1000, 900], descriptive_name: 'Bob', + actual_name: 'Bob', radius: 10 }) + await gm.ws.request({ t: 'wall.add', scene: gm.sceneId, a: [1010, 700], b: [1010, 1100], + kind: 'wall' }) + const grown = await mutate(gm.ws, { t: 'token.resize', id: free.id, radius: 60 }) + assert.equal(grown.ack.ok, true) + const pushed = await grown.wait(m => m.t === 'token' && m.id === free.id && m.radius === 60) + assert.ok(pushed.pos[0] <= 1010 - 60, `pushed west of the wall: ${JSON.stringify(pushed.pos)}`) + assert.equal(Math.abs(pushed.pos[1] - 900) < 1e-6, true, 'the push is perpendicular') + assert.deepEqual(pushed.statuses, [], 'a pushed token is clear of every wall') + a.ws.close(); gm.ws.close() + }) + }) + +test('stuck from a wall and from a GM placement, cleared by the removal and by a shrink', + async () => { + await withGmServer(async (s, gmKey) => { + const gm = await gmConnect(s.origin, gmKey) + const alice = await namedPlayer(s.stateDir, gm, 'Alice') + const tok = await gm.ws.request({ t: 'token.create', scene: gm.sceneId, kind: 'pc', + pos: [1000, 1000], descriptive_name: 'Alice', + actual_name: 'Alice', controller: alice.id, + flags: { vision: true } }) + const a = await openAs(s.origin, alice.key) + await a.ws.waitText('hello') + + // a wall added over the token gives it stuck(walls) (5.5 SET) + const add = await mutate(gm.ws, { t: 'wall.add', scene: gm.sceneId, a: [990, 800], + b: [990, 1200], kind: 'wall' }) + const wall = add.ack + let frame = await add.wait(m => m.t === 'token' && m.id === tok.id && m.statuses.length > 0) + assert.deepEqual(frame.statuses, [{ status: 'stuck', source: 'walls' }]) + let playerFrame = await a.ws.waitFor(m => m.t === 'token' && m.id === tok.id && + m.statuses.length > 0) + assert.deepEqual(playerFrame.statuses, [{ status: 'stuck' }]) + // the player cannot step out (the plain escape rule still applies: it may, sideways) + assert.equal((await a.ws.request({ t: 'token.move', id: tok.id, pos: [1040, 1000] })).ok, false) + + // shrinking below the overlap clears the walls entry (5.5 CLEAR, 5.6) + const shrink = await mutate(gm.ws, { t: 'token.resize', id: tok.id, radius: 5 }) + assert.equal(shrink.ack.ok, true) + frame = await shrink.wait(m => m.t === 'token' && m.id === tok.id && m.statuses.length === 0) + assert.deepEqual(frame.statuses, []) + // and now the player can step away from the wall + assert.equal((await a.ws.request({ t: 'token.move', id: tok.id, pos: [1030, 1000] })).ok, true) + + // removing the wall does not resurrect the entry + const remove = await mutate(gm.ws, { t: 'wall.remove', scene: gm.sceneId, id: wall.id }) + assert.equal(remove.ack.ok, true) + await sleep(80) + assert.deepEqual(frameOf(gm.ws, tok.id).statuses, []) + + // a GM placement on a wall is stuck too (5.5 SET) + await gm.ws.request({ t: 'wall.add', scene: gm.sceneId, a: [990, 800], b: [990, 1200], + kind: 'wall' }) + const placed = await gm.ws.request({ t: 'token.create', scene: gm.sceneId, kind: 'npc', + pos: [990, 1000], descriptive_name: 'a guard', + actual_name: 'Vex' }) + const placedFrame = await gm.ws.waitFor(m => m.t === 'token' && m.id === placed.id) + assert.deepEqual(placedFrame.statuses, [{ status: 'stuck', source: 'walls' }], + 'the create ack carries the id and the very first frame already has the status') + a.ws.close(); gm.ws.close() + }) + }) + +test('status.set and status.clear: the GM source, single entries, and the codes of 6.1', async () => { + await withGmServer(async (s, gmKey) => { + const gm = await gmConnect(s.origin, gmKey) + const alice = await namedPlayer(s.stateDir, gm, 'Alice') + const tok = await gm.ws.request({ t: 'token.create', scene: gm.sceneId, kind: 'pc', pos: [400, 400], + descriptive_name: 'Alice', actual_name: 'Alice', + controller: alice.id, flags: { vision: true } }) + const a = await openAs(s.origin, alice.key) + await a.ws.waitText('hello') + await a.ws.waitFor(m => m.t === 'token' && m.id === tok.id) + + // a GM-sourced stuck: the player is locked, the GM sees the source + let op = await mutate(gm.ws, { t: 'status.set', id: tok.id, status: 'stuck' }) + assert.equal(op.ack.ok, true) + let frame = await op.wait(m => m.t === 'token' && m.id === tok.id && m.statuses.length > 0) + assert.deepEqual(frame.statuses, [{ status: 'stuck', source: 'GM' }]) + frame = await a.ws.waitFor(m => m.t === 'token' && m.id === tok.id && m.statuses.length > 0) + assert.deepEqual(frame.statuses, [{ status: 'stuck' }]) + const nack = await a.ws.request({ t: 'token.move', id: tok.id, pos: [440, 400] }) + assert.equal(nack.ok, false) + assert.deepEqual(nack.pos, [400, 400]) + + // both statuses show at once; the same entry twice is a no-op + const squeeze = await mutate(gm.ws, { t: 'status.set', id: tok.id, status: 'squeezed' }) + assert.equal(squeeze.ack.ok, true) + frame = await squeeze.wait(m => m.t === 'token' && m.id === tok.id && m.statuses.length === 2) + assert.equal((await gm.ws.request({ t: 'status.set', id: tok.id, status: 'stuck' })).ok, true) + assert.deepEqual(frame.statuses, [{ status: 'stuck', source: 'GM' }, + { status: 'squeezed', source: 'GM' }]) + + // clearing one entry leaves the other + const cleared = await mutate(gm.ws, { t: 'status.clear', id: tok.id, status: 'stuck', + source: 'GM' }) + assert.equal(cleared.ack.ok, true) + frame = await cleared.wait(m => m.t === 'token' && m.id === tok.id && m.statuses.length === 1) + assert.deepEqual(frame.statuses, [{ status: 'squeezed', source: 'GM' }]) + // clearing it again is not-found (the entry is gone), and so is a bad source + assert.equal((await gm.ws.request({ t: 'status.clear', id: tok.id, status: 'stuck', + source: 'GM' })).code, 'not-found') + assert.equal((await gm.ws.request({ t: 'status.clear', id: tok.id, status: 'stuck', + source: 'wall' })).code, 'invalid') + assert.equal((await gm.ws.request({ t: 'status.clear', id: 'nope', status: 'stuck', + source: 'GM' })).code, 'not-found') + for (const patch of [{}, { status: 'blocked' }, { status: 3 }]) { + assert.equal((await gm.ws.request({ t: 'status.set', id: tok.id, ...patch })).code, 'invalid', + JSON.stringify(patch)) + } + assert.equal((await gm.ws.request({ t: 'status.set', id: 'nope', status: 'stuck' })).code, + 'not-found') + // a player may not set a status (G-only) + assert.equal((await a.ws.request({ t: 'status.set', id: tok.id, status: 'stuck' })).code, + 'not-allowed') + // clearing the last entry frees the token for its player + const free = await mutate(gm.ws, { t: 'status.clear', id: tok.id, status: 'squeezed', + source: 'GM' }) + assert.equal(free.ack.ok, true) + await free.wait(m => m.t === 'token' && m.id === tok.id && m.statuses.length === 0) + assert.equal((await a.ws.request({ t: 'token.move', id: tok.id, pos: [440, 400] })).ok, true) + a.ws.close(); gm.ws.close() + }) +}) + +test('prop.set / prop.unset: three buckets, the caps, and who may read which bucket', async () => { + await withGmServer(async (s, gmKey) => { + const gm = await gmConnect(s.origin, gmKey) + const alice = await namedPlayer(s.stateDir, gm, 'Alice') + const tok = await gm.ws.request({ t: 'token.create', scene: gm.sceneId, kind: 'pc', pos: [400, 400], + descriptive_name: 'Alice', actual_name: 'Alice', + controller: alice.id, flags: { vision: true } }) + const a = await openAs(s.origin, alice.key) + await a.ws.waitText('hello') + const seen = await a.ws.waitFor(m => m.t === 'token' && m.id === tok.id) + assert.deepEqual(seen.props, { public: {}, owner: {} }, + 'a token starts with empty buckets; the controller gets public + owner') + + // one write per bucket + for (const [bucket, value] of [['public', 'cold'], ['owner', 7], ['gm', 'the duke']]) { + assert.equal((await gm.ws.request({ t: 'prop.set', target: 'token', id: tok.id, bucket, + key: 'aura', value })).ok, true, bucket) + } + const gmFrame = await gm.ws.waitFor(m => m.t === 'token' && m.id === tok.id && + m.props.gm && m.props.gm.aura === 'the duke') + assert.deepEqual(gmFrame.props, { public: { aura: 'cold' }, owner: { aura: 7 }, + gm: { aura: 'the duke' } }) + const playerFrame = await a.ws.waitFor(m => m.t === 'token' && m.id === tok.id && + m.props.owner && m.props.owner.aura === 7) + assert.deepEqual(playerFrame.props, { public: { aura: 'cold' }, owner: { aura: 7 } }, + 'a controller never gets the gm bucket') + assert.equal(playerFrame.props.gm, undefined) + + // a bystander sees the public bucket only + const bob = await namedPlayer(s.stateDir, gm, 'Bob') + await gm.ws.request({ t: 'token.create', scene: gm.sceneId, kind: 'pc', pos: [420, 400], + descriptive_name: 'Bob', actual_name: 'Bob', controller: bob.id, + flags: { vision: true } }) + const b = await openAs(s.origin, bob.key) + await b.ws.waitText('hello') + const theirs = await b.ws.waitFor(m => m.t === 'token' && m.id === tok.id) + assert.deepEqual(theirs.props, { public: { aura: 'cold' } }, + 'a non-controller gets the public bucket and nothing else') + assert.equal(theirs.mine, false) + + // unset removes one key from one bucket; unsetting an absent key is ok + assert.equal((await gm.ws.request({ t: 'prop.unset', target: 'token', id: tok.id, + bucket: 'public', key: 'aura' })).ok, true) + await gm.ws.waitFor(m => m.t === 'token' && m.id === tok.id && + Object.keys(m.props.public).length === 0) + assert.equal((await gm.ws.request({ t: 'prop.unset', target: 'token', id: tok.id, + bucket: 'public', key: 'aura' })).ok, true) + assert.equal((await gm.ws.request({ t: 'prop.unset', target: 'token', id: tok.id, + bucket: 'gm', key: 'never-there' })).ok, true) + // the owner and gm buckets survived the public unset + const after = await gm.ws.waitFor(m => m.t === 'token' && m.id === tok.id && + m.props.owner.aura === 7 && m.props.gm.aura === 'the duke') + assert.equal(after.props.owner.aura, 7) + + // codes + assert.equal((await gm.ws.request({ t: 'prop.set', target: 'token', id: tok.id, + bucket: 'secret', key: 'k', value: 1 })).code, 'invalid') + assert.equal((await gm.ws.request({ t: 'prop.set', target: 'nope', id: tok.id, + bucket: 'public', key: 'k', value: 1 })).code, 'invalid') + assert.equal((await gm.ws.request({ t: 'prop.set', target: 'token', id: tok.id, + bucket: 'public', key: '', value: 1 })).code, 'invalid') + assert.equal((await gm.ws.request({ t: 'prop.set', target: 'token', id: tok.id, + bucket: 'public', key: 'x'.repeat(65), value: 1 })).code, + 'invalid') + assert.equal((await gm.ws.request({ t: 'prop.set', target: 'token', id: tok.id, + bucket: 'public', key: 'k', value: 'y'.repeat(8193) })).code, + 'invalid', 'a value over 8 KB is refused (6.1)') + assert.equal((await gm.ws.request({ t: 'prop.set', target: 'token', id: tok.id, + bucket: 'public', key: 'k' })).code, 'invalid', + 'a missing value is invalid') + assert.equal((await gm.ws.request({ t: 'prop.set', target: 'token', id: 'nope', + bucket: 'public', key: 'k', value: 1 })).code, 'not-found') + assert.equal((await gm.ws.request({ t: 'prop.set', target: 'character', id: 'abc', + bucket: 'public', key: 'k', value: 1 })).code, 'not-found', + 'characters do not exist before slice 8: an unknown character id') + // a player may not write props in v1 (G-only) + assert.equal((await a.ws.request({ t: 'prop.set', target: 'token', id: tok.id, + bucket: 'owner', key: 'k', value: 1 })).code, 'not-allowed') + + // the cap: 64 keys in one bucket, the 65th refused and nothing applied + for (let i = 0; i < 64; i++) { + assert.equal((await gm.ws.request({ t: 'prop.set', target: 'token', id: tok.id, + bucket: 'public', key: `k${i}`, value: i })).ok, true) + } + assert.equal((await gm.ws.request({ t: 'prop.set', target: 'token', id: tok.id, + bucket: 'public', key: 'one-too-many', value: 1 })).code, + 'invalid') + const capped = await gm.ws.waitFor(m => m.t === 'token' && m.id === tok.id && + Object.keys(m.props.public).length === 64) + assert.equal(Object.keys(capped.props.public).includes('one-too-many'), false) + assert.equal((await gm.ws.request({ t: 'prop.set', target: 'token', id: tok.id, + bucket: 'gm', key: 'still-room', value: 1 })).ok, true, + 'the cap is per bucket') + + // token.create accepts props in all three buckets + const withProps = await gm.ws.request({ t: 'token.create', scene: gm.sceneId, kind: 'item', + pos: [460, 400], descriptive_name: 'a lamp', + actual_name: 'Lantern', + props: { public: { light: 30 }, gm: { trap: true } } }) + assert.equal(withProps.ok, true) + const created = await gm.ws.waitFor(m => m.t === 'token' && m.id === withProps.id) + assert.deepEqual(created.props, { public: { light: 30 }, owner: {}, gm: { trap: true } }) + a.ws.close(); b.ws.close(); gm.ws.close() + }) +}) + +test('restart: sizes, props and statuses come back with the same view', async () => { + const stateDir = makeStateDir() + try { + const gmKey = gmKeyOf(stateDir) + let s = await startServer({ stateDir }) + let saved + try { + const gm = await gmConnect(s.origin, gmKey) + const alice = await namedPlayer(stateDir, gm, 'Alice') + const tok = await gm.ws.request({ t: 'token.create', scene: gm.sceneId, kind: 'pc', + pos: [400, 400], descriptive_name: 'Alice', + actual_name: 'Alice', controller: alice.id, + flags: { vision: true }, radius: 35, + props: { public: { aura: 'cold' }, gm: { secret: 1 } } }) + await gm.ws.request({ t: 'status.set', id: tok.id, status: 'stuck' }) + await gm.ws.request({ t: 'status.set', id: tok.id, status: 'squeezed' }) + const frame = await gm.ws.waitFor(m => m.t === 'token' && m.id === tok.id && + m.statuses.length === 2) + saved = { id: tok.id, radius: frame.radius, props: frame.props, statuses: frame.statuses, + alice } + gm.ws.close() + } finally { + await stopServer(s) + } + s = await startServer({ stateDir }) + try { + const gm = await gmConnect(s.origin, gmKey) + const frame = await gm.ws.waitFor(m => m.t === 'token' && m.id === saved.id) + assert.equal(frame.radius, saved.radius) + assert.deepEqual(frame.props, saved.props) + assert.deepEqual(frame.statuses, saved.statuses) + assert.equal(frame.radius_own, 35) + // the lock survived the restart: the controller still cannot move it + const a = await openAs(s.origin, saved.alice.key) + await a.ws.waitText('hello') + await a.ws.waitFor(m => m.t === 'token' && m.id === saved.id) + assert.equal((await a.ws.request({ t: 'token.move', id: saved.id, pos: [430, 400] })).ok, false) + a.ws.close(); gm.ws.close() + } finally { + await stopServer(s) + } + } finally { + fs.rmSync(stateDir, { recursive: true, force: true }) + } +}) diff --git a/tools/fault.test.mjs b/tools/fault.test.mjs index 47976aa..a4dbe50 100644 --- a/tools/fault.test.mjs +++ b/tools/fault.test.mjs @@ -3,9 +3,9 @@ // and it must fail under the EXACT class set named here: a checker that flags everything would // prove nothing. The shipped build must contain no fault hook at all, and it must still pass. // -// Classes of this slice: HIDDEN_TOKEN, GMONLY_TOKEN, WALLDATA, WITHHELD, NO_REMOVE, OWN_VIEW, -// OTHER_PLAYER, EXPLORED. (The character and name classes of 10.3 land with slice 8, the tile class -// with slice 9.) +// Classes: HIDDEN_TOKEN, GMONLY_TOKEN, WALLDATA, WITHHELD, NO_REMOVE, OWN_VIEW, OTHER_PLAYER, +// EXPLORED, and from slice 7 (#22) OWNER_PROP, GM_PROP and STATUS_SOURCE. (The character and name +// classes of 10.3 land with slice 8, the tile class with slice 9.) import test from 'node:test' import assert from 'node:assert/strict' import fs from 'node:fs' @@ -27,6 +27,9 @@ const FAULTS = { otherExplored: ['OTHER_PLAYER'], noremove: ['NO_REMOVE'], explored: ['EXPLORED'], + ownerProp: ['OWNER_PROP'], + gmProp: ['GM_PROP'], + statusSource: ['STATUS_SOURCE'], } function classesOf(output) { diff --git a/tools/leak.mjs b/tools/leak.mjs index 297792f..d9ff9ba 100644 --- a/tools/leak.mjs +++ b/tools/leak.mjs @@ -19,6 +19,9 @@ // - a wall added and removed while the subject watches (its polygon shrinks and grows) // - a door closing on a token, which the server pushes aside (5.5) // - a token that is never within range at all (M4) +// - slice 7 (#22): props written into all three buckets on a token the subject can see, a +// GM-sourced status, a walls-sourced stuck from a new wall, a resize, and a prop.unset — every +// frame of the group is checked for the bucket and the `source` it must not carry import fs from 'node:fs' import path from 'node:path' import { spawnSync } from 'node:child_process' @@ -233,6 +236,45 @@ export async function runLeak({ origin, gmKey, stateDir, transcript, keepOpen = const ack = await gm.ws.request({ t: 'door.set', scene, id: wallIds[1], open: false }) if (ack.ok !== true) throw new Error(`door.set refused: ${JSON.stringify(ack)}`) }) + // Slice 7 (#22): a token the subject can see, in every bucket and with a status. N2 sits 60 px + // north-east of A, so every frame of these groups is one the subject receives. + await group('GM creates N2 in view', async () => { + await createToken('N2', { kind: 'item', pos: [660, 600], descriptive_name: 'a rune', + actual_name: 'The Rune' }) + }) + await group('GM writes props into all three buckets on N2', async () => { + for (const [bucket, value] of [['public', 'cold'], ['owner', 3], ['gm', 'the duke']]) { + const ack = await gm.ws.request({ t: 'prop.set', target: 'token', id: ids.N2, bucket, + key: 'aura', value }) + if (ack.ok !== true) throw new Error(`prop.set refused: ${JSON.stringify(ack)}`) + } + }) + await group('GM sets a GM-sourced status on N2', async () => { + const ack = await gm.ws.request({ t: 'status.set', id: ids.N2, status: 'squeezed' }) + if (ack.ok !== true) throw new Error(`status.set refused: ${JSON.stringify(ack)}`) + }) + await group('GM resizes N2', async () => { + const resized = await gm.ws.request({ t: 'token.resize', id: ids.N2, radius: 45 }) + if (resized.ok !== true) throw new Error(`token.resize refused: ${JSON.stringify(resized)}`) + }) + await group('GM adds a wall over N2 (stuck, source walls)', async () => { + await addWall({ a: [700, 560], b: [700, 660], kind: 'wall' }) + }) + await group('GM unsets the public prop of N2', async () => { + const unset = await gm.ws.request({ t: 'prop.unset', target: 'token', id: ids.N2, + bucket: 'public', key: 'aura' }) + if (unset.ok !== true) throw new Error(`prop.unset refused: ${JSON.stringify(unset)}`) + }) + await group('GM clears the GM-sourced status of N2', async () => { + const cleared = await gm.ws.request({ t: 'status.clear', id: ids.N2, status: 'squeezed', + source: 'GM' }) + if (cleared.ok !== true) throw new Error(`status.clear refused: ${JSON.stringify(cleared)}`) + }) + await group('GM removes the wall over N2', async () => { + const ack = await gm.ws.request({ t: 'wall.remove', scene, + id: wallIds[wallIds.length - 1] }) + if (ack.ok !== true) throw new Error(`wall.remove refused: ${JSON.stringify(ack)}`) + }) await group('A walks away from the door', async () => { expectAck(await move(A, ids.A, [560, 950]), true) }) diff --git a/tools/leakcheck.nim b/tools/leakcheck.nim index 665572c..0a11bbe 100644 --- a/tools/leakcheck.nim +++ b/tools/leakcheck.nim @@ -16,6 +16,9 @@ ## OWN_VIEW the subject's own token position or its vision polygon is wrong ## OTHER_PLAYER another player's polygon, `mine` flag, explored cells or presence leaked ## EXPLORED the explored set differs from the recomputation / the clear-segment oracle +## OWNER_PROP the `owner` property bucket reached someone who does not control the token +## GM_PROP the `gm` property bucket reached a player at all +## STATUS_SOURCE a player frame carried the `source` of a status (5.5, 6.1 note 6) ## GEOMETRY the recomputed polygon disagrees with the clear-segment oracle (sanity) ## PROTOCOL a frame the catalogue does not allow, a bad `n` sequence, a missing hello block ## @@ -37,6 +40,8 @@ type hasVision: bool visionRadius: Option[float] radius: float + props: JsonNode ## the GM's three buckets (the truth for every bucket question) + statuses: seq[string] ## the status names the GM sees, in order Truth = object walls: seq[Wall] @@ -129,6 +134,8 @@ proc applyGmTokens(truth: var Truth, m: JsonNode) = m["flags"]["vision"].getBool, radius: m["radius"].getFloat) if m["vision_radius"].kind != JNull: t.visionRadius = some(m["vision_radius"].getFloat) + t.props = m["props"] + for st in m["statuses"]: t.statuses.add st["status"].getStr truth.tokens[m["id"].getStr] = t of "token_gone": truth.tokens.del m["id"].getStr @@ -266,7 +273,11 @@ proc main() = var keys = initHashSet[string]() keysDeep(m, keys) for k in keys: - if k in BannedKeys: fail "WALLDATA", "player frame has wall-ish/GM-only key " & k + if k == "source": + # 5.5 / 6.1 note 6: a viewer sees the status, never what caused it. + fail "STATUS_SOURCE", "player frame carries a status source" + elif k in BannedKeys: + fail "WALLDATA", "player frame has wall-ish/GM-only key " & k case t of "ack": # only a bad shape is interesting here; the driver already checked the outcomes it expected @@ -277,6 +288,33 @@ proc main() = fail "HIDDEN_TOKEN", "token " & id & " is not in the GM's truth" continue let actual = truth.tokens[id] + # props: the public bucket always, the owner bucket only for the controller, the gm bucket + # never (6.1 leak notes; the typed view has no field for it, so an injected fault shows here) + var buckets = initHashSet[string]() + if m.hasKey("props") and m["props"].kind == JObject: + for name, _ in m["props"]: buckets.incl name + if "gm" in buckets: + fail "GM_PROP", "token " & id & " carried the gm property bucket to a player" + # A frame that claims `mine` is the OTHER_PLAYER fault's shape: the bucket then matches the + # (wrong) claim, so the claim itself is what gets reported, not the bucket. + if "owner" in buckets and not (actual.controller == me) and not m["mine"].getBool: + fail "OWNER_PROP", "token " & id & " carried the owner bucket to a non-controller" + if actual.controller == me and "owner" notin buckets: + fail "OWNER_PROP", "the controller is missing the owner bucket of token " & id + if m.hasKey("props"): + for name in ["public", "owner"]: + if name notin buckets or not actual.props.hasKey(name): continue + if m["props"][name] != actual.props[name]: + fail (if name == "public": "OWN_VIEW" else: "OWNER_PROP"), + "token " & id & " has a " & name & " bucket that is not the truth" + # statuses: the names the GM sees, and nothing else on the entry + var gotStatuses: seq[string] + for st in m["statuses"]: + if st.len != 1: fail "STATUS_SOURCE", "a player status entry carries more than `status`" + gotStatuses.add st["status"].getStr + if gotStatuses != actual.statuses: + fail "OWN_VIEW", "token " & id & " statuses " & $gotStatuses & " != truth " & + $actual.statuses if not samePos(m["pos"], actual.pos): fail "OWN_VIEW", "token " & id & " position " & $m["pos"] & " != truth " & $[actual.pos.x, actual.pos.y] diff --git a/tools/mutation.sh b/tools/mutation.sh index d7f99db..1eff1f6 100755 --- a/tools/mutation.sh +++ b/tools/mutation.sh @@ -6,7 +6,7 @@ # d1/d2: drop arm 1/2 of the shared-vertex fixture # e: cellsTouched without the fill spans | f: escape rule without the crossing check | g: GM moves checked against walls # h: capsule reduced to centre path + destination circle (prototype H10) | i: no step cap | j: blocked trigger needs centre-on-wall -# k: wall removal / door open clears blocked unconditionally (no KEEP) | l: GM moves never set/clear blocked +# k: wall removal / door open clears stuck unconditionally (no KEEP) | l: GM moves never set/clear stuck # m: door push goes to the wrong side first | n: door push skips the validity check | o: push ignores the previous-position rule # p: token bucket never refills | q: reqId upper bound dropped | r: malformed flood never fires | s: frame counter frozen # t: wall removal renumbers next_wall_id (the dense-id design, #3) | u: the id counter is not loaded from the DB @@ -72,7 +72,7 @@ NEW="shared endpoint: no leak at the vertex|'<' apex|every segment endpoint|rays D="shared vertex: both arms required" E="random visibility polygons|random simple polygons|corpus|prototype scene, all tokens|random wall fields|concave polygon|square polygon" F="exactly on a wall: can step off|overlapping 10 px off|escape from a closed door|GM placement and GM move onto a wall" -G="GM: ignores walls, step cap and blocked" +G="GM: ignores walls, step cap and the lock" H="corner clipping|leg of the path|diagonal squeeze past" I="step cap|over-cap, blocked-by-wall|P1:|P2:" J="wall added within r of the circle|Q14: a door closed" @@ -105,12 +105,12 @@ run d1 "shared-vertex fixture without arm 1" tests/tgeometry.nim 's/@\[arm1, arm run d2 "shared-vertex fixture without arm 2" tests/tgeometry.nim 's/@\[arm1, arm2\] *# SHARED-VERTEX/@[arm1]/' "$D" run e "cellsTouched without fill spans" server/geometry.nim '/for k in countup(0, xs\[row\].len - 2, 2)/d' "$E" run f "escape rule without the crossing check" server/moverules.nim 's/if pathCrosses(s, d, w.a, w.b) or segDist(d, w.a, w.b) < r: return false/if segDist(d, w.a, w.b) < r: return false/' "$F" -run g "GM moves checked against walls" server/moverules.nim 's/^ if not inBounds(sc, d): return nack(s)$/ if not inBounds(sc, d) or not pathClear(sc.walls, s, d, sc.tokenRadius): return nack(s)/' "$G" +run g "GM moves checked against walls" server/moverules.nim 's/^ if not inBounds(sc, d): return nack(s)$/ if not inBounds(sc, d) or not pathClear(sc.walls, s, d, sc.tokens[ti].radius): return nack(s)/' "$G" run h "capsule = centre path + destination circle (prototype)" server/moverules.nim 's/elif segsCross(s, d, w.a, w.b) or segSegDist(s, d, w.a, w.b) < r: return false/elif segsCross(s, d, w.a, w.b) or segDist(d, w.a, w.b) < r: return false/' "$H" run i "no step cap" server/moverules.nim '/if hypot(dd.x, dd.y) > stepCap(sc, sc.tokens\[ti\]): return nack(s)/d' "$I" -run j "blocked trigger needs the centre on the wall" server/moverules.nim 's/segDist(t.pos, w.a, w.b) < sc.tokenRadius/segDist(t.pos, w.a, w.b) < 1e-9/' "$J" -run k "removal/open clears blocked unconditionally (no KEEP)" server/moverules.nim 's/sc.tokens\[i\].blocked = overlapsAny(sc, sc.tokens\[i\])/sc.tokens[i].blocked = false/' "$K" -run l "GM moves never set or clear blocked" server/moverules.nim '/^ if who.role == roleGM: sc.tokens\[ti\].blocked = /d' "$L" +run j "stuck trigger needs the centre on the wall" server/moverules.nim 's/segDist(t.pos, w.a, w.b) < t.radius/segDist(t.pos, w.a, w.b) < 1e-9/' "$J" +run k "removal/open clears stuck unconditionally (no KEEP)" server/moverules.nim 's/if not overlapsAny(sc, sc.tokens\[i\]): sc.tokens\[i\].clearWalls()/sc.tokens[i].clearWalls()/' "$K" +run l "GM moves never set or clear stuck" server/moverules.nim '/^ if who.role == roleGM: sc.placeToken(ti)$/d' "$L" run m "door push: wrong side first" server/moverules.nim 's/for sg in \[(if side > 0: 1.0 else: -1.0), (if side > 0: -1.0 else: 1.0)\]:/for sg in [(if side > 0: -1.0 else: 1.0), (if side > 0: 1.0 else: -1.0)]:/' "$M" run n "door push: no validity check" server/moverules.nim 's/if inBounds(sc, p) and not overlapsAny(sc, tt): return (true, p)/return (true, p)/' "$N" run o "door push: previous position ignored on the line" server/moverules.nim 's/side = if t.hasPrev: dot(t.prev - w.a, n) else: 0.0/side = 0.0/' "$O" @@ -134,7 +134,7 @@ run aa "the egress ignores LOS, gm_only and ownership" server/views.nim 's/^ run ab "gm_only ignored by the view rule" server/vision.nim '/^ if t\.gmOnly: return false$/d' "$AB" run ac "a controlled token is not always visible" server/vision.nim '/^ if t\.owner == playerId: return true$/d' "$AC" run ad "no token_gone when a token leaves the view" server/views.nim 's/^ result\.add tokenGoneFrame(id)$/ discard/' "$AD" -run ae "a player token frame carries the GM-only kind" server/views.nim 's/ "statuses": \[\], "props": props/ "statuses": [], "props": props, "kind": "npc"/' "$AE" +run ae "a player token frame carries the GM-only kind" server/views.nim 's/ "statuses": statusKindsJson(v.statuses), "props": buckets/ "statuses": statusKindsJson(v.statuses), "props": buckets, "kind": "npc"/' "$AE" run af "explored forgets cells outside the current polygon" server/vision.nim 's/^ for idx in added: pv\.explored\.incl idx$/ pv.explored = added/' "$AF" # slice 6 (#21): the chunk format, the per-player keying, the upsert and the startup restore run ag "the chunk row stride is dropped" server/explored.nim 's/((cy mod ChunkCells) \* ChunkCells) + (cx mod ChunkCells)/(cy mod ChunkCells) + (cx mod ChunkCells)/' "bitmap layout is pinned" @@ -143,9 +143,20 @@ run ai "restore forgets the decoded cells" server/explored.nim 's/^ result\ run aj "explored chunks keyed by scene, not player" server/explored.nim 's/db\.exec(ps, c\.playerId, sceneId, c\.cx, c\.cy, c\.bits)/db.exec(ps, sceneId, sceneId, c.cx, c.cy, c.bits)/' "never mix" run ak "a chunk rewrite is ignored" server/explored.nim 's/DO UPDATE SET bits = excluded\.bits"""$/DO NOTHING"""/' "replaces the bitmap" run al "dirty chunks keyed by row only" server/explored.nim 's/^ let key = ccy \* sc\.chunkCols + ccx$/ let key = ccy/' "two chunks in one chunk row are both written" +# slice 7 (#22): the bucket filter, the caps, the status set/clear and the resize/grow rules +run am "the owner bucket reaches a non-controller" server/views.nim 's/propsOwner: (if mine: objectOf(t.props\[pbOwner\]) else: nil)/propsOwner: t.props[pbOwner]/' "never the gm bucket|gets the public bucket only" +run an "a new wall does not stick a token" server/moverules.nim 's/sc.tokens\[i\].stuckWalls = true/discard/' "wall added within r of the circle" +run ao "a shrink never clears the walls entries" server/moverules.nim 's/^ sc.tokens\[ti\]\.clearWalls()$/ discard/' "a squeeze from a failed grow clears|a shrink that still overlaps keeps" +run ap "the property cap is not enforced" server/props.nim '/and p\[bucket\]\.len >= MaxPropKeys/d' "64 keys per bucket|the 65th" +run aq "the grow push is skipped" server/moverules.nim 's/^ if not grew:$/ if true:/' "grow inside r of a wall pushes it out" +run ar "a failed grow is not flagged squeezed" server/moverules.nim '/^ sc.tokens\[ti\]\.squeezedWalls = true$/d' "grow with no room on either side squeezes" +run as "a failed door push sticks instead of squeezing" server/moverules.nim 's/^ sc.tokens\[i\]\.squeezedWalls = true$/ sc.tokens[i].stuckWalls = true/' "push: both sides invalid" +run at "one bucket budget shared by all buckets" server/props.nim 's/and p\[bucket\]\.len >= MaxPropKeys/and p[pbPublic].len >= MaxPropKeys/' "64 keys per bucket" +run au "a grow that already fits still pushes" server/moverules.nim 's/^ if not overlapsAny(sc, sc.tokens\[ti\]):$/ if false:/' "a grow that already fits does not move the token" wait + rc=0; : > "$LOG" -for id in control a b c d1 d2 e f g h i j k l m n o p q r s t u v w x y z z2 aa ab ac ad ae af ag ah ai aj ak al; do +for id in control a b c d1 d2 e f g h i j k l m n o p q r s t u v w x y z z2 aa ab ac ad ae af ag ah ai aj ak al am an ao ap aq ar as at au; do [ -f "$T/$id/res" ] && cat "$T/$id/res" >> "$LOG" if [ -f "$T/$id/verdict" ]; then tee -a "$LOG" < "$T/$id/verdict"; [ "$(cat "$T/$id/rc")" = 0 ] || rc=1 else echo "$id: NO RESULT (job killed?)" | tee -a "$LOG"; rc=1; fi diff --git a/tools/persistence.test.mjs b/tools/persistence.test.mjs index 82e55de..8488fa9 100644 --- a/tools/persistence.test.mjs +++ b/tools/persistence.test.mjs @@ -399,7 +399,7 @@ INSERT INTO entity (id, scene_id, kind, descriptive_name, actual_name, x, y, own PRAGMA user_version = 4; ` -test('migration: a slice-5 DB (fixture, schema version 4) migrates under the real binary', async () => { +test('migration: a schema-4 DB (fixture) migrates under the real binary to the latest schema', async () => { const stateDir = makeStateDir() const dbPath = `${stateDir}/state.db` const fixture = new DatabaseSync(dbPath) @@ -413,7 +413,7 @@ test('migration: a slice-5 DB (fixture, schema version 4) migrates under the rea } const s = await startServer({ stateDir }) try { - assert.match(s.log(), /db_ready .*schema_version=5 applied=1/, s.log()) + assert.match(s.log(), /db_ready .*schema_version=6 applied=2/, s.log()) // The old data is served unchanged through the product surface. const alice = { id: 2, key: 'ALIC-ALIC-ALIC-ALIC-ALIC' } const conn = await openAs(s.origin, alice.key) @@ -434,10 +434,11 @@ test('migration: a slice-5 DB (fixture, schema version 4) migrates under the rea } const db = new DatabaseSync(dbPath) try { - assert.equal(Number(db.prepare('PRAGMA user_version').get().user_version), 5) + assert.equal(Number(db.prepare('PRAGMA user_version').get().user_version), 6) assert.deepEqual(db.prepare('SELECT version, name FROM schema_migration ORDER BY version').all() .map(r => [Number(r.version), r.name]), - [[1, 'meta'], [2, 'auth'], [3, 'world'], [4, 'tokens'], [5, 'explored']]) + [[1, 'meta'], [2, 'auth'], [3, 'world'], [4, 'tokens'], [5, 'explored'], + [6, 'token details']]) assert.equal(Number(db.prepare('SELECT count(*) AS n FROM explored_chunk').get().n), 0) assert.equal(db.prepare('SELECT name FROM player WHERE id = 2').get().name, 'Alice') } finally { diff --git a/tools/protocol.test.mjs b/tools/protocol.test.mjs index 6ea156c..afbf0eb 100644 --- a/tools/protocol.test.mjs +++ b/tools/protocol.test.mjs @@ -97,9 +97,9 @@ test('an unknown type is refused, unknown fields are ignored, and every intent g assert.equal((await gm.ws.request({ t: 'token.teleport', id: 'x' })).code, 'unknown-type') assert.equal((await gm.ws.request({ t: '' })).code, 'unknown-type') assert.equal((await gm.ws.request({ t: 'TOKEN.MOVE', id: 'x' })).code, 'unknown-type') - // a catalogue intent whose slice has not landed still answers exactly once (slices 6-8) - assert.equal((await gm.ws.request({ t: 'status.set', id: 'x', status: 'stuck' })).code, - 'unknown-type') + // a catalogue intent whose slice has not landed still answers exactly once (slice 8) + assert.equal((await gm.ws.request({ t: 'name.reveal', subject: 'token', id: 'x', + player: 2 })).code, 'unknown-type') assert.equal((await gm.ws.request({ t: 'scene.set', scene: 1 })).code, 'unknown-type') assert.equal((await gm.ws.request({ t: 'character.create', descriptive_name: 'x', actual_name: 'X' })).code, 'unknown-type') diff --git a/tools/smoke.test.mjs b/tools/smoke.test.mjs index 7ac0d8b..acb8c08 100644 --- a/tools/smoke.test.mjs +++ b/tools/smoke.test.mjs @@ -49,15 +49,16 @@ test('a fresh DB is created and migrated; re-opening applies nothing', async () const first = await startServer({ stateDir }) const firstLog = first.log() await stopServer(first) - assert.match(firstLog, /db_ready .*schema_version=5 applied=5/, firstLog) + assert.match(firstLog, /db_ready .*schema_version=6 applied=6/, firstLog) assert.ok(fs.existsSync(first.dbPath), 'state.db was not created') const db = new DatabaseSync(first.dbPath) try { - assert.equal(Number(db.prepare('PRAGMA user_version').get().user_version), 5) + assert.equal(Number(db.prepare('PRAGMA user_version').get().user_version), 6) const rows = db.prepare('SELECT version, name FROM schema_migration ORDER BY version').all() assert.deepEqual(rows.map(r => [Number(r.version), r.name]), - [[1, 'meta'], [2, 'auth'], [3, 'world'], [4, 'tokens'], [5, 'explored']]) + [[1, 'meta'], [2, 'auth'], [3, 'world'], [4, 'tokens'], [5, 'explored'], + [6, 'token details']]) assert.equal(Number(db.prepare('SELECT count(*) AS n FROM meta').get().n), 0) assert.equal(Number(db.prepare('SELECT count(*) AS n FROM player').get().n), 0) // step 3 seeds the single v1 scene (Q3) with no walls and a counter at 1 @@ -68,6 +69,12 @@ test('a fresh DB is created and migrated; re-opening applies nothing', async () assert.equal(Number(db.prepare('SELECT count(*) AS n FROM entity').get().n), 0) // step 5 creates the chunked explored store (DESIGN 4.4, #21), empty assert.equal(Number(db.prepare('SELECT count(*) AS n FROM explored_chunk').get().n), 0) + // step 6 adds the three prop buckets and the status set (DESIGN 5.5, 8; #22), empty + assert.equal(Number(db.prepare('SELECT count(*) AS n FROM entity_status').get().n), 0) + for (const col of ['props_public', 'props_owner', 'props_gm']) { + assert.equal(Number(db.prepare(`SELECT count(*) AS n FROM pragma_table_info('entity') + WHERE name = '${col}'`).get().n), 1, col) + } assert.equal(db.prepare('PRAGMA journal_mode').get().journal_mode, 'wal') } finally { db.close() @@ -76,7 +83,7 @@ test('a fresh DB is created and migrated; re-opening applies nothing', async () const second = await startServer({ stateDir }) const secondLog = second.log().slice(firstLog.length) await stopServer(second) - assert.match(secondLog, /db_ready .*schema_version=5 applied=0/, secondLog) + assert.match(secondLog, /db_ready .*schema_version=6 applied=0/, secondLog) assert.doesNotMatch(secondLog, /applied=[1-9]/) } finally { fs.rmSync(stateDir, { recursive: true, force: true }) diff --git a/tools/tokens.test.mjs b/tools/tokens.test.mjs index 8f02c73..9e14a49 100644 --- a/tools/tokens.test.mjs +++ b/tools/tokens.test.mjs @@ -89,8 +89,9 @@ test('token.create validation: the 6.1 table and the fields this slice cannot ho { ...base, flags: [1, 2] }, { ...base, vision_radius: 0 }, { ...base, vision_radius: 'big' }, - { ...base, radius: 30 }, // slice 7 (#4) - { ...base, props: { public: {} } }, // slice 7 (#22) + { ...base, radius: 0 }, // slice 7 (#4): a radius is > 0 or null + { ...base, props: { secret: {} } }, // slice 7 (#22): the bucket names are closed + { ...base, props: { public: { '': 1 } } }, { ...base, character_id: 'abc' }, // slice 8 (#23) { ...base, controller: 'alice' }, ]