// 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-.{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 }) } }) }