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
39 lines
1.7 KiB
JavaScript
39 lines
1.7 KiB
JavaScript
// Story 9 / DR 6.2 (#67): a proto mismatch completes the upgrade, sends closing{proto-mismatch}
|
|
// and closes; the client must show "reload" and stop, not sign in and not retry.
|
|
//
|
|
// The real server's mismatch path is already proven by tools/protocol.test.mjs (it takes a build
|
|
// whose proto differs). Here the browser's own WebSocket is intercepted and given exactly that
|
|
// documented frame sequence, so the assertion is about the client's UI and close-code mapping.
|
|
import test from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import { launchBrowser, newPage, waitForText, waitForVisible, withStack } from './stack.mjs'
|
|
|
|
test('protocol mismatch: the client shows reload and does not reconnect', { timeout: 120000 }, async () => {
|
|
await withStack(async ({ origin }) => {
|
|
const browser = await launchBrowser()
|
|
try {
|
|
const { page } = await newPage(browser)
|
|
let sockets = 0
|
|
await page.routeWebSocket(/\/ws\?proto=2$/, ws => {
|
|
sockets += 1
|
|
// DESIGN 6.5 row 5: closing then the close frame; no hello, no state.
|
|
ws.send(JSON.stringify({ t: 'closing', n: 1, reason: 'proto-mismatch', code: 4003 }))
|
|
ws.close()
|
|
})
|
|
|
|
await page.goto(`${origin}/`)
|
|
await waitForVisible(page, '#fatal')
|
|
await waitForText(page, '#fatal-text', /out of date.*reload/i)
|
|
const reload = page.locator('#reload')
|
|
assert.equal(await reload.isVisible(), true)
|
|
assert.equal(await page.locator('#signin').isVisible(), false)
|
|
assert.equal(await page.locator('#stage canvas').count(), 0)
|
|
|
|
await new Promise(resolve => setTimeout(resolve, 400))
|
|
assert.equal(sockets, 1, 'a mismatch is terminal: exactly one connection attempt')
|
|
} finally {
|
|
await browser.close()
|
|
}
|
|
})
|
|
})
|