fix(tests): recette server sends the nginx.conf Cache-Control lines (env.js no-store, /assets/ immutable) so an offline import reuses the cached worker chunk; r4-offline-import.mjs re-runs J1.7 on three engines and two network cuts

This commit is contained in:
bchanot committed 2026-10-21 00:26:06 +02:00
1 parent 45093135e9
commit 63034e10c4
3 files changed
+247 -4

No files matched your search

+11 -4
View File
@@ -1,5 +1,6 @@
// Static server of the production build for the browser harness (R4.1e):
// apps/app/dist with the SPA fallback of docker/nginx.conf, `.wasm` as
// apps/app/dist with the SPA fallback and the Cache-Control lines of
// docker/nginx.conf (an offline import reuses the cached worker chunk), `.wasm` as
// application/wasm, the production CSP of DEPLOY.md on every response, and
// the env.js docker/entrypoint.sh writes when no APP_* variable is set (the
// local tool, no Supabase). Binds 127.0.0.1 by default, or the one address
@@ -56,6 +57,9 @@ async function bindAddress(host) {
return results[0]
}
const WASM_KEYWORD = "'wasm-unsafe-eval'"
// The Cache-Control values of docker/nginx.conf (env.js, /assets/).
export const NO_STORE = 'no-store, no-cache, must-revalidate'
export const IMMUTABLE = 'public, max-age=31536000, immutable'
const REPORT_PATH = '/__csp-report'
const MAX_REPORT_BYTES = 64 * 1024
const MIME = {
@@ -132,10 +136,10 @@ async function fileUnder(root, path) {
}
}
function send(res, { status, body = '', type, csp, noStore = false, head }) {
function send(res, { status, body = '', type, csp, cache, head }) {
const headers = { 'Content-Security-Policy': csp }
if (type) headers['Content-Type'] = type
if (noStore) headers['Cache-Control'] = 'no-store, no-cache, must-revalidate'
if (cache) headers['Cache-Control'] = cache
headers['Content-Length'] = Buffer.byteLength(body)
res.writeHead(status, headers)
res.end(head ? undefined : body)
@@ -163,9 +167,12 @@ async function route(root, path, mounts) {
const mounted = await mountedAnswer(mounts, path)
if (mounted) return mounted
if (path === '/env.js') {
return { body: LOCAL_TOOL_ENV_JS, type: MIME['.js'], noStore: true }
return { body: LOCAL_TOOL_ENV_JS, type: MIME['.js'], cache: NO_STORE }
}
const file = await fileUnder(root, path)
if (file && path.startsWith('/assets/')) {
return { ...(await fileAnswer(file)), cache: IMMUTABLE }
}
if (file) return fileAnswer(file)
if (path.startsWith('/assets/')) return { status: 404 }
return { body: await readFile(join(root, 'index.html')), type: MIME['.html'] }