tools: leak driver, checker and the fault controls (#20)

tools/leak.mjs builds a 27-group scene over the real wire (movement, a closed door,
create/remove, gm_only, a controller hand-over, another player walking in and out, a
wall added and removed, a door push) and records every frame each socket saw, one
group per mutation. tools/leakcheck.nim replays it: the GM socket is ground truth,
the subject's polygons and explored cells are recomputed from geometry.nim, and the
explored set is also probed with a clear-segment sampler. Subjects A and B both pass
with zero failures; the transcripts and logs land in results/.

tools/fault.test.mjs runs the same scenario against a -d:leakfault build for each
fault and asserts the EXACT class set (HIDDEN_TOKEN, GMONLY_TOKEN, WALLDATA,
WITHHELD, OTHER_PLAYER, NO_REMOVE, EXPLORED), plus that the shipped binary carries no
LEAK_FAULT string.

withserver can build a variant with extra -d: flags and pass an env to it; lib.mjs
can name a player out of band, the fixture the player-side tests need until slice 8
brings player.setname (the unnamed gate itself is pinned in tools/tokens.test.mjs).
This commit is contained in:
2026-11-15 09:35:24 +01:00
parent 6fcf7f8271
commit 959412ff09
6 changed files with 861 additions and 9 deletions
+34
View File
@@ -0,0 +1,34 @@
// M3 slice 5 (#20), leak test A and B (DESIGN 10.1 "leak test", 10.3): the driver builds a scene
// over the real wire and records every frame each socket saw; tools/leakcheck.nim then verifies the
// subject's whole view against the GM socket (ground truth) and its own geometry. One run per
// subject on its own server; logs land in results/leak-<subject>.{jsonl,log}.
import test from 'node:test'
import assert from 'node:assert/strict'
import fs from 'node:fs'
import path from 'node:path'
import { runLeak, runChecker } from './leak.mjs'
import { gmKeyOf, makeStateDir, startServer, stopServer } from './withserver.mjs'
import { projectRoot } from './lib.mjs'
const results = path.join(projectRoot, 'results')
for (const subject of ['A', 'B']) {
test(`leak test ${subject}: the subject's whole view matches the GM's truth`, async () => {
fs.mkdirSync(results, { recursive: true })
const stateDir = makeStateDir()
const gmKey = gmKeyOf(stateDir)
const s = await startServer({ stateDir })
const transcript = path.join(results, `leak-${subject}.jsonl`)
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`)
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()}`)
assert.match(check.output, / 0 failures/)
} finally {
await stopServer(s)
fs.rmSync(stateDir, { recursive: true, force: true })
}
})
}