feat: client shell, sign-in and protocol client (#67)

New `client/` package (Vite + TypeScript + PixiJS v8, plain DOM overlay):
the pure reducer seam (no Pixi import), an append-only slice registry
build-time glob, the `proto` 2 WS client with envelope/ack/closing mapping,
the sign-in door (`POST /join`, one "Key not recognised." for wrong and
unknown), the DOM shell/HUD and a minimal Pixi stage created only after a
live `hello`. `hello` resets every slice so a reconnect cannot show stale
state; `proto-mismatch` shows reload; `revoked` returns to the sign-in page
and stops.

The browser e2e moves into the client package (`client/e2e/`, owning
playwright-core) and runs the real Vite build through the TLS/HTTP2 test
nginx: join -> canvas -> hello/roster for GM and player, no data before
join, identical wrong/unknown key refusal, proto mismatch, revoked.
`devbox run client-test` adds the Vitest seam; `devbox run e2e` builds the
client first. The #66 stub dist stays local to `tools/vhost.test.mjs`, so
`devbox run test` still needs no npm install.

Refs #67
This commit is contained in:
2026-11-20 23:57:16 +01:00
parent 97f618c5ad
commit 3c0258ea31
37 changed files with 3439 additions and 178 deletions
+103
View File
@@ -0,0 +1,103 @@
// T4 client shell (#67, TESTING 10.3): join -> canvas -> hello/roster for the GM and a player, no
// data before join, one plain refusal for a wrong and an unknown key, and a revoked session
// returning to sign-in. The server, the nginx vhost and the client are the real ones.
import test from 'node:test'
import assert from 'node:assert/strict'
import { sleep } from '../../tools/lib.mjs'
import { openAs } from '../../tools/withserver.mjs'
import {
launchBrowser,
makePlayer,
newPage,
signIn,
waitForText,
waitForVisible,
withStack,
} from './stack.mjs'
const KEY_REFUSED = 'Key not recognised.'
async function canvasAndRoster(page, expectedNames) {
await waitForVisible(page, '#stage canvas')
await waitForVisible(page, '#hud')
const roster = await waitForText(page, '#roster', new RegExp(expectedNames[0]))
for (const name of expectedNames) assert.match(roster, new RegExp(name))
return roster
}
test('no session: only the sign-in page, and a wrong and an unknown key look identical', { timeout: 120000 }, async () => {
await withStack(async ({ origin }) => {
const browser = await launchBrowser()
try {
const { page } = await newPage(browser)
const joins = []
page.on('response', response => {
if (new URL(response.url()).pathname === '/join') joins.push(response.status())
})
await page.goto(`${origin}/`)
await waitForVisible(page, '#signin')
// Story 1: a stranger gets the door and no game data.
assert.equal(await page.locator('#stage').isVisible(), false)
assert.equal(await page.locator('#hud').isVisible(), false)
assert.equal(await page.locator('#roster li').count(), 0)
// Story 3: the same answer for a well-formed but wrong key and for an unknown one.
await signIn(page, 'ABCD-EFGH-JKMN-PQRS')
await waitForVisible(page, '#signin-error')
const wrong = await page.textContent('#signin-error')
await signIn(page, 'not-a-key')
await waitForVisible(page, '#signin-error')
const unknown = await page.textContent('#signin-error')
assert.equal(wrong, KEY_REFUSED)
assert.equal(unknown, KEY_REFUSED)
assert.deepEqual(joins, [401, 401])
// No map request was made before a session existed.
assert.equal(await page.locator('#stage canvas').count(), 0)
} finally {
await browser.close()
}
})
})
test('GM and player: join -> canvas -> hello and roster; revoked returns to sign-in', { timeout: 120000 }, async () => {
await withStack(async ({ origin, gmKey }) => {
const player = await makePlayer(origin, gmKey, 'Alice')
const browser = await launchBrowser()
try {
const gmView = await newPage(browser)
await gmView.page.goto(`${origin}/`)
await waitForVisible(gmView.page, '#signin')
await signIn(gmView.page, gmKey)
const gmRoster = await canvasAndRoster(gmView.page, ['GM', 'Alice'])
assert.equal(await gmView.page.textContent('#role'), 'GM')
assert.match(gmRoster, /connected/)
const playerView = await newPage(browser)
await playerView.page.goto(`${origin}/`)
await waitForVisible(playerView.page, '#signin')
await signIn(playerView.page, player.key)
await canvasAndRoster(playerView.page, ['GM', 'Alice'])
assert.equal(await playerView.page.textContent('#role'), 'Player')
assert.equal(await playerView.page.textContent('#me'), 'Alice')
// Story 10: the GM replaces the key, the server revokes the session, and the browser stops
// at the sign-in door instead of hammering a dead socket.
const gm = await openAs(origin, gmKey)
await gm.ws.waitText('hello')
const ack = await gm.ws.request({ t: 'key.replace', id: player.id })
assert.equal(ack.ok, true)
gm.ws.close()
await waitForVisible(playerView.page, '#signin')
await waitForText(playerView.page, '#signin-notice', /session has ended/i)
assert.equal(await playerView.page.locator('#stage canvas').count(), 0)
assert.equal(await playerView.page.locator('#roster li').count(), 0)
// No automatic reconnection: still on the sign-in page a moment later.
await sleep(300)
assert.equal(await playerView.page.locator('#signin').isVisible(), true)
} finally {
await browser.close()
}
})
})