54 lines
2.9 KiB
JavaScript
54 lines
2.9 KiB
JavaScript
// 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`)
|
|
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)}`)
|
|
assert.ok(cov.markedWindowsOccluded >= 1,
|
|
`the world needs a marked window behind the far wall (TESTING 5.8): ${JSON.stringify(cov)}`)
|
|
assert.equal(cov.markedWindowsOccludedSeen, 0,
|
|
`a wall behind a sight blocker yields no marker: ${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()}`)
|
|
assert.match(check.output, / 0 failures/)
|
|
} finally {
|
|
await stopServer(s)
|
|
fs.rmSync(stateDir, { recursive: true, force: true })
|
|
}
|
|
})
|
|
}
|