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).
68 lines
2.7 KiB
JavaScript
68 lines
2.7 KiB
JavaScript
// Negative controls for the leak checker (DESIGN 10.1 "fault test", 10.3; M3 slice 5 / #20).
|
|
// Every deliberate leak injected into a `-d:leakfault` build must make tools/leakcheck.nim fail,
|
|
// 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.)
|
|
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 { buildServer, gmKeyOf, makeStateDir, startServer, stopServer } from './withserver.mjs'
|
|
import { projectRoot } from './lib.mjs'
|
|
|
|
const results = path.join(projectRoot, 'results')
|
|
|
|
// fault -> the exact set of classes the checker must report (nothing more, nothing less)
|
|
const FAULTS = {
|
|
hidden: ['HIDDEN_TOKEN'],
|
|
gmOnly: ['GMONLY_TOKEN'],
|
|
walls: ['WALLDATA'],
|
|
withhold: ['WITHHELD'],
|
|
otherOwner: ['OTHER_PLAYER'],
|
|
otherVision: ['OTHER_PLAYER'],
|
|
otherExplored: ['OTHER_PLAYER'],
|
|
noremove: ['NO_REMOVE'],
|
|
explored: ['EXPLORED'],
|
|
}
|
|
|
|
function classesOf(output) {
|
|
return output.split('\n')
|
|
.map(line => /^FAILCLASS ([A-Z_]+) \d+/.exec(line))
|
|
.filter(Boolean)
|
|
.map(m => m[1])
|
|
.sort()
|
|
}
|
|
|
|
test('the shipped build carries no fault hook and passes the leak test', () => {
|
|
const bin = buildServer()
|
|
const bytes = fs.readFileSync(bin)
|
|
assert.equal(bytes.includes(Buffer.from('LEAK_FAULT')), false,
|
|
`${bin} contains the fault hook: a production binary must be incapable of leaking`)
|
|
})
|
|
|
|
for (const [fault, expected] of Object.entries(FAULTS)) {
|
|
test(`fault ${fault}: caught as exactly ${expected.join(' ')}`, async () => {
|
|
fs.mkdirSync(results, { recursive: true })
|
|
const stateDir = makeStateDir()
|
|
const gmKey = gmKeyOf(stateDir)
|
|
const s = await startServer({ stateDir, defines: ['leakfault'], env: { LEAK_FAULT: fault } })
|
|
const transcript = path.join(stateDir, 'fault.jsonl')
|
|
try {
|
|
await runLeak({ origin: s.origin, gmKey, stateDir, transcript })
|
|
const check = runChecker(transcript, 'A')
|
|
fs.appendFileSync(path.join(results, 'faults.log'),
|
|
`== fault ${fault}\n${check.output}\n`)
|
|
assert.notEqual(check.status, 0, `the checker passed a leak (${fault}):\n${check.output}`)
|
|
assert.deepEqual(classesOf(check.output), expected.sort(),
|
|
`wrong classes for ${fault}:\n${check.output}`)
|
|
} finally {
|
|
await stopServer(s)
|
|
fs.rmSync(stateDir, { recursive: true, force: true })
|
|
}
|
|
})
|
|
}
|