tools: name players through player.setname, and the character groups and four fault classes (#23)

This commit is contained in:
2026-11-15 12:01:30 +01:00
parent f134534c6c
commit c4b97ec16c
10 changed files with 405 additions and 132 deletions
+111 -31
View File
@@ -50,11 +50,19 @@ export function runChecker(transcript, subject) {
return { status: r.status, output: `${r.stdout ?? ''}${r.stderr ?? ''}` }
}
// One socket, its received frames, and where the transcript cursor is.
async function connect(origin, key, who, log) {
// One socket, its received frames, and where the transcript cursor is. Every intent a client sends
// is logged too (`k:'intent'`): the checker needs it to tell an intended controller change from one
// a character edit caused (the CONTROLLER_CHANGE class, DESIGN 10.3).
async function connect(origin, key, who, log, group) {
const { cookie } = await signIn(origin, key)
const ws = await openWs(origin, cookie)
return { who, ws, logged: 0, log }
return {
who, ws, logged: 0, log,
request(fields) {
log({ k: 'intent', g: group(), who, t: fields.t, f: fields })
return ws.request(fields)
},
}
}
export async function runLeak({ origin, gmKey, stateDir, transcript, keepOpen = false }) {
@@ -63,7 +71,7 @@ export async function runLeak({ origin, gmKey, stateDir, transcript, keepOpen =
const log = obj => lines.push(JSON.stringify(obj))
const clients = []
const gm = await connect(origin, gmKey, 'GM', log)
const gm = await connect(origin, gmKey, 'GM', log, () => g)
clients.push(gm)
await gm.ws.waitText('hello')
const walls = await gm.ws.waitText('walls')
@@ -113,30 +121,31 @@ export async function runLeak({ origin, gmKey, stateDir, transcript, keepOpen =
const wallIds = []
const addWall = async fields => {
const ack = await gm.ws.request({ t: 'wall.add', scene, ...fields })
const ack = await gm.request({ t: 'wall.add', scene, ...fields })
if (ack.ok !== true) throw new Error(`wall.add refused: ${JSON.stringify(ack)}`)
wallIds.push(ack.id)
return ack.id
}
const createToken = async (id, fields) => {
const ack = await gm.ws.request({ t: 'token.create', scene, ...fields })
const ack = await gm.request({ t: 'token.create', scene, ...fields })
if (ack.ok !== true) throw new Error(`token.create refused: ${JSON.stringify(ack)}`)
ids[id] = ack.id
return ack.id
}
const ids = {}
const characters = {}
const move = async (client, id, pos) => {
const ack = await client.ws.request({ t: 'token.move', id, pos })
const ack = await client.request({ t: 'token.move', id, pos })
return ack
}
// Two named players: the naming is the fixture of lib.mjs (player.setname is slice 8).
const playerA = await createPlayer(gm.ws)
const playerB = await createPlayer(gm.ws)
await namePlayer(stateDir, playerA.id, 'Subject A')
await namePlayer(stateDir, playerB.id, 'Player B')
await namePlayer(origin, playerA.key, 'Subject A')
await namePlayer(origin, playerB.key, 'Player B')
await group('walls', async () => {
for (const w of wallsToAdd) await addWall(w)
@@ -157,12 +166,12 @@ export async function runLeak({ origin, gmKey, stateDir, transcript, keepOpen =
actual_name: 'The Vault' })
})
const A = await connect(origin, playerA.key, 'A', log)
const A = await connect(origin, playerA.key, 'A', log, () => g)
clients.push(A)
await A.ws.waitText('hello')
await group('connect subject', async () => { await sleep(0) })
const B = await connect(origin, playerB.key, 'B', log)
const B = await connect(origin, playerB.key, 'B', log, () => g)
clients.push(B)
await B.ws.waitText('hello')
await group('connect other', async () => { await sleep(0) })
@@ -177,7 +186,7 @@ export async function runLeak({ origin, gmKey, stateDir, transcript, keepOpen =
await group('M2 is hidden behind the closed door', async () => { await sleep(0) })
await group('GM opens the door', async () => {
const ack = await gm.ws.request({ t: 'door.set', scene, id: wallIds[1], open: true })
const ack = await gm.request({ t: 'door.set', scene, id: wallIds[1], open: true })
if (ack.ok !== true) throw new Error(`door.set refused: ${JSON.stringify(ack)}`)
})
await group('A steps through the door', async () => {
@@ -194,26 +203,26 @@ export async function runLeak({ origin, gmKey, stateDir, transcript, keepOpen =
actual_name: 'Lantern' })
})
await group('GM removes it', async () => {
const ack = await gm.ws.request({ t: 'token.remove', id: ids.N1 })
const ack = await gm.request({ t: 'token.remove', id: ids.N1 })
if (ack.ok !== true) throw new Error(`token.remove refused: ${JSON.stringify(ack)}`)
})
await group('GM hides M1', async () => {
const ack = await gm.ws.request({ t: 'token.update', id: ids.M1, gm_only: true })
const ack = await gm.request({ t: 'token.update', id: ids.M1, gm_only: true })
if (ack.ok !== true) throw new Error(`token.update refused: ${JSON.stringify(ack)}`)
})
await group('GM unhides M1', async () => {
const ack = await gm.ws.request({ t: 'token.update', id: ids.M1, gm_only: false })
const ack = await gm.request({ t: 'token.update', id: ids.M1, gm_only: false })
if (ack.ok !== true) throw new Error(`token.update refused: ${JSON.stringify(ack)}`)
})
await group('GM hands M1 to the subject', async () => {
const ack = await gm.ws.request({ t: 'token.update', id: ids.M1, controller: playerA.id })
const ack = await gm.request({ t: 'token.update', id: ids.M1, controller: playerA.id })
if (ack.ok !== true) throw new Error(`token.update refused: ${JSON.stringify(ack)}`)
})
await group('GM moves the subject-owned token far away', async () => {
expectAck(await move(gm, ids.M1, [3000, 3000]), true)
})
await group('GM hands M1 back to the GM', async () => {
const ack = await gm.ws.request({ t: 'token.update', id: ids.M1, controller: null })
const ack = await gm.request({ t: 'token.update', id: ids.M1, controller: null })
if (ack.ok !== true) throw new Error(`token.update refused: ${JSON.stringify(ack)}`)
})
await group('GM walks the other player in', async () => {
@@ -226,14 +235,14 @@ export async function runLeak({ origin, gmKey, stateDir, transcript, keepOpen =
await addWall({ a: [400, 900], b: [900, 900], kind: 'wall' })
})
await group('GM removes it again', async () => {
const ack = await gm.ws.request({ t: 'wall.remove', scene, id: wallIds[wallIds.length - 1] })
const ack = await gm.request({ t: 'wall.remove', scene, id: wallIds[wallIds.length - 1] })
if (ack.ok !== true) throw new Error(`wall.remove refused: ${JSON.stringify(ack)}`)
})
await group('GM puts M2 on the door line', async () => {
expectAck(await move(gm, ids.M2, [500, 600]), true)
})
await group('GM closes the door: the server pushes M2 aside', async () => {
const ack = await gm.ws.request({ t: 'door.set', scene, id: wallIds[1], open: false })
const ack = await gm.request({ t: 'door.set', scene, id: wallIds[1], open: false })
if (ack.ok !== true) throw new Error(`door.set refused: ${JSON.stringify(ack)}`)
})
// Slice 7 (#22): a token the subject can see, in every bucket and with a status. N2 sits 60 px
@@ -242,39 +251,110 @@ export async function runLeak({ origin, gmKey, stateDir, transcript, keepOpen =
await createToken('N2', { kind: 'item', pos: [660, 600], descriptive_name: 'a rune',
actual_name: 'The Rune' })
})
await group('GM writes props into all three buckets on N2', async () => {
for (const [bucket, value] of [['public', 'cold'], ['owner', 3], ['gm', 'the duke']]) {
const ack = await gm.ws.request({ t: 'prop.set', target: 'token', id: ids.N2, bucket,
key: 'aura', value })
for (const [bucket, value] of [['public', 'cold'], ['owner', 3], ['gm', 'the duke']]) {
await group(`GM writes the ${bucket} prop of N2`, async () => {
const ack = await gm.request({ t: 'prop.set', target: 'token', id: ids.N2, bucket,
key: 'aura', value })
if (ack.ok !== true) throw new Error(`prop.set refused: ${JSON.stringify(ack)}`)
}
})
})
}
await group('GM sets a GM-sourced status on N2', async () => {
const ack = await gm.ws.request({ t: 'status.set', id: ids.N2, status: 'squeezed' })
const ack = await gm.request({ t: 'status.set', id: ids.N2, status: 'squeezed' })
if (ack.ok !== true) throw new Error(`status.set refused: ${JSON.stringify(ack)}`)
})
await group('GM resizes N2', async () => {
const resized = await gm.ws.request({ t: 'token.resize', id: ids.N2, radius: 45 })
const resized = await gm.request({ t: 'token.resize', id: ids.N2, radius: 45 })
if (resized.ok !== true) throw new Error(`token.resize refused: ${JSON.stringify(resized)}`)
})
await group('GM adds a wall over N2 (stuck, source walls)', async () => {
await addWall({ a: [700, 560], b: [700, 660], kind: 'wall' })
})
await group('GM unsets the public prop of N2', async () => {
const unset = await gm.ws.request({ t: 'prop.unset', target: 'token', id: ids.N2,
const unset = await gm.request({ t: 'prop.unset', target: 'token', id: ids.N2,
bucket: 'public', key: 'aura' })
if (unset.ok !== true) throw new Error(`prop.unset refused: ${JSON.stringify(unset)}`)
})
await group('GM clears the GM-sourced status of N2', async () => {
const cleared = await gm.ws.request({ t: 'status.clear', id: ids.N2, status: 'squeezed',
const cleared = await gm.request({ t: 'status.clear', id: ids.N2, status: 'squeezed',
source: 'GM' })
if (cleared.ok !== true) throw new Error(`status.clear refused: ${JSON.stringify(cleared)}`)
})
await group('GM removes the wall over N2', async () => {
const ack = await gm.ws.request({ t: 'wall.remove', scene,
const ack = await gm.request({ t: 'wall.remove', scene,
id: wallIds[wallIds.length - 1] })
if (ack.ok !== true) throw new Error(`wall.remove refused: ${JSON.stringify(ack)}`)
})
// Slice 8 (#23): characters, names and the encountered list. Every group here is one the subject
// receives: A is in the room, and C1's token is placed next to A's own.
await group('GM creates a character owned by the other player', async () => {
const ack = await gm.request({ t: 'character.create', descriptive_name: 'a cloaked figure',
actual_name: 'Lady Vex', owner: playerB.id })
if (ack.ok !== true) throw new Error(`character.create refused: ${JSON.stringify(ack)}`)
characters.C1 = ack.id
})
await group('GM puts a token of the character in the subject sight', async () => {
const ack = await gm.request({ t: 'token.create', scene, kind: 'pc', pos: [600, 560],
character_id: characters.C1 })
if (ack.ok !== true) throw new Error(`token.create refused: ${JSON.stringify(ack)}`)
ids.C1 = ack.id
})
// 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']]) {
await group(`GM writes the ${bucket} prop of the character`, async () => {
const ack = await gm.request({ t: 'prop.set', target: 'character', id: characters.C1, bucket,
key: 'rank', value })
if (ack.ok !== true) throw new Error(`prop.set refused: ${JSON.stringify(ack)}`)
})
}
await group('GM renames the character', async () => {
const ack = await gm.request({ t: 'character.update', id: characters.C1,
descriptive_name: 'a tall stranger' })
if (ack.ok !== true) throw new Error(`character.update refused: ${JSON.stringify(ack)}`)
})
await group('GM reveals the actual name to the subject only', async () => {
const ack = await gm.request({ t: 'name.reveal', subject: 'character', id: characters.C1,
player: playerA.id })
if (ack.ok !== true) throw new Error(`name.reveal refused: ${JSON.stringify(ack)}`)
})
await group('GM reveals the actual name to everyone', async () => {
const ack = await gm.request({ t: 'name.reveal_all', subject: 'character', id: characters.C1 })
if (ack.ok !== true) throw new Error(`name.reveal_all refused: ${JSON.stringify(ack)}`)
})
await group('GM hands the character to the subject (controllers must not move)', async () => {
const ack = await gm.request({ t: 'character.reassign', id: characters.C1, owner: playerA.id })
if (ack.ok !== true) throw new Error(`character.reassign refused: ${JSON.stringify(ack)}`)
})
await group('GM gives the character back to the other player', async () => {
const ack = await gm.request({ t: 'character.reassign', id: characters.C1, owner: playerB.id })
if (ack.ok !== true) throw new Error(`character.reassign refused: ${JSON.stringify(ack)}`)
})
await group('GM reveals a plain token actual name to the subject', async () => {
const ack = await gm.request({ t: 'name.reveal', subject: 'token', id: ids.N2,
player: playerA.id })
if (ack.ok !== true) throw new Error(`name.reveal refused: ${JSON.stringify(ack)}`)
})
await group('GM reveals that plain token to everyone', async () => {
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 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)}`)
})
await group('GM shows it again', async () => {
const ack = await gm.request({ t: 'token.update', id: ids.C1, gm_only: false })
if (ack.ok !== true) throw new Error(`token.update refused: ${JSON.stringify(ack)}`)
})
await group('GM removes the character token (the entry stays, greyed)', async () => {
const ack = await gm.request({ t: 'token.remove', id: ids.C1 })
if (ack.ok !== true) throw new Error(`token.remove refused: ${JSON.stringify(ack)}`)
})
await group('GM removes one encountered entry of the subject', async () => {
const ack = await gm.request({ t: 'encountered.remove', player: playerA.id, id: ids.N2 })
if (ack.ok !== true) throw new Error(`encountered.remove refused: ${JSON.stringify(ack)}`)
})
await group('A walks away from the door', async () => {
expectAck(await move(A, ids.A, [560, 950]), true)
})
@@ -290,7 +370,7 @@ export async function runLeak({ origin, gmKey, stateDir, transcript, keepOpen =
fs.mkdirSync(path.dirname(transcript), { recursive: true })
fs.writeFileSync(transcript, lines.join('\n') + '\n')
return { transcript, groups: g, walls: wallIds, tokens: ids }
return { transcript, groups: g, walls: wallIds, tokens: ids, characters }
}
function expectAck(ack, ok) {