From f9f26a4a013c4749edd669ef711a524bc06311ee Mon Sep 17 00:00:00 2001 From: Davide Cappellini Date: Thu, 19 Nov 2026 23:56:16 +0100 Subject: [PATCH] test(walls): rewrite the leak scenario as one world, gate every fault class (#61) The Walls r1 scenario had grown appendages: a marked window bolted on in the room, a one-way wall tacked onto the southern walk, and no secret or locked door at all. #61 makes it one coherent world and proves the world itself. The world now holds a room entered through an opening door, a far wall with a solid stretch, a secret door and a locked door (a token behind each, so their absence from the transcript is the leak proof), a one-way screen the subject sees across, a marked window in the room, the same window's switch cleared and restored (retraction and re-earn end to end), a marked solid wall, and a marked window the subject never sees. - tools/leak.mjs: declarative WORLD with role handles (no wallIds[1] indexing), narrative groups, and a scenarioCoverage() reading the GM's wall frames and the subject's marker frames. - tools/leak.test.mjs: asserts the coverage on subject A: one-way wall, secret door, locked door, a marked window on each side of the sight gate and a marked non-window. - tools/groups.mjs: the leak+fault group lists doors.test.mjs (#56) and markers.test.mjs (#59/#60) with their proving tests. - docs/TESTING.md: the scenario, the coverage gate and the marker retraction exercise are recorded as built. Fault matrix: all 21 fault classes still caught as exactly their own class (oneWay, markerEarly/Extra/Off included); 22 tests with the clean-build gate. That build passes and its bytes carry no LEAK_FAULT. nimble test and the 136-test node suite green. Ref #61 --- docs/TESTING.md | 16 ++- tools/groups.mjs | 7 +- tools/leak.mjs | 252 +++++++++++++++++++++++++++++--------------- tools/leak.test.mjs | 15 +++ 4 files changed, 202 insertions(+), 88 deletions(-) diff --git a/docs/TESTING.md b/docs/TESTING.md index 52aed7f..4cfd4ec 100644 --- a/docs/TESTING.md +++ b/docs/TESTING.md @@ -60,7 +60,7 @@ How to run: `devbox run test` = Nim in-process tests first, then the Node black- | # | Proving test | |---|---| | T1 | leak test + fault classes | -| T2 | fault `walls` [MEASURED caught]; door-equivalence test (T17, §10.3) [MEASURED caught: fault `secretgap`]; `MARKER_EARLY`/`MARKER_EXTRA`/`MARKER_OFF` (§10.3) [MEASURED caught: `tools/fault.test.mjs`, Walls r1 #60] | +| T2 | fault `walls` [MEASURED caught]; door-equivalence test (T17, §10.3) [MEASURED caught: fault `secretgap`]; `MARKER_EARLY`/`MARKER_EXTRA`/`MARKER_OFF` (§10.3) [MEASURED caught: `tools/fault.test.mjs`, Walls r1 #60]; scenario coverage of the rewritten leak world (Walls r1 #61) [MEASURED: `tools/leak.test.mjs`] | | T3 | faults `other-*` [MEASURED caught] | | T4 | leak (d) against the independent oracle, smoke steal check, direct `/_tiles/` -> 404 (M3 test nginx) | | T5 | documented, not testable as a leak; M4 timing gates (§13) | @@ -325,7 +325,7 @@ from the prototype, what was missing, what the M3 build added, and the tools it |---|---|---| | Geometry unit tests (M1 port baseline: 33 test blocks / 98 checks, none dropped; current count in `results/nimble-test.log`) | `tests/tgeometry.nim`, `results/nimble-test.log` | Port with `geometry.nim`. | | Geometry mutation check | `tools/mutation.sh` (a: no +-RayEps rays, b/c: upper/lower segment end exclusive) | Control passes, each mutation fails >= 1 test [MEASURED 1, 2, 2]. Port. | -| Leak test | `tools/leak.mjs`, `leakcheck.nim`, `leaktest.sh` | Subject A and B, fresh DB, ~240 steps; asserts (a)-(e) in README. Independent LOS oracle for token visibility (added after the bow-tie bug). | +| Leak test | `tools/leak.mjs`, `leakcheck.nim`, `leaktest.sh` | Subject A and B, fresh DB, ~240 steps; asserts (a)-(e) in README. Independent LOS oracle for token visibility (added after the bow-tie bug). Walls r1 #61 rewrote the scenario into one world (a marked window, a one-way wall, a secret and a locked door, marked walls on both sides of the sight test) and `tools/leak.test.mjs` asserts that coverage. | | Negative control / fault injection | `tools/faulttest.sh`, `-d:leakfault` build | 8 faults, exact failure-class set each, clean build passes, `LEAK_FAULT` string asserted absent from clean binary [MEASURED 8/8]. Port and extend. | | Restart | `tools/restart.mjs` | SIGTERM + SIGKILL, identical player keys/positions/doors/vision/explored/hello+state. | | Concurrency | `tools/concurrency.mjs` | 60 s, 3 clients, gseq monotonic, every intent acked, quiesced views == fresh connection. **M5 port [FIXED, #15]:** 6 walkers on one GM socket (~200/s) exceeds the 30/s per-connection rate (DESIGN §6.4); spread walkers across connections (4 per player, 16 total; DESIGN §4.3). | @@ -356,6 +356,14 @@ from the prototype, what was missing, what the M3 build added, and the tools it transcript checker); `MARKER_EARLY`/`MARKER_EXTRA`/`MARKER_OFF` (#60), each asserted as exactly its own class by `tools/fault.test.mjs` (the leak transcript checker, with the scenario's unseen marked window and marked solid wall as the negative controls). + **The scenario itself (Walls r1 #61)** is one coherent world, not appended fragments: a room with + an opening door, a far wall holding a solid stretch, a secret door and a locked door with a token + behind each, a one-way screen, a marked window the subject sees, the same window's switch cleared + and restored (retraction and re-earn), a marked solid wall and a marked window the subject never + sees. `tools/leak.test.mjs` asserts that coverage from the GM's wall frames and the subject's + marker frames, so a rewrite that drops an element fails on its own, not only inside a fault. All + pre-existing classes still fire under the rewrite, each as exactly its own class (all 21 entries + of the `FAULTS` table of `tools/fault.test.mjs`, 22 tests with the clean-build gate). `tools/leakcheck.nim` refuses the `gm` bucket, the `owner` bucket on a non-controller and any `source` on a player status entry. Two consequences: the `hidden` and @@ -464,7 +472,9 @@ from the prototype, what was missing, what the M3 build added, and the tools it `set` and `del` for one id in a frame, no explored write from a pure retraction, and durability of the deletes across a restart. A `LEAK_FAULT=markerCrash` hook quits in a `-d:leakfault` build between the wall commit and the derived write; after a restart the changed wall's marker is gone - for all four causes while the untouched window's marker is restored (the positive control). + for all four causes while the untouched window's marker is restored (the positive control). The + leak scenario (#61) also drives one retraction and one re-earn end to end, so the transcript + checker's own memory drop is exercised inside the world. - **Wall fields, storage and migration (#49).** Three gates. **Leak:** `BannedAlways` contains every wall field name (`thickness`, `position`, `height`, `blocks_sight`, `blocks_movement`, `sight_dir`, `player_marker`, `door`, `open`, `secret`, `locked`, `label`, `a`, `b`), so any of them in a player diff --git a/tools/groups.mjs b/tools/groups.mjs index a7875db..1e49ad1 100644 --- a/tools/groups.mjs +++ b/tools/groups.mjs @@ -5,10 +5,15 @@ // tokens, details, scene, wsheaders) still run; they are not listed here. export const GROUPS = { 'leak+fault': { - files: ['leak.test.mjs', 'fault.test.mjs'], + // The transcript checker and its negative controls, plus the two Walls r1 harnesses whose + // guarantees ride the same seam: the differential door equivalence (the `secretgap` control, + // #56) and the player marker group (#59/#60). #61's scenario rewrite keeps all of them green. + files: ['leak.test.mjs', 'fault.test.mjs', 'doors.test.mjs', 'markers.test.mjs'], evidence: [ ['leak.test.mjs', 'leak test ${subject}: the subject\'s whole view matches the GM\'s truth'], ['fault.test.mjs', 'caught as exactly'], + ['doors.test.mjs', 'fault secretgap: the equivalence group fails as exactly SECRETGAP'], + ['markers.test.mjs', 'retraction: every cause sends del only, a re-earned marker gets a fresh id (#60)'], ], }, tiles: { diff --git a/tools/leak.mjs b/tools/leak.mjs index 5eb1c3f..eef62ee 100644 --- a/tools/leak.mjs +++ b/tools/leak.mjs @@ -1,32 +1,35 @@ -// Leak test driver (DESIGN 10.1, 10.3; M3 slice 5 / #20). Builds a known scene over the real wire, -// then plays a scripted narrative with ONE mutation per group and writes every frame each socket -// received to a JSONL transcript. tools/leakcheck.nim replays it: the GM socket is ground truth, -// the subject's own messages are only ever checked, never trusted. +// Leak test driver (DESIGN 10.1, 10.3; M3 slice 5 / #20; scenario rewrite Walls r1 #61). Builds a +// known scene over the real wire, then plays a scripted narrative with ONE mutation per group and +// writes every frame each socket received to a JSONL transcript. tools/leakcheck.nim replays it: the +// GM socket is ground truth, the subject's own messages are only ever checked, never trusted. // // Groups: a marker line, one action, then "quiescent" (no frame for QUIET ms on any socket). That // is what lets the checker evaluate a group as one state: every mutation is its own group, so the // truth after the group is the truth the group's frames describe. // -// The scenario (4096 px world, 32 px cells, 400 px vision, token radius 20) is built to exercise -// every way a token can enter or leave a player's view: -// - visible at the first resync (M1, and the subject's own token) -// - hidden behind a closed door, revealed by opening it (M2) -// - removed from view by moving away, and re-entering -// - created and removed while in view -// - a `gm_only` token inside LOS that must never appear (M3) -// - a controller change: handed to the subject while out of sight, handed back -// - another player's token walking in and out (A sees B) -// - 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 -// - Walls r1 (#58): a one-way wall the subject sees across (`sight_dir` names the token's side -// blind), the ONEWAY fault's positive source and the blind-side oracle's control -// - Walls r1 (#60): a marked window far outside every scripted position and a marked solid wall -// in the room, the negative controls for MARKER_EARLY and MARKER_EXTRA; the marker retraction -// rules themselves are proven by tools/markers.test.mjs (the final scenario rewrite is #61) +// THE WORLD (4096 px, 32 px cells, 400 px vision, token radius 20) is one coherent scene, not a list +// of appendages. Every element is there to be sight-tested, and each carries exactly one obligation: +// +// - the room x 500..1400, entered through an opening door in the west wall; the subject +// starts west of it, so "behind a closed door" and "through it" are both shown +// - far wall x = 1400: solid, a secret door, solid, a locked door. N3 and N4 stand behind +// them and are as invisible as a token behind solid wall (5.8, T17): the +// checker recomputes from `blocks_sight` alone, never from `secret`/`locked` +// - one-way screen the southern hall is split at x = 700 with `sight_dir:"right"` (east blind); +// the subject, west of it, sees across to the sentry E2 (#58) +// - markers a marked opening window in the room (seen: the positive control), the same +// window's switch cleared and restored (the retraction/re-earn path, #60), a +// marked solid wall in the room (switch on, no marker: MARKER_EXTRA control) +// and a marked window far outside every scripted position (never seen: +// MARKER_EARLY control) +// - the rest a token hidden behind the closed door and revealed by opening it, tokens +// created/removed while watched, a `gm_only` token inside LOS, a controller +// handed over and back, another player walking in and out, a wall added and +// removed in sight, a door closing on a token (the 5.5 push), and the slice 7/8 +// property, status, name and character groups +// +// Every pre-existing fault class keeps its witness here, so the rewrite traded no old obligation +// for a new one; tools/fault.test.mjs asserts each class exactly. import fs from 'node:fs' import path from 'node:path' import { spawnSync } from 'node:child_process' @@ -70,6 +73,70 @@ async function connect(origin, key, who, log, group) { } } +// The world: one fixture per obligation. `role` is the handle later groups and the coverage +// assertion use, so no group has to count positions in a list (the old `wallIds[1]` fragility). +const WORLD = [ + // West wall x = 500, y 0..1000 with an opening door (y 400..700). The subject starts west of it. + { role: 'west-north', a: [500, 0], b: [500, 400] }, + { role: 'west-door', a: [500, 400], b: [500, 700], door: true, open: false }, + { role: 'west-south', a: [500, 700], b: [500, 1000] }, + // Far wall x = 1400: solid, secret door, solid, locked door. `secret`/`locked` are ordinary + // closed door switches; to a player the three blockers are indistinguishable (5.8, T17). + { role: 'far-north', a: [1400, 400], b: [1400, 620] }, + { role: 'far-secret', a: [1400, 620], b: [1400, 720], door: true, secret: true }, + { role: 'far-middle', a: [1400, 720], b: [1400, 820] }, + { role: 'far-locked', a: [1400, 820], b: [1400, 920], door: true, locked: true }, + // One-way screen: the wall's right (east) side is blind, so a subject west of it sees across. + { role: 'one-way-screen', a: [700, 1200], b: [700, 1400], sight_dir: 'right' }, + // Marked window in the room, the positive marker control: anchor (520, 800) (#59). + { role: 'marked-window', preset: 'window', a: [520, 700], b: [520, 900] }, + // Marked solid wall in the room: the switch is on but the shape is a wall, so no marker may be + // minted (the MARKER_EXTRA negative control, #60). + { role: 'marked-solid', a: [620, 760], b: [720, 760], player_marker: true }, + // Marked window far outside every scripted position: never seen, so never a marker (the + // MARKER_EARLY negative control, #60). + { role: 'marked-unseen', preset: 'window', a: [3500, 2000], b: [3500, 2200] }, +] + +const isWindow = w => w.blocks_sight === false && w.blocks_movement === true +const anchorOf = w => [Math.round((w.a[0] + w.b[0]) / 2), Math.round((w.a[1] + w.b[1]) / 2)] + +// The scenario's own coverage, read off the GM's wall frames and the subject's marker frames. The +// acceptance contract of #61 is a world holding each of these elements, so the test proves the +// scenario really has them instead of trusting the list above: a rewrite that silently drops the +// locked door, the one-way wall or one side of the marker sight test fails loudly. +export function scenarioCoverage(gmMsgs, subjMsgs) { + const walls = new Map() + for (const m of gmMsgs) { + if (!m || typeof m.t !== 'string') continue + if (m.t === 'walls') { + walls.clear() + for (const w of m.walls) walls.set(w.id, w) + } else if (m.t === 'wall') walls.set(m.id, m) + else if (m.t === 'wall_gone') walls.delete(m.id) + } + const all = [...walls.values()] + const received = new Set() + for (const m of subjMsgs) { + if (!m || m.t !== 'marker') continue + for (const e of m.set ?? []) received.add(e.pos.join(',')) + } + const marked = all.filter(w => w.player_marker) + const windows = marked.filter(isWindow) + return { + walls: all.length, + oneWay: all.filter(w => w.sight_dir !== 'both').length, + secretDoors: all.filter(w => w.secret).length, + lockedDoors: all.filter(w => w.locked).length, + markedWindows: windows.length, + markedNonWindows: marked.filter(w => !isWindow(w)).length, + // "both sides of the sight test": a marked window the subject earned and one it did not. + markedWindowsSeen: windows.filter(w => received.has(anchorOf(w).join(','))).length, + markedWindowsUnseen: windows.filter(w => !received.has(anchorOf(w).join(','))).length, + markers: received.size, + } +} + export async function runLeak({ origin, gmKey, stateDir, transcript, keepOpen = false }) { // The transcript is written in group order; the checker needs nothing else. const lines = [] @@ -115,26 +182,15 @@ export async function runLeak({ origin, gmKey, stateDir, transcript, keepOpen = flush() } - // --- the scene ------------------------------------------------------------------------------- - // x = 500 is a wall with a door in the middle (y 400..700): the subject starts west of it. - const wallsToAdd = [ - { a: [500, 0], b: [500, 400] }, - { a: [500, 400], b: [500, 700], door: true, open: false }, - { a: [500, 700], b: [500, 1000] }, - { a: [1400, 400], b: [1400, 900] }, - // Walls r1 (#60) fault controls, added last so `wallIds[1]` stays the door. The window is far - // outside every scripted position: only a build that drops the extent gate (MARKER_EARLY) - // sends it. The solid wall with the switch on stands in the room the subject enters: only a - // build that drops the derived-window gate (MARKER_EXTRA) sends a marker for it. - { preset: 'window', a: [3500, 2000], b: [3500, 2200] }, - { a: [620, 760], b: [720, 760], player_marker: true }, - ] - const wallIds = [] + const wallIds = {} // role -> id, so a later group never indexes into creation order + const ids = {} + const characters = {} - const addWall = async fields => { + const addWall = async spec => { + const { role, ...fields } = spec const ack = await gm.request({ t: 'wall.add', scene, ...fields }) - if (ack.ok !== true) throw new Error(`wall.add refused: ${JSON.stringify(ack)}`) - wallIds.push(ack.id) + if (ack.ok !== true) throw new Error(`wall.add refused (${role ?? 'transient'}): ${JSON.stringify(ack)}`) + if (role !== undefined) wallIds[role] = ack.id return ack.id } @@ -144,13 +200,8 @@ export async function runLeak({ origin, gmKey, stateDir, transcript, keepOpen = ids[id] = ack.id return ack.id } - const ids = {} - const characters = {} - const move = async (client, id, pos) => { - const ack = await client.request({ t: 'token.move', id, pos }) - return ack - } + const move = async (client, id, pos) => client.request({ t: 'token.move', id, pos }) // Two named players: the naming is the fixture of lib.mjs (player.setname is slice 8). const playerA = await createPlayer(gm.ws) @@ -158,11 +209,12 @@ export async function runLeak({ origin, gmKey, stateDir, transcript, keepOpen = await namePlayer(origin, playerA.key, 'Subject A') await namePlayer(origin, playerB.key, 'Player B') - await group('walls', async () => { - for (const w of wallsToAdd) await addWall(w) + // --- the world and its cast ---------------------------------------------------------------- + await group('the world', async () => { + for (const w of WORLD) await addWall(w) }) - await group('tokens', async () => { + await group('the cast', async () => { await createToken('A', { kind: 'pc', pos: [300, 300], descriptive_name: 'A', actual_name: 'A', controller: playerA.id, flags: { vision: true } }) await createToken('B', { kind: 'pc', pos: [300, 3000], descriptive_name: 'B', actual_name: 'B', @@ -175,37 +227,46 @@ export async function runLeak({ origin, gmKey, stateDir, transcript, keepOpen = actual_name: 'The Hidden', gm_only: true }) await createToken('M4', { kind: 'item', pos: [3500, 3500], descriptive_name: 'a chest', actual_name: 'The Vault' }) + // Behind the far wall's secret and locked doors: never visible, and never named. + await createToken('N3', { kind: 'npc', pos: [1500, 670], descriptive_name: 'a scribe', + actual_name: 'Brother Ivo' }) + await createToken('N4', { kind: 'npc', pos: [1500, 870], descriptive_name: 'a jailer', + actual_name: 'Warden Hale' }) }) const A = await connect(origin, playerA.key, 'A', log, () => g) clients.push(A) await A.ws.waitText('hello') - await group('connect subject', async () => { await sleep(0) }) + await group('the subject connects', async () => { await sleep(0) }) const B = await connect(origin, playerB.key, 'B', log, () => g) clients.push(B) await B.ws.waitText('hello') - await group('connect other', async () => { await sleep(0) }) + await group('the other player connects', async () => { await sleep(0) }) - // A walks from (300,300) to just west of the door. - await group('A walks to the door', async () => { + // --- through the door ---------------------------------------------------------------------- + // A walks from (300,300) to just west of the door; M2 waits behind it. + await group('A walks up to the closed door', async () => { expectAck(await move(A, ids.A, [350, 600]), true) }) - await group('A at the door', async () => { + await group('A stands at the door', async () => { expectAck(await move(A, ids.A, [350, 620]), true) }) await group('M2 is hidden behind the closed door', async () => { await sleep(0) }) await group('GM opens the door', async () => { - const ack = await gm.request({ t: 'door.set', scene, id: wallIds[1], open: true }) + const ack = await gm.request({ t: 'door.set', scene, id: wallIds['west-door'], open: true }) if (ack.ok !== true) throw new Error(`door.set refused: ${JSON.stringify(ack)}`) }) + // In the room the subject also first sees the marked window: its marker is earned here. await group('A steps through the door', async () => { expectAck(await move(A, ids.A, [560, 600]), true) }) await group('A steps into the room', async () => { expectAck(await move(A, ids.A, [600, 640]), true) }) + + // --- sight, hiding and seeing --------------------------------------------------------------- await group('GM moves M1 into the room', async () => { expectAck(await move(gm, ids.M1, [700, 700]), true) }) @@ -242,22 +303,23 @@ export async function runLeak({ origin, gmKey, stateDir, transcript, keepOpen = await group('GM walks the other player out', async () => { expectAck(await move(gm, ids.B, [420, 1500]), true) }) - await group('GM adds a wall in the subject sight', async () => { - await addWall({ a: [400, 900], b: [900, 900] }) + await group('GM adds a plain wall in the subject sight', async () => { + await addWall({ role: 'transient-wall', a: [400, 910], b: [900, 910] }) }) await group('GM removes it again', async () => { - const ack = await gm.request({ t: 'wall.remove', scene, id: wallIds[wallIds.length - 1] }) + const ack = await gm.request({ t: 'wall.remove', scene, id: wallIds['transient-wall'] }) if (ack.ok !== true) throw new Error(`wall.remove refused: ${JSON.stringify(ack)}`) }) await group('GM puts M2 on the door line', async () => { expectAck(await move(gm, ids.M2, [500, 600]), true) }) await group('GM closes the door: the server pushes M2 aside', async () => { - const ack = await gm.request({ t: 'door.set', scene, id: wallIds[1], open: false }) + const ack = await gm.request({ t: 'door.set', scene, id: wallIds['west-door'], 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. + + // --- properties, statuses and shapes (slice 7, #22) ------------------------------------------ + // N2 sits near 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' }) @@ -278,7 +340,7 @@ export async function runLeak({ origin, gmKey, stateDir, transcript, keepOpen = 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] }) + await addWall({ role: 'over-n2', a: [700, 560], b: [700, 660] }) }) await group('GM unsets the public prop of N2', async () => { const unset = await gm.request({ t: 'prop.unset', target: 'token', id: ids.N2, @@ -291,19 +353,11 @@ export async function runLeak({ origin, gmKey, stateDir, transcript, keepOpen = 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.request({ t: 'wall.remove', scene, - id: wallIds[wallIds.length - 1] }) + const ack = await gm.request({ t: 'wall.remove', scene, id: wallIds['over-n2'] }) if (ack.ok !== true) throw new Error(`wall.remove refused: ${JSON.stringify(ack)}`) }) - // Walls r1 (#59): a marked window in the subject's sight. The window preset carries the marker, - // so the subject gets exactly one opaque-id anchor after the explored diff; the checker's own - // visible-extent oracle independently expects the drawn midpoint (520,800). It sits in the room, - // east of the x=500 walls and clear of every scripted path (x >= 560 or the door line). - await group('GM adds a marked window in the subject sight', async () => { - await addWall({ preset: 'window', a: [520, 700], b: [520, 900] }) - }) - // Slice 8 (#23): characters, names and the encountered list. Every group here is one the subject - // receives: A is in the room, and C1's token is placed next to A's own. + + // --- characters, names and the encountered list (slice 8, #23) ------------------------------ await group('GM creates a character owned by the other player', async () => { const ack = await gm.request({ t: 'character.create', descriptive_name: 'a cloaked figure', actual_name: 'Lady Vex', owner: playerB.id }) @@ -383,19 +437,48 @@ export async function runLeak({ origin, gmKey, stateDir, transcript, keepOpen = if (ack.ok !== true) throw new Error(`encountered.remove refused: ${JSON.stringify(ack)}`) }) - await group('A walks away from the door', async () => { + // --- marker memory: retract and re-earn (#60) ----------------------------------------------- + // A still sees the marked window from the room. Clearing the switch retracts its marker (a `del` + // only, never a new anchor); restoring it re-earns one with a fresh id, because the old id died. + // The checker's oracle mirrors the rule from the GM's wall frames, so both directions are checked + // against its own memory, not against what the server sent. + await group('GM clears the marked window player marker', async () => { + const ack = await gm.request({ t: 'wall.update', scene, id: wallIds['marked-window'], + player_marker: false }) + if (ack.ok !== true) throw new Error(`wall.update refused: ${JSON.stringify(ack)}`) + }) + await group('GM turns the marker back on', async () => { + const ack = await gm.request({ t: 'wall.update', scene, id: wallIds['marked-window'], + player_marker: true }) + if (ack.ok !== true) throw new Error(`wall.update refused: ${JSON.stringify(ack)}`) + }) + + // --- the far wall: a secret and a locked door (5.8, T17) ------------------------------------ + // A walks up to the far wall. N3 and N4 are 200 px away behind the two doors, well inside sight: + // with any of the three blockers missing they would be in the polygon, so their absence here is + // the leak-checker's proof that a secret or locked door is a solid wall to this player. The walk + // is in step-cap legs (a player's move is capped at its vision radius, 5.5). + await group('A walks east across the room', async () => { + expectAck(await move(A, ids.A, [950, 645]), true) + }) + await group('A walks up to the far wall', async () => { + expectAck(await move(A, ids.A, [1300, 650]), true) + }) + await group('the secret and locked doors are solid wall to the subject', async () => { await sleep(0) }) + + // --- the southern hall and the one-way screen (#58) ----------------------------------------- + await group('A walks away from the far wall', async () => { + expectAck(await move(A, ids.A, [930, 800]), true) + }) + await group('A walks back towards the door', async () => { expectAck(await move(A, ids.A, [560, 950]), true) }) await group('A walks further south', async () => { expectAck(await move(A, ids.A, [560, 1300]), true) }) - // Walls r1 (#58): a one-way wall between the subject (west) and a token on its blind (east) side. - // `sight_dir:"right"` names the east side blind, so the subject sees across; the ONEWAY fault - // drops `sight_dir` and the same wall would hide E2 and shrink the subject's fan. - await group('GM adds a one-way wall east of the subject', async () => { - await addWall({ a: [700, 1200], b: [700, 1400], sight_dir: 'right' }) - }) - await group('GM puts a token behind the one-way wall (the subject sees across)', async () => { + // `sight_dir:"right"` names the east side blind, so the subject west of the screen sees across; + // the ONEWAY fault drops `sight_dir` and the same wall would hide E2 and shrink the fan. + await group('GM puts a sentry behind the one-way screen (the subject sees across)', async () => { await createToken('E2', { kind: 'npc', pos: [800, 1300], descriptive_name: 'a sentry', actual_name: 'Sentry' }) }) @@ -408,7 +491,8 @@ export async function runLeak({ origin, gmKey, stateDir, transcript, keepOpen = fs.mkdirSync(path.dirname(transcript), { recursive: true }) fs.writeFileSync(transcript, lines.join('\n') + '\n') - return { transcript, groups: g, walls: wallIds, tokens: ids, characters } + const coverage = scenarioCoverage(gm.ws.messages, A.ws.messages) + return { transcript, groups: g, walls: wallIds, tokens: ids, characters, coverage } } function expectAck(ack, ok) { diff --git a/tools/leak.test.mjs b/tools/leak.test.mjs index 2e3c6f0..87ea50d 100644 --- a/tools/leak.test.mjs +++ b/tools/leak.test.mjs @@ -22,6 +22,21 @@ for (const subject of ['A', 'B']) { try { const run = await runLeak({ origin: s.origin, gmKey, stateDir, transcript }) assert.ok(run.groups > 15, `the scenario must have real coverage, got ${run.groups} groups`) + if (subject === 'A') { + // #61: the world's own contract, read off the GM's wall frames and the subject's markers. + // A rewrite that drops an element (or a side of the marker sight test) fails here, not in + // a fault that happens to stop firing. + const cov = run.coverage + assert.ok(cov.oneWay >= 1, `the world needs a one-way wall: ${JSON.stringify(cov)}`) + assert.ok(cov.secretDoors >= 1, `the world needs a secret door: ${JSON.stringify(cov)}`) + assert.ok(cov.lockedDoors >= 1, `the world needs a locked door: ${JSON.stringify(cov)}`) + assert.ok(cov.markedNonWindows >= 1, + `the world needs a marked non-window wall (MARKER_EXTRA control): ${JSON.stringify(cov)}`) + assert.ok(cov.markedWindowsSeen >= 1, + `the world needs a marked window the subject sees: ${JSON.stringify(cov)}`) + assert.ok(cov.markedWindowsUnseen >= 1, + `the world needs a marked window the subject never sees (MARKER_EARLY control): ${JSON.stringify(cov)}`) + } const check = runChecker(transcript, subject) fs.writeFileSync(path.join(results, `leak-${subject}.log`), check.output) assert.equal(check.status, 0, `${check.output}\n--- server log ---\n${s.log()}`)