Files
FFF_vtt_frozen/e2e/h2.test.mjs
T
SirStone 1dff520f31 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
2026-11-20 23:11:05 +01:00

81 lines
4.1 KiB
JavaScript

// 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()
}
})
})