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:
@@ -1,24 +0,0 @@
|
||||
// A throwaway client build for the vhost tests (#66). The real Vite build lands in T4; until then the
|
||||
// test nginx's `/` needs *some* `dist` to serve, with the shape DESIGN 11.1 pins: an index.html that
|
||||
// names a content-hashed asset under /assets/. Nothing here is committed: the fixture is written into
|
||||
// the run's state dir, and no version of it pretends to be the client.
|
||||
import fs from 'node:fs'
|
||||
import path from 'node:path'
|
||||
|
||||
export const ASSET_HASH = 'a1b2c3d4e5f6'
|
||||
|
||||
export function writeClientDist(dir, { hash = ASSET_HASH } = {}) {
|
||||
const assetPath = `/assets/app-${hash}.js`
|
||||
fs.mkdirSync(path.join(dir, 'assets'), { recursive: true })
|
||||
const index = `<!doctype html>
|
||||
<html lang="en">
|
||||
<head><meta charset="utf-8"><title>fff-vtt client fixture</title>
|
||||
<script type="module" src="${assetPath}"></script></head>
|
||||
<body><p id="fixture">client dist fixture</p></body>
|
||||
</html>
|
||||
`
|
||||
const asset = `// content-hashed fixture asset (#66)\ndocument.documentElement.dataset.fixture = 'loaded'\n`
|
||||
fs.writeFileSync(path.join(dir, 'index.html'), index)
|
||||
fs.writeFileSync(path.join(dir, assetPath.slice(1)), asset)
|
||||
return { dir, indexHtml: index, assetPath }
|
||||
}
|
||||
+1
-1
@@ -4,7 +4,7 @@
|
||||
//
|
||||
// One directory per run (`run/tls`, gitignored) is shared by every harness file in the run: the
|
||||
// certificate is a trust anchor for the Node side through NODE_EXTRA_CA_CERTS (set by tools/test.sh
|
||||
// and e2e/run.sh), and nginx loads the same pair. The SANs are what a client checks on loopback.
|
||||
// and client/e2e/run.sh), and nginx loads the same pair. The SANs are what a client checks on loopback.
|
||||
import { spawnSync } from 'node:child_process'
|
||||
import fs from 'node:fs'
|
||||
import path from 'node:path'
|
||||
|
||||
+27
-4
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user