Files
FFF_vtt_frozen/tools/fault.test.mjs
T
SirStone c3c0a39188 feat(walls): marker retraction, re-earn and marker fault classes (#60)
Retract a player marker when the GM removes the wall, clears
player_marker, makes the wall stop deriving window, or moves its
geometry (a/b, thickness, position). Retraction emits del only and
never the new anchor; a re-earned marker gets a fresh id. The
marker_seen deletes ride the same derived-memory NORMAL transaction as
the explored chunks, after the wall row commits and before the ack.

Replace the leak checker's aggregate MARKER class with MARKER_EARLY,
MARKER_EXTRA and MARKER_OFF, add their leakfault hooks and exact-class
fault tests, and extend the leak scenario with an unseen marked window
and a marked solid wall as the negative controls. WS black-box tests
cover all four causes, fresh re-earns, no untouched re-send, no
set/del for one id in a frame, no explored write from a retraction,
and delete/cascade durability across a restart.
2026-11-19 23:43:44 +01:00

88 lines
3.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: HIDDEN_TOKEN, GMONLY_TOKEN, WALLDATA, WITHHELD, NO_REMOVE, OWN_VIEW, OTHER_PLAYER,
// EXPLORED, from slice 7 (#22) OWNER_PROP, GM_PROP, STATUS_SOURCE, and from slice 8 (#23)
// ACTUAL_NAME, CHAR_LIST, CONTROLLER_CHANGE, CHAR_OWNER_PROP, and from Walls r1 (#58) ONEWAY and
// (#60) MARKER_EARLY, MARKER_EXTRA, MARKER_OFF.
// (The tile class lands 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).
//
// `hidden` and `gmOnly` carry NO_REMOVE as well, and that is not a slack assertion: a state frame is
// sent only when its content changes (T11, 6.4), so a token leaked by one of these faults that stops
// changing leaves the client holding it with no message to correct it. From the client's side that
// is indistinguishable from a withheld `token_gone`, which is what NO_REMOVE reports. Both
// invariants really are broken by the fault.
const FAULTS = {
hidden: ['HIDDEN_TOKEN', 'NO_REMOVE'],
gmOnly: ['GMONLY_TOKEN', 'NO_REMOVE'],
walls: ['WALLDATA'],
wallHeight: ['WALLDATA'],
oneWay: ['ONEWAY'],
markerEarly: ['MARKER_EARLY'],
markerExtra: ['MARKER_EXTRA'],
markerOff: ['MARKER_OFF'],
withhold: ['WITHHELD'],
otherOwner: ['OTHER_PLAYER'],
otherVision: ['OTHER_PLAYER'],
otherExplored: ['OTHER_PLAYER'],
noremove: ['NO_REMOVE'],
explored: ['EXPLORED'],
ownerProp: ['OWNER_PROP'],
gmProp: ['GM_PROP'],
statusSource: ['STATUS_SOURCE'],
actualName: ['ACTUAL_NAME'],
charList: ['CHAR_LIST'],
controllerChange: ['CONTROLLER_CHANGE'],
charOwnerProp: ['CHAR_OWNER_PROP'],
}
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 })
}
})
}