Files
FFF_vtt_frozen/tools/tokens.test.mjs
T
SirStone 0323fbd2ae feat: GM characters, reveals, who-sees-it and seen_by (#75)
Server: GM token frames gain the additive, GM-only seen_by:[player ids],
computed from each player's existing sight (PlayerVision.visibleTo) with
no extra polygon pass. Leakcheck BannedAlways bans seen_by; a seenBy
fault build is caught as exactly WALLDATA. proto stays 2 (6.2 additive).

Client: new cast slice parses character/character_gone/encountered frames
and seen_by; gmcast panel adds character create/rename/assign/remove,
reveal to one/all, encountered forget (grey entries only) and the
who-sees-it list (0/100 in M4). Mounted beside the #74 admin panel.

Docs: DESIGN 5.9/6.1/6.2/7.4 record the round-1 shape and the no-bump
call. Gates: devbox run test, client-test, e2e green; bench recorded.
2026-11-21 01:04:10 +01:00

465 lines
25 KiB
JavaScript

// M3 slice 5 (#20): tokens and sight over the real wire. The 6.1 acks and codes of
// token.create/update/move/remove, the GM-only and controller-only rules, the `vision`/`explored`
// resync and the token_gone paths, the unnamed-player gate of 6.1/6.5, the door push of 5.5, and a
// restart that brings every token back. The exhaustive leak/fault proof is tools/leak.test.mjs.
import test from 'node:test'
import assert from 'node:assert/strict'
import fs from 'node:fs'
import { createPlayer, namePlayer, sleep } from './lib.mjs'
import { gmKeyOf, makeStateDir, openAs, startServer, stopServer, withGmServer } from './withserver.mjs'
const stripN = msg => { const { n, ...rest } = msg; return rest }
async function gmConnect(origin, gmKey) {
const conn = await openAs(origin, gmKey)
await conn.ws.waitText('hello')
const walls = await conn.ws.waitText('walls')
return { ...conn, scene: walls.scene, walls }
}
// A named player: the harness names it through `player.setname` (lib.mjs, slice 8 / #23).
async function namedPlayer(origin, gm, name) {
const player = await createPlayer(gm.ws)
await namePlayer(origin, player.key, name)
return player
}
async function playerConnect(origin, player, expectTokens = 0) {
const conn = await openAs(origin, player.key)
await conn.ws.waitText('hello')
if (expectTokens > 0) await conn.ws.waitFor(m => m.t === 'token', 5000)
return conn
}
const tokenFrames = ws => ws.messages.filter(m => m.t === 'token')
test('token.create: ack with the id, the token to the GM, invisible to a player out of range', async () => {
await withGmServer(async (s, gmKey) => {
const gm = await gmConnect(s.origin, gmKey)
const player = await namedPlayer(s.origin, gm, 'Alice')
const p = await playerConnect(s.origin, player)
const ack = await gm.ws.request({ t: 'token.create', scene: gm.scene, kind: 'pc', pos: [400, 400],
descriptive_name: 'a grumpy man', actual_name: 'Lord Vex' })
assert.equal(ack.ok, true)
assert.equal(typeof ack.id, 'string')
assert.equal(ack.id.length, 12, 'ids are 12 characters (DESIGN 8)')
assert.match(ack.id, /^[A-Za-z0-9_-]{12}$/)
assert.equal(ack.code, undefined)
const gmView = await gm.ws.waitFor(m => m.t === 'token' && m.id === ack.id)
assert.equal(gmView.scene, gm.scene)
assert.deepEqual(gmView.pos, [400, 400])
assert.equal(gmView.name, 'a grumpy man', 'the descriptive name is what a recipient sees')
assert.equal(gmView.radius, 20, 'the scene token_radius_default (#4, slice 7)')
assert.equal(gmView.mine, false)
assert.equal(gmView.kind, 'pc')
assert.equal(gmView.controller, null)
assert.equal(gmView.gm_only, false)
assert.deepEqual(gmView.flags, {})
assert.equal(gmView.actual_name, 'Lord Vex')
assert.equal(gmView.descriptive_name, 'a grumpy man')
assert.deepEqual(Object.keys(gmView.props).sort(), ['gm', 'owner', 'public'])
assert.deepEqual(gmView.statuses, [])
// the player controls nothing and the token is far away: nothing reaches that connection
await sleep(150)
assert.equal(tokenFrames(p.ws).length, 0, 'a player must not learn about an unseen token')
p.ws.close(); gm.ws.close()
})
})
test('token.create validation: the 6.1 table and the fields this slice cannot honour', async () => {
await withGmServer(async (s, gmKey) => {
const gm = await gmConnect(s.origin, gmKey)
const scene = gm.scene
const player = await namedPlayer(s.origin, gm, 'Alice')
const base = { kind: 'npc', pos: [100, 100], descriptive_name: 'a thing', actual_name: 'Thing' }
const invalid = [
{ ...base, descriptive_name: '' },
{ ...base, descriptive_name: ' padded' },
{ ...base, actual_name: 'tab\there' },
{ ...base, descriptive_name: 'x'.repeat(65) },
{ ...base, kind: '' },
{ ...base, pos: [-1, 100] },
{ ...base, pos: [5000, 100] },
{ ...base, pos: [1] },
{ ...base, pos: ['1', '2'] },
{ ...base, gm_only: 'yes' },
{ ...base, flags: [1, 2] },
{ ...base, vision_radius: 0 },
{ ...base, vision_radius: 'big' },
{ ...base, radius: 0 }, // slice 7 (#4): a radius is > 0 or null
{ ...base, props: { secret: {} } }, // slice 7 (#22): the bucket names are closed
{ ...base, props: { public: { '': 1 } } },
{ ...base, character_id: 'abc' }, // slice 8 (#23)
{ ...base, controller: 'alice' },
]
for (const fields of invalid) {
const ack = await gm.ws.request({ t: 'token.create', scene, ...fields })
assert.equal(ack.ok, false, JSON.stringify(fields))
assert.equal(ack.code, 'invalid', JSON.stringify(fields))
assert.equal(ack.id, undefined, 'a refusal carries no state')
}
// lookups (6.5 step 8) and the scene check
assert.equal((await gm.ws.request({ t: 'token.create', scene: scene + 1, ...base })).code, 'not-found')
assert.equal((await gm.ws.request({ t: 'token.create', scene: '1', ...base })).code, 'invalid')
assert.equal((await gm.ws.request({ t: 'token.create', scene, ...base, controller: 99 })).code,
'not-found')
// a GM controller is stored as GM-controlled, and the GM's own player id means the same thing
const viaGm = await gm.ws.request({ t: 'token.create', scene, ...base, controller: 1 })
assert.equal(viaGm.ok, true)
const view = await gm.ws.waitFor(m => m.t === 'token' && m.id === viaGm.id)
assert.equal(view.controller, null)
gm.ws.close(); player.ws?.close?.()
})
})
test('token.move: controller only, uniform nack, and one code for unknown and not-yours', async () => {
await withGmServer(async (s, gmKey) => {
const gm = await gmConnect(s.origin, gmKey)
const alice = await namedPlayer(s.origin, gm, 'Alice')
const bob = await namedPlayer(s.origin, gm, 'Bob')
const mine = await gm.ws.request({ t: 'token.create', scene: gm.scene, kind: 'pc', pos: [400, 400],
descriptive_name: 'Alice', actual_name: 'Alice',
controller: alice.id, flags: { vision: true } })
const theirs = await gm.ws.request({ t: 'token.create', scene: gm.scene, kind: 'pc',
pos: [500, 500], descriptive_name: 'Bob', actual_name: 'Bob',
controller: bob.id })
const a = await playerConnect(s.origin, alice, 1)
const own = await a.ws.waitFor(m => m.t === 'token' && m.id === mine.id)
assert.equal(own.mine, true)
assert.deepEqual(own.props && Object.keys(own.props).sort(), ['owner', 'public'])
const ok = await a.ws.request({ t: 'token.move', id: mine.id, pos: [600, 400] })
assert.equal(ok.ok, true)
assert.deepEqual(ok.pos, [600, 400])
const moved = await a.ws.waitFor(m => m.t === 'token' && m.id === mine.id && m.pos[0] === 600)
assert.deepEqual(moved.pos, [600, 400])
// over the step cap: the uniform refusal, old position, no code (5.5, T9)
const far = await a.ws.request({ t: 'token.move', id: mine.id, pos: [1400, 400] })
assert.equal(far.ok, false)
assert.equal(far.code, undefined, 'a move refusal carries no code')
assert.deepEqual(far.pos, [600, 400])
// another player's token and an unknown id are the same refusal for a player
for (const id of [theirs.id, 'does-not-exist']) {
const ack = await a.ws.request({ t: 'token.move', id, pos: [700, 500] })
assert.equal(ack.ok, false, id)
assert.equal(ack.code, 'not-allowed', id)
assert.equal(ack.pos, undefined, 'no position oracle for a non-controlled token')
}
// the GM's missing target is not-found, and an out-of-bounds GM move is the uniform nack
assert.equal((await gm.ws.request({ t: 'token.move', id: 'nope', pos: [0, 0] })).code, 'not-found')
const gmVoid = await gm.ws.request({ t: 'token.move', id: mine.id, pos: [-50, 0] })
assert.equal(gmVoid.ok, false)
assert.equal(gmVoid.code, undefined)
assert.deepEqual(gmVoid.pos, [600, 400])
// the GM moves anyone's token, past the cap and through walls
const gmMove = await gm.ws.request({ t: 'token.move', id: mine.id, pos: [3000, 3000] })
assert.equal(gmMove.ok, true)
a.ws.close(); gm.ws.close()
})
})
test('token.update: controller, gm_only, names, flags and the codes of 6.5', async () => {
await withGmServer(async (s, gmKey) => {
const gm = await gmConnect(s.origin, gmKey)
const alice = await namedPlayer(s.origin, gm, 'Alice')
const own = await gm.ws.request({ t: 'token.create', scene: gm.scene, kind: 'pc', pos: [300, 400],
descriptive_name: 'Alice', actual_name: 'Alice',
controller: alice.id, flags: { vision: true } })
const created = await gm.ws.request({ t: 'token.create', scene: gm.scene, kind: 'npc',
pos: [450, 400], descriptive_name: 'a guard',
actual_name: 'Captain Vex' })
const a = await playerConnect(s.origin, alice, 2)
const seen = await a.ws.waitFor(m => m.t === 'token' && m.id === created.id)
assert.equal(seen.name, 'a guard')
assert.equal(seen.mine, false)
assert.equal(seen.vision_radius, undefined, 'only the controller gets the step cap field')
// gm_only takes it away from a player who could see it (6.1)
assert.equal((await gm.ws.request({ t: 'token.update', id: created.id, gm_only: true })).ok, true)
const gone = await a.ws.waitFor(m => m.t === 'token_gone' && m.id === created.id)
assert.deepEqual(stripN(gone), { t: 'token_gone', id: created.id })
assert.equal((await gm.ws.request({ t: 'token.update', id: created.id, gm_only: false })).ok, true)
await a.ws.waitFor(m => m.t === 'token' && m.id === created.id && m.name === 'a guard')
// a rename reaches whoever may see the token; the GM keeps both names
assert.equal((await gm.ws.request({ t: 'token.update', id: created.id,
descriptive_name: 'a tall guard' })).ok, true)
const renamed = await a.ws.waitFor(m => m.t === 'token' && m.id === created.id &&
m.name === 'a tall guard')
assert.equal(renamed.actual_name, undefined, 'the actual name has no egress path (slice 8)')
// the controller change flips `mine` and hands over the step-cap field
assert.equal((await gm.ws.request({ t: 'token.update', id: created.id,
controller: alice.id })).ok, true)
const handed = await a.ws.waitFor(m => m.t === 'token' && m.id === created.id && m.mine === true)
assert.equal(handed.vision_radius, null)
assert.equal((await gm.ws.request({ t: 'token.update', id: created.id, controller: null })).ok, true)
await a.ws.waitFor(m => m.t === 'token' && m.id === created.id && m.mine === false)
// codes: a fieldless patch and a character link are invalid, a bad target is not-found
for (const patch of [{}, { character_id: null }, { kind: '' }, { descriptive_name: '' },
{ controller: 'alice' }, { vision_radius: 0 }, { flags: 3 }]) {
const ack = await gm.ws.request({ t: 'token.update', id: created.id, ...patch })
assert.equal(ack.ok, false, JSON.stringify(patch))
assert.equal(ack.code, 'invalid', JSON.stringify(patch))
}
assert.equal((await gm.ws.request({ t: 'token.update', id: 'nope', gm_only: true })).code,
'not-found')
assert.equal((await gm.ws.request({ t: 'token.update', id: created.id, controller: 42 })).code,
'not-found')
a.ws.close(); gm.ws.close()
})
})
test('token.remove: token_gone to whoever knew it, not-found after', async () => {
await withGmServer(async (s, gmKey) => {
const gm = await gmConnect(s.origin, gmKey)
const alice = await namedPlayer(s.origin, gm, 'Alice')
await gm.ws.request({ t: 'token.create', scene: gm.scene, kind: 'pc', pos: [300, 400],
descriptive_name: 'Alice', actual_name: 'Alice',
controller: alice.id, flags: { vision: true } })
const created = await gm.ws.request({ t: 'token.create', scene: gm.scene, kind: 'item',
pos: [450, 400], descriptive_name: 'a lamp',
actual_name: 'Lantern' })
const a = await playerConnect(s.origin, alice, 2)
await gm.ws.waitFor(m => m.t === 'token' && m.id === created.id)
assert.equal((await gm.ws.request({ t: 'token.remove', id: created.id })).ok, true)
await a.ws.waitFor(m => m.t === 'token_gone' && m.id === created.id)
await gm.ws.waitFor(m => m.t === 'token_gone' && m.id === created.id)
assert.equal((await gm.ws.request({ t: 'token.remove', id: created.id })).code, 'not-found')
a.ws.close(); gm.ws.close()
})
})
test('connect resync: GM gets walls then every token; a player vision, explored, then its tokens', async () => {
await withGmServer(async (s, gmKey) => {
const gm = await gmConnect(s.origin, gmKey)
const alice = await namedPlayer(s.origin, gm, 'Alice')
const visible = await gm.ws.request({ t: 'token.create', scene: gm.scene, kind: 'npc',
pos: [450, 400], descriptive_name: 'a wolf',
actual_name: 'Fang' })
const far = await gm.ws.request({ t: 'token.create', scene: gm.scene, kind: 'npc',
pos: [3500, 3500], descriptive_name: 'a chest',
actual_name: 'Vault' })
const mine = await gm.ws.request({ t: 'token.create', scene: gm.scene, kind: 'pc',
pos: [3000, 3000], descriptive_name: 'Alice',
actual_name: 'Alice', controller: alice.id,
flags: { vision: true } })
await sleep(200)
// a fresh GM connection: hello (scene block + extra), walls, then every token
const gm2 = await openAs(s.origin, gmKey)
const hello = await gm2.ws.waitText('hello')
assert.equal(hello.role, 'gm')
assert.equal(hello.scene.id, gm.scene)
assert.equal(hello.scene.cell, 32)
assert.equal(hello.scene.vision_radius_default, 400)
assert.deepEqual(hello.extra, {})
assert.equal(hello.n, 1)
const order = gm2.ws.messages.map(m => m.t)
// 6.3 resync order: roster, walls, then every token (characters/encountered are slice 8).
assert.deepEqual(order.slice(0, 3), ['hello', 'roster', 'walls'])
assert.equal(order.filter(t => t === 'token').length, 3)
assert.equal(order.includes('vision'), false, 'the GM never gets vision polygons')
assert.equal(order.includes('explored'), false, 'the GM never gets explored cells')
assert.deepEqual([...new Set(gm2.ws.messages.map(m => m.n))].length, gm2.ws.messages.length,
'every frame carries its own n')
// a fresh player connection: hello, vision, explored (full), then the tokens it may see
const a = await playerConnect(s.origin, alice, 1)
await sleep(150)
const aOrder = a.ws.messages.map(m => m.t)
// 6.3: hello, roster, the encountered list, then vision/explored and the tokens.
assert.deepEqual(aOrder.slice(0, 5), ['hello', 'roster', 'encountered', 'vision', 'explored'])
const explored = a.ws.messages[4]
assert.equal(explored.full, true)
assert.ok(Array.isArray(explored.rle))
const ids = tokenFrames(a.ws).map(m => m.id).sort()
assert.deepEqual(ids, [mine.id].sort(),
'a player gets only what it controls or sees (its own token is far away: controlled)')
assert.equal(ids.includes(far.id), false)
const vision = a.ws.messages[3]
assert.equal(vision.polys.length, 1)
assert.equal(vision.polys[0].id, mine.id)
for (const pt of vision.polys[0].pts) {
assert.equal(Number.isInteger(pt[0]) && Number.isInteger(pt[1]), true, 'integer px (6.4)')
}
a.ws.close(); gm2.ws.close(); gm.ws.close()
})
})
test('an unnamed player gets nothing but hello, and every intent is refused (6.1, 6.5 step 5)', async () => {
await withGmServer(async (s, gmKey) => {
const gm = await gmConnect(s.origin, gmKey)
const player = await createPlayer(gm.ws) // a fresh key: unnamed until player.setname
const p = await playerConnect(s.origin, player)
const hello = await p.ws.waitText('hello')
assert.deepEqual(Object.keys(hello).sort(), ['me', 'n', 'proto', 'role', 't'])
assert.equal(hello.me.name, null)
const created = await gm.ws.request({ t: 'token.create', scene: gm.scene, kind: 'pc',
pos: [400, 400], descriptive_name: 'x', actual_name: 'X',
controller: player.id, flags: { vision: true } })
await sleep(150)
assert.equal(p.ws.messages.length, 1, 'nothing but hello: no scene block, no resync')
const ack = await p.ws.request({ t: 'token.move', id: created.id, pos: [500, 400] })
assert.equal(ack.ok, false)
assert.equal(ack.code, 'not-allowed')
p.ws.close(); gm.ws.close()
})
})
test('door closing pushes an overlapped token aside (5.5), and the push is a normal token update',
async () => {
await withGmServer(async (s, gmKey) => {
const gm = await gmConnect(s.origin, gmKey)
const alice = await namedPlayer(s.origin, gm, 'Alice')
const door = await gm.ws.request({ t: 'wall.add', scene: gm.scene, a: [500, 400], b: [500, 700],
door: true })
const tok = await gm.ws.request({ t: 'token.create', scene: gm.scene, kind: 'pc',
pos: [300, 550], descriptive_name: 'Alice',
actual_name: 'Alice', controller: alice.id,
flags: { vision: true } })
const a = await playerConnect(s.origin, alice, 1)
// the GM drops the token onto the door line, then closes the door on it
assert.equal((await gm.ws.request({ t: 'token.move', id: tok.id, pos: [500, 550] })).ok, true)
await a.ws.waitFor(m => m.t === 'token' && m.id === tok.id && m.pos[0] === 500)
assert.equal((await gm.ws.request({ t: 'door.set', scene: gm.scene, id: door.id, open: true })).ok,
true)
assert.equal((await gm.ws.request({ t: 'door.set', scene: gm.scene, id: door.id, open: false })).ok,
true)
const pushed = await a.ws.waitFor(m => m.t === 'token' && m.id === tok.id && m.pos[0] !== 500)
// pushed perpendicular to the door by the minimal distance that clears the token radius
assert.equal(pushed.pos[0] < 480 || pushed.pos[0] > 520, true, JSON.stringify(pushed.pos))
assert.equal(Math.abs(pushed.pos[1] - 550) < 1e-6, true, 'the push keeps the along-axis position')
// and the new position is what a restart loads
const gmToken = await gm.ws.waitFor(m => m.t === 'token' && m.id === tok.id &&
m.pos[0] === pushed.pos[0])
assert.deepEqual(gmToken.pos, pushed.pos)
a.ws.close(); gm.ws.close()
})
})
test('restart: tokens, positions and controllers come back with the same view', async () => {
const stateDir = makeStateDir()
try {
const gmKey = gmKeyOf(stateDir)
let s = await startServer({ stateDir })
let ids
try {
const gm = await gmConnect(s.origin, gmKey)
const alice = await namedPlayer(s.origin, gm, 'Alice')
const t1 = await gm.ws.request({ t: 'token.create', scene: gm.scene, kind: 'pc', pos: [400, 400],
descriptive_name: 'Alice', actual_name: 'Alice',
controller: alice.id, flags: { vision: true } })
const t2 = await gm.ws.request({ t: 'token.create', scene: gm.scene, kind: 'npc',
pos: [600, 550], descriptive_name: 'a guard',
actual_name: 'Vex' })
assert.equal((await gm.ws.request({ t: 'token.move', id: t2.id, pos: [620, 560] })).ok, true)
ids = { t1: t1.id, t2: t2.id, alice }
gm.ws.close()
} finally {
await stopServer(s)
}
s = await startServer({ stateDir })
try {
const gm = await gmConnect(s.origin, gmKey)
const tokens = await gm.ws.waitFor(m => m.t === 'token' && m.id === ids.t2)
assert.deepEqual(tokens.pos, [620, 560])
await gm.ws.waitFor(m => m.t === 'token' && m.id === ids.t1)
const a = await playerConnect(s.origin, ids.alice, 1)
await sleep(150)
assert.equal(tokenFrames(a.ws).length, 2, 'both tokens are in the restored view')
a.ws.close(); gm.ws.close()
} finally {
await stopServer(s)
}
} finally {
fs.rmSync(stateDir, { recursive: true, force: true })
}
})
test('seen_by: the GM sees which players see each token (0/100); players never receive it', async () => {
await withGmServer(async (s, gmKey) => {
const gm = await gmConnect(s.origin, gmKey)
const alice = await namedPlayer(s.origin, gm, 'Alice')
const bob = await namedPlayer(s.origin, gm, 'Bob')
const pa = await playerConnect(s.origin, alice)
const pb = await playerConnect(s.origin, bob)
const create = fields => gm.ws.request({ t: 'token.create', scene: gm.scene, ...fields })
// One scout each: Alice at (400,400), Bob far away at (3900,3900). Both have sight, so the
// `seen_by` lists below are the server's own per-player vision, not a second rule.
const aScout = await create({ kind: 'pc', pos: [400, 400], descriptive_name: 'A',
actual_name: 'A', controller: alice.id, flags: { vision: true } })
const bScout = await create({ kind: 'pc', pos: [3900, 3900], descriptive_name: 'B',
actual_name: 'B', controller: bob.id, flags: { vision: true } })
// In Alice's sight, controlled by nobody.
const near = await create({ kind: 'npc', pos: [500, 500], descriptive_name: 'near',
actual_name: 'Near' })
// In Alice's sight, controlled by Bob: both see it (sight plus control, 3.1).
const bobs = await create({ kind: 'npc', pos: [300, 300], descriptive_name: 'bobs',
actual_name: 'Bobs', controller: bob.id })
// gm_only inside Alice's sight: nobody sees it.
const hidden = await create({ kind: 'npc', pos: [450, 450], descriptive_name: 'hidden',
actual_name: 'Hidden', gm_only: true })
// gm_only, controlled by Alice: its controller always sees it.
const hiddenMine = await create({ kind: 'npc', pos: [450, 550], descriptive_name: 'hidden mine',
actual_name: 'Hidden Mine', gm_only: true,
controller: alice.id })
// Out of Alice's sight, controlled by Bob: its controller sees it.
const far = await create({ kind: 'npc', pos: [3000, 3000], descriptive_name: 'far',
actual_name: 'Far', controller: bob.id })
const seen = async id => {
const frame = await gm.ws.waitFor(m => m.t === 'token' && m.id === id && Array.isArray(m.seen_by))
return frame.seen_by
}
assert.deepEqual(await seen(aScout.id), [alice.id])
assert.deepEqual(await seen(bScout.id), [bob.id])
assert.deepEqual(await seen(near.id), [alice.id])
assert.deepEqual(await seen(bobs.id), [alice.id, bob.id].sort((a, b) => a - b))
assert.deepEqual(await seen(hidden.id), [], 'gm_only and uncontrolled: nobody sees it')
assert.deepEqual(await seen(hiddenMine.id), [alice.id], 'a controller always sees its token')
assert.deepEqual(await seen(far.id), [bob.id])
// A `gm_only` flip updates the list: control survives it, sight does not.
assert.equal((await gm.ws.request({ t: 'token.update', id: bobs.id, gm_only: true })).ok, true)
let flipped = null
await gm.ws.waitFor(m => {
if (m.t === 'token' && m.id === bobs.id && m.gm_only === true) flipped = m
return flipped !== null
})
assert.deepEqual(flipped.seen_by, [bob.id])
// The only M4 wire change is GM-only: neither player socket ever receives the field.
await sleep(150)
for (const conn of [pa, pb]) {
assert.equal(JSON.stringify(conn.ws.messages).includes('seen_by'), false,
'seen_by reached a player wire')
}
pa.ws.close(); pb.ws.close(); gm.ws.close()
})
})
test('player.remove hands the player\'s tokens to the GM (3.2)', async () => {
await withGmServer(async (s, gmKey) => {
const gm = await gmConnect(s.origin, gmKey)
const alice = await namedPlayer(s.origin, gm, 'Alice')
const tok = await gm.ws.request({ t: 'token.create', scene: gm.scene, kind: 'pc', pos: [400, 400],
descriptive_name: 'Alice', actual_name: 'Alice',
controller: alice.id, flags: { vision: true } })
const before = await gm.ws.waitFor(m => m.t === 'token' && m.id === tok.id)
assert.equal(before.controller, alice.id)
assert.equal((await gm.ws.request({ t: 'player.remove', id: alice.id })).ok, true)
const after = await gm.ws.waitFor(m => m.t === 'token' && m.id === tok.id &&
m.controller === null)
assert.equal(after.controller, null)
assert.equal(after.mine, false)
gm.ws.close()
})
})