test: TLS + HTTP/2 test vhost with the client dist served at /

The test nginx is now the production shape of DESIGN 11.1 and the browser
gate's real path (#66, spec #63 decision 6): TLS-only listener with
http2 on, a self-signed certificate generated per run (tools/tlsdev.mjs,
added to the process's default CA list so verification stays on), the
client dist at / with SPA fallback, index no-cache and a year-immutable
/assets/ cache, and the tile gate's internal /_tiles/ still unreachable.

Existing tile/doors/oneway/wallbehaviour harnesses point their server's
public origin at the https vhost, so they prove the same listener the
browser uses. tools/vhost.test.mjs is the independent node:http2 client
(cert SANs, ALPN h2, cache headers, SPA fallback, direct /_tiles/ 404);
e2e/h2.test.mjs drives devbox chromium via playwright-core and asserts
the page reports h2 (`devbox run e2e`, npm deps outside tools/).

Root devbox gains chromium + openssl. Harness builds use a worktree-local
nimcache so parallel worktrees stop corrupting each other's objects.

Refs #66
This commit is contained in:
2026-11-20 23:11:05 +01:00
parent 0448002cc5
commit 1dff520f31
18 changed files with 627 additions and 27 deletions
+80
View File
@@ -0,0 +1,80 @@
// The browser e2e gate (TESTING 10.3 "Browser e2e"; #66 first slice). `playwright-core` drives the
// devbox `chromium` against the real server through the TLS/HTTP2 test nginx: the one proof that
// matters before a phone is asked to measure is that real browsers negotiate h2 over the vhost and
// execute the built client from `/`.
//
// The app's own e2e (join, fog pixels, drag, reconnect, traffic audit) lands with the client in T4+
// on this same harness. Here the page is the fixture `dist` of tools/distfixture.mjs, so the gate
// exists and is green before the client package does.
import test from 'node:test'
import assert from 'node:assert/strict'
import fs from 'node:fs'
import { chromium } from 'playwright-core'
import { freePort, httpsBaseUrl } from '../tools/lib.mjs'
import { makeStateDir, startServer, stopServer } from '../tools/withserver.mjs'
import { startTestNginx, stopTestNginx } from '../tools/nginx.mjs'
import { writeClientDist } from '../tools/distfixture.mjs'
// Nix's chromium is a wrapper around the real binary; playwright-core launches it by path (the
// perf prototype does the same). SwiftShader is enough for correctness, never for a perf number.
const CHROMIUM = process.env.CHROMIUM ?? 'chromium'
const LAUNCH_ARGS = ['--no-sandbox', '--use-angle=swiftshader', '--enable-unsafe-swiftshader',
'--ignore-gpu-blocklist']
async function stack(fn) {
const stateDir = makeStateDir()
const dist = writeClientDist(`${stateDir}/dist`)
const nginxPort = await freePort()
const server = await startServer({ stateDir, publicOrigin: httpsBaseUrl(nginxPort) })
let nginx
try {
nginx = await startTestNginx({ backendPort: server.port, stateDir, port: nginxPort, distDir: dist.dir })
return await fn({ stateDir, server, nginx, dist, origin: nginx.origin })
} finally {
await stopTestNginx(nginx)
await stopServer(server)
fs.rmSync(stateDir, { recursive: true, force: true })
}
}
test('e2e: headless chromium loads the client dist and the page reports h2', async () => {
await stack(async ({ origin, dist }) => {
const browser = await chromium.launch({ executablePath: CHROMIUM, args: LAUNCH_ARGS })
try {
// The certificate is a generated self-signed one (tools/tlsdev.mjs); a browser must be told
// to accept it. Every other security property of the page is the real thing.
const context = await browser.newContext({ ignoreHTTPSErrors: true })
const page = await context.newPage()
const loaded = []
page.on('response', r => loaded.push({ url: r.url(), status: r.status() }))
const errors = []
page.on('pageerror', e => errors.push(e.message))
page.on('console', m => { if (m.type() === 'error') errors.push(m.text()) })
await page.goto(`${origin}/`, { waitUntil: 'load' })
assert.equal(await page.title(), 'fff-vtt client fixture')
assert.equal(await page.textContent('#fixture'), 'client dist fixture')
// The hashed asset was fetched and executed by the vhost's immutable-cache location.
assert.equal(await page.evaluate(() => document.documentElement.dataset.fixture), 'loaded')
assert.deepEqual(errors, [])
const assetResponse = loaded.find(r => r.url.endsWith(dist.assetPath))
assert.ok(assetResponse, `the page loaded ${dist.assetPath}: ${JSON.stringify(loaded)}`)
assert.equal(assetResponse.status, 200)
// The acceptance criterion: the browser's own view of the connection is h2 over TLS.
const proto = await page.evaluate(() => {
const nav = performance.getEntriesByType('navigation')[0]
const resources = performance.getEntriesByType('resource')
.map(e => ({ name: e.name, protocol: e.nextHopProtocol }))
return { scheme: location.protocol, navigation: nav.nextHopProtocol, resources }
})
assert.equal(proto.scheme, 'https:')
assert.equal(proto.navigation, 'h2', 'the document came over HTTP/2')
assert.ok(proto.resources.some(r => r.protocol === 'h2' && r.name.endsWith('.js')),
`subresources are h2 too: ${JSON.stringify(proto.resources)}`)
} finally {
await browser.close()
}
})
})
+28
View File
@@ -0,0 +1,28 @@
{
"name": "fff-vtt-e2e",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "fff-vtt-e2e",
"version": "1.0.0",
"devDependencies": {
"playwright-core": "1.65.1"
}
},
"node_modules/playwright-core": {
"version": "1.65.1",
"resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.65.1.tgz",
"integrity": "sha512-hqPpz7blSMPxWVdoeE1yiBSzXsKiVOd2k+kjCvmUywD2GPO2Dd9HfcWnq9NN0GHbNZDFgZ9JfBFr+X5/BLo0qw==",
"dev": true,
"license": "Apache-2.0",
"bin": {
"playwright-core": "cli.js"
},
"engines": {
"node": ">=20"
}
}
}
}
+10
View File
@@ -0,0 +1,10 @@
{
"name": "fff-vtt-e2e",
"version": "1.0.0",
"private": true,
"type": "module",
"description": "Headless-browser e2e for fff-vtt (playwright-core + the devbox chromium). Lives outside tools/ because TESTING 10.4 keeps the black-box harnesses npm-dependency-free.",
"devDependencies": {
"playwright-core": "1.65.1"
}
}
Executable
+18
View File
@@ -0,0 +1,18 @@
#!/usr/bin/env bash
# devbox run e2e: the headless-browser gate (TESTING 10.3). Separate from `devbox run test` so the
# fast server gate stays fast (TESTING 11.1 note in #66). Requires the root devbox's `chromium` and
# the e2e/ npm dependency (`playwright-core`); the client build test in T4+ extends this script.
set -euo pipefail
cd "$(dirname "$0")/.." || exit 1
mkdir -p results
export CHROMIUM="${CHROMIUM:-$(command -v chromium || true)}"
if [ -z "$CHROMIUM" ]; then
echo "e2e: chromium not found; it is a root devbox package (devbox.json) - run inside devbox" >&2
exit 1
fi
# npm deps stay out of tools/ (TESTING 10.4) and out of git; install once per checkout.
( cd e2e && { [ -d node_modules ] || npm ci --no-audit --no-fund; } )
node --test --test-concurrency=1 --test-reporter=spec e2e/*.test.mjs > results/e2e.log 2>&1
rc=$?
cat results/e2e.log
exit $rc