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
+45
View File
@@ -0,0 +1,45 @@
// The test nginx's TLS material (#66, DESIGN 11.1 / TESTING 11.1). A self-signed certificate is
// GENERATED at run time, never committed: browsers only negotiate HTTP/2 over TLS, and the session
// cookie is `Secure`, so the browser e2e and the harnesses have to speak https.
//
// 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.
import { spawnSync } from 'node:child_process'
import fs from 'node:fs'
import path from 'node:path'
const SUBJECT = '/CN=fff-vtt test nginx'
const SAN = 'subjectAltName=DNS:localhost,IP:127.0.0.1'
function generate(dir) {
fs.mkdirSync(dir, { recursive: true })
const certPath = path.join(dir, 'cert.pem')
const keyPath = path.join(dir, 'key.pem')
const r = spawnSync('openssl', [
'req', '-x509', '-newkey', 'ec', '-pkeyopt', 'ec_paramgen_curve:prime256v1',
'-nodes', '-sha256', '-days', '3',
'-keyout', keyPath, '-out', certPath,
'-subj', SUBJECT,
// CA:TRUE so the pair is usable as a trust anchor (NODE_EXTRA_CA_CERTS) as well as a leaf;
// serverAuth + digitalSignature so a browser/h2 client accepts it as a TLS server certificate.
'-addext', SAN,
'-addext', 'basicConstraints=critical,CA:TRUE',
'-addext', 'keyUsage=critical,digitalSignature,keyCertSign',
'-addext', 'extendedKeyUsage=serverAuth',
], { encoding: 'utf8' })
if (r.status !== 0) {
throw new Error(`openssl could not generate the test certificate (is the openssl devbox ` +
`package installed?):\n${r.stdout}\n${r.stderr}`)
}
return { certPath, keyPath }
}
// Ensures <dir>/{cert,key}.pem exist and returns their paths. Idempotent: an existing pair is
// reused, so a run's harness files start from the same anchor.
export function ensureDevCert(dir) {
const certPath = path.join(dir, 'cert.pem')
const keyPath = path.join(dir, 'key.pem')
if (fs.existsSync(certPath) && fs.existsSync(keyPath)) return { certPath, keyPath }
return generate(dir)
}