names: per-player reveal, one encountered write path, link by update (#27, #29, #30)

name.reveal wrote the subject's actual name into the encountered row of every
player who had met it: the SQL had no player predicate, so the leak was silent
live and visible only after a restart. rewriteEncountered is now the one path
that keeps a snapshot in step with its subject: it rewrites the SQLite row and
the live in-memory entry together from the name rule, takes onlyPlayer for
name.reveal (every player for reveal_all), and also runs on a rename, a link
change and an owner change, so the wire and a post-restart reload cannot
disagree (#30). The DB-only renameEncountered*/revealEncountered* helpers are
gone, which is what let the two stores drift.

token.update {character_id} now drops the token's own two names as part of the
link patch (#29): a plain token can be linked, names supplied with a link stay
invalid and unlinking still needs both names.

Tests: tcharacters covers the per-player row, the DB/memory equality, the link
handover; restart.test.mjs builds three named players, reveals to one of them
and asserts the rows directly and the whole resync over SIGTERM/SIGKILL, plus a
mid-session rename; leak.mjs/leakcheck.nim pit two players on the same subject
and pin each entry's expected name (STALE_NAME). Mutations e1-e3 and the
repointed b2 pin the three rules.
This commit is contained in:
2026-11-15 14:26:07 +01:00
parent e68c6eefbf
commit 8e045b0ac8
9 changed files with 528 additions and 93 deletions
+10
View File
@@ -298,6 +298,13 @@ export async function runLeak({ origin, gmKey, stateDir, transcript, keepOpen =
if (ack.ok !== true) throw new Error(`token.create refused: ${JSON.stringify(ack)}`)
ids.C1 = ack.id
})
// #27/#30: a second player meets the same token of the same character, so the transcript carries
// two encountered lists whose names can be compared independently (leakcheck runs once per
// subject). The later rename and reveals must reach this player's snapshot too, and a reveal to
// the *other* player must not.
await group('GM walks the other player into the room again', async () => {
expectAck(await move(gm, ids.B, [650, 700]), true)
})
// One mutation per group (the driver's contract): the checker evaluates a group as one state, so
// two prop writes in one group would compare an intermediate frame against the final truth.
for (const [bucket, value] of [['public', 'noble'], ['owner', 4], ['gm', 'the duke']]) {
@@ -338,6 +345,9 @@ export async function runLeak({ origin, gmKey, stateDir, transcript, keepOpen =
const ack = await gm.request({ t: 'name.reveal_all', subject: 'token', id: ids.N2 })
if (ack.ok !== true) throw new Error(`name.reveal_all refused: ${JSON.stringify(ack)}`)
})
await group('GM walks the other player out again', async () => {
expectAck(await move(gm, ids.B, [420, 1500]), true)
})
await group('GM hides the character token (the encountered entry stays, greyed)', async () => {
const ack = await gm.request({ t: 'token.update', id: ids.C1, gm_only: true })
if (ack.ok !== true) throw new Error(`token.update refused: ${JSON.stringify(ack)}`)