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
+27 -4
View File
@@ -2,20 +2,43 @@
// by ALPN, the client build at `/` (SPA fallback, index no-cache, hashed assets immutable), and the
// tile gate's `internal` location still unreachable from outside. The certificate is generated per
// run by tools/tlsdev.mjs. Here a Node HTTP/2 client (built-in `node:http2`, TESTING 10.4) is the
// independent client; the headless-browser proof lives in `e2e/` (npm dep, outside tools/).
// independent client; the headless-browser proof against the real build lives in `client/e2e/`
// (`devbox run e2e`, npm deps outside tools/).
import test from 'node:test'
import assert from 'node:assert/strict'
import fs from 'node:fs'
import http2 from 'node:http2'
import path from 'node:path'
import { X509Certificate } from 'node:crypto'
import { freePort, httpsBaseUrl, refuseLivePort } from './lib.mjs'
import { makeStateDir, startServer, stopServer } from './withserver.mjs'
import { startTestNginx, stopTestNginx } from './nginx.mjs'
import { writeClientDist } from './distfixture.mjs'
// This group proves nginx's config, not the app, and runs inside `devbox run test`, which must not
// need the client's npm build. The stub has the exact shape DESIGN 11.1 pins (hashed asset under
// /assets/ named by index.html); `client/e2e/h2.test.mjs` repeats the same assertions on the real
// Vite output.
const STUB_HASH = 'a1b2c3d4e5f6'
function writeStubDist(dir) {
const assetPath = `/assets/app-${STUB_HASH}.js`
fs.mkdirSync(path.join(dir, 'assets'), { recursive: true })
const indexHtml = `<!doctype html>
<html lang="en">
<head><meta charset="utf-8"><title>vhost stub</title>
<script type="module" src="${assetPath}"></script></head>
<body><p id="stub">dist stub</p></body>
</html>
`
const asset = `// content-hashed stub asset (#66)\ndocument.documentElement.dataset.stub = 'loaded'\n`
fs.writeFileSync(path.join(dir, 'index.html'), indexHtml)
fs.writeFileSync(path.join(dir, assetPath.slice(1)), asset)
return { dir, indexHtml, assetPath }
}
async function stack(fn) {
const stateDir = makeStateDir()
const dist = writeClientDist(`${stateDir}/dist`)
const dist = writeStubDist(`${stateDir}/dist`)
const nginxPort = await freePort()
refuseLivePort(nginxPort)
const server = await startServer({ stateDir, publicOrigin: httpsBaseUrl(nginxPort) })
@@ -85,7 +108,7 @@ test('vhost: hashed assets are immutable, the SPA falls back, a missing asset is
assert.equal(asset.alpn, 'h2')
assert.match(asset.headers['content-type'], /^application\/javascript/)
assert.equal(asset.headers['cache-control'], 'public, max-age=31536000, immutable')
assert.match(asset.body, /content-hashed fixture asset/)
assert.match(asset.body, /content-hashed stub asset/)
// A client-side route with no file behind it is index.html (SPA fallback), revalidated.
const route = await h2Get(nginx.origin, '/scene/abc/tokens')