test: tie group evidence to passing tests and baseline restart on the as-built server (#36)

- tools/groups.mjs evidence entries now name the exact test, a minimum assertion
  count and the calls its body must keep; groups.test.mjs checks all three.
- tools/evidence.mjs parses the spec reporter log and fails the gate unless every
  registered evidence test ran and passed; test.sh runs it after the Node suite.
- restart.test.mjs snapshots the live as-built world on the first server, then
  compares it to the post-SIGTERM/SIGKILL state (players connect before the GM, so
  the GM's derived encountered grey is computed on both sides).
- Negative controls: a hollowed auth test fails the new evidence check; a planted
  first-load drop of a token's gm prop bucket fails the new restart baseline while
  the old restart-to-restart test passed.
- Refresh the gate evidence (control + 73 mutations incl. s1-s7, 142 node tests).
This commit is contained in:
2026-11-20 21:55:50 +01:00
parent b0e1633aa9
commit 1f11779658
10 changed files with 816 additions and 216 deletions
+35 -20
View File
@@ -201,15 +201,24 @@ function expectedEncounteredName(who, ids) {
[ids.linked]: 'a cloaked figure', [ids.pc]: 'Wanderer' }
}
// The full before/after comparison: one fresh GM connection and one fresh connection per player.
async function compareAcross(origin, gmKey, players, ids, expected) {
const beforeGm = await snapshot(origin, gmKey, expected, true)
const before = { gm: beforeGm }
// The full before/after comparison: one fresh connection per player and one fresh GM connection.
// #36: players connect first, so their live sight state is computed before the GM's per-player
// `encountered` lists (whose `grey` is a live sight test, not stored state) are read. Connecting
// them only after the GM would compare a refreshed restarted server against an unrefreshed one.
async function snapshotAll(origin, gmKey, players, expected) {
const all = {}
for (const [who, p] of Object.entries(players)) {
// Only the character's owner is sent a `character` record (6.1).
before[who] = await snapshot(origin, p.key,
{ ...expected, characters: who === 'alice' ? 1 : 0 }, false)
all[who] = await snapshot(origin, p.key,
{ ...expected, characters: who === 'alice' ? 1 : 0 }, false)
}
all.gm = await snapshot(origin, gmKey, expected, true)
return all
}
async function compareAcross(origin, gmKey, players, ids, expected) {
const before = await snapshotAll(origin, gmKey, players, expected)
const beforeGm = before.gm
// The CRUD inventory is not empty: a restart test over an empty world would prove nothing.
assert.ok(beforeGm.walls.walls.length >= 2, 'the wall and the door are there')
assert.equal(beforeGm.walls.walls.find(w => w.id === ids.door).open, true, 'the door is open')
@@ -242,11 +251,10 @@ async function compareAcross(origin, gmKey, players, ids, expected) {
return before
}
async function restartAndCompare(stateDir, gmKey, players, ids, expected, hard) {
let s = await startServer({ stateDir })
const before = await compareAcross(s.origin, gmKey, players, ids, expected)
// Kill the server that holds the as-built world. SIGKILL is deliberate for the hard variant: every
// ack is sent after COMMIT (4.2), so a hard kill cannot lose an acked mutation.
async function stopWithSignal(s, hard) {
if (hard) {
// Every ack is sent after COMMIT (4.2), so a hard kill cannot lose an acked mutation.
s.child.kill('SIGKILL')
const deadline = Date.now() + 5000
while (s.child.signalCode === null && s.child.exitCode === null && Date.now() < deadline) {
@@ -254,19 +262,22 @@ async function restartAndCompare(stateDir, gmKey, players, ids, expected, hard)
}
}
await stopServer(s)
}
s = await startServer({ stateDir })
// #36: `before` is the snapshot of the *as-built* world on the first server instance, taken after
// the CRUD and before any restart. The old version took it after a restart, so a field silently
// dropped on the first load was missing from both sides and the deepEqual held.
async function restartAndCompare(stateDir, before, gmKey, players, ids, expected) {
let s = await startServer({ stateDir })
try {
const afterGm = await snapshot(s.origin, gmKey, expected, true)
assert.deepEqual(afterGm, before.gm, 'the GM resync after the restart is identical')
for (const [who, p] of Object.entries(players)) {
const after = await snapshot(s.origin, p.key,
{ ...expected, characters: who === 'alice' ? 1 : 0 }, false)
assert.deepEqual(after, before[who],
const after = await snapshotAll(s.origin, gmKey, players, expected)
assert.deepEqual(after.gm, before.gm, 'the GM resync after the restart is identical')
for (const who of Object.keys(players)) {
assert.deepEqual(after[who], before[who],
`${who}'s resync after the restart is identical`)
// ... and the absolute truth, so two equally wrong snapshots cannot pass (#27).
for (const [id, name] of Object.entries(expectedEncounteredName(who, ids))) {
assert.equal(after.encountered.set.find(e => e.id === id)?.name, name,
assert.equal(after[who].encountered.set.find(e => e.id === id)?.name, name,
`${who}'s encountered entry for ${id} after the restart`)
}
}
@@ -305,6 +316,7 @@ async function restartGroup(hard) {
let s = await startServer({ stateDir })
let saved
let markerRows
let before
try {
saved = await buildWorld(s.origin, gmKey)
players.alice = saved.alice
@@ -331,11 +343,14 @@ async function restartGroup(hard) {
assert.equal(linkedRows[String(saved.bob.id)], '')
assert.equal(linkedRows[String(saved.carol.id)], '',
'the reveal to Alice did not write Bob\'s or Carol\'s row (#27)')
// #36: the baseline is this live server's full resync, built by the CRUD above and never
// reloaded from disk. A field lost when the first server reloads the DB fails the comparison.
before = await compareAcross(s.origin, gmKey, players, saved.ids, EXPECTED)
} finally {
await stopServer(s)
await stopWithSignal(s, hard)
}
try {
await restartAndCompare(stateDir, gmKey, players, saved.ids, EXPECTED, hard)
await restartAndCompare(stateDir, before, gmKey, players, saved.ids, EXPECTED)
assert.deepEqual(dbMarkerRows(stateDir, saved.ids.window), markerRows,
'the marker_seen rows (player and opaque id) survive the restart unchanged')
} finally {