test(tests): R4.2e browser measurements of the Rust import (module worker page, same perimeter as the TS baseline)
r4-import.mjs runs the 226 baseline files and the hostile classes through a disposable module worker calling SheetHandle.import_pdf in Chromium 156, Firefox 157 and WebKit 27.2 under the RSS watchdog (not a guaranteed limit); compare-imports.mjs prints TS vs Rust; serve.mjs gains opt-in mounts (/r4/, /pkg/). Results 2026-10-18-r4-import.json: 666/678 agreements, the 12 others are the 4 declared files; W4 met (max 68 MiB linear); the 1 GiB ceiling traps in every engine.
This commit is contained in:
1 parent
cad485b13c
commit
c84186b032
14 files changed
+3135
-17
No files matched your search
+47
-12
@@ -4,18 +4,23 @@
|
||||
// the env.js docker/entrypoint.sh writes when no APP_* variable is set (the
|
||||
// local tool, no Supabase). Binds 127.0.0.1 only.
|
||||
//
|
||||
// node scripts/browser/serve.mjs [--port 4173] [--csp with|without]
|
||||
// node scripts/browser/serve.mjs [--port 4173] [--csp with|without] [--r4]
|
||||
//
|
||||
// --csp with (default): script-src carries 'wasm-unsafe-eval' (DEPLOY.md
|
||||
// note for R2+ images); without: the header exactly without the keyword,
|
||||
// for the CSP proofs of later slices.
|
||||
//
|
||||
// --r4 also mounts the R4 import page and the core module builds (R4.2e,
|
||||
// r4-import.mjs): /r4/ (scripts/browser/r4-import-page), /pkg/ and
|
||||
// /pkg-proofs/ (packages/core-wasm). A mounted path is a file or a 404,
|
||||
// never the SPA fallback. Without it nothing changes.
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { readFile, stat } from 'node:fs/promises'
|
||||
import { createServer } from 'node:http'
|
||||
import { extname, join, resolve, sep } from 'node:path'
|
||||
import { pathToFileURL } from 'node:url'
|
||||
import { parseArgs } from 'node:util'
|
||||
import { DIST_DIR, REPO_ROOT } from './lib/paths.mjs'
|
||||
import { DIST_DIR, HARNESS_DIR, REPO_ROOT } from './lib/paths.mjs'
|
||||
|
||||
const HOST = '127.0.0.1'
|
||||
const WASM_KEYWORD = "'wasm-unsafe-eval'"
|
||||
@@ -33,6 +38,12 @@ const MIME = {
|
||||
'.txt': 'text/plain; charset=utf-8',
|
||||
}
|
||||
|
||||
export const R4_MOUNTS = {
|
||||
'/r4/': join(HARNESS_DIR, 'r4-import-page'),
|
||||
'/pkg/': join(REPO_ROOT, 'packages/core-wasm/pkg'),
|
||||
'/pkg-proofs/': join(REPO_ROOT, 'packages/core-wasm/pkg-proofs'),
|
||||
}
|
||||
|
||||
// Byte for byte what docker/entrypoint.sh writes with no APP_* variable set.
|
||||
export const LOCAL_TOOL_ENV_JS = `window.__APP_CONFIG__ = {
|
||||
siteName: "Faunosteo",
|
||||
@@ -96,38 +107,59 @@ function send(res, { status, body = '', type, csp, noStore = false, head }) {
|
||||
res.end(head ? undefined : body)
|
||||
}
|
||||
|
||||
async function fileAnswer(file) {
|
||||
const type = MIME[extname(file)] ?? 'application/octet-stream'
|
||||
return { body: await readFile(file), type }
|
||||
}
|
||||
|
||||
/** A mounted directory: its file (index.html for a directory) or a 404. */
|
||||
async function mountedAnswer(mounts, path) {
|
||||
const prefix = Object.keys(mounts).find((p) => path.startsWith(p))
|
||||
if (!prefix) return null
|
||||
const rest = path.slice(prefix.length - 1)
|
||||
const file = await fileUnder(
|
||||
mounts[prefix],
|
||||
rest.endsWith('/') ? `${rest}index.html` : rest,
|
||||
)
|
||||
return file ? fileAnswer(file) : { status: 404 }
|
||||
}
|
||||
|
||||
/** nginx.conf: env.js generated, /assets/ files or 404, else the SPA. */
|
||||
async function route(root, path) {
|
||||
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 }
|
||||
}
|
||||
const file = await fileUnder(root, path)
|
||||
if (file) {
|
||||
const type = MIME[extname(file)] ?? 'application/octet-stream'
|
||||
return { body: await readFile(file), type }
|
||||
}
|
||||
if (file) return fileAnswer(file)
|
||||
if (path.startsWith('/assets/')) return { status: 404 }
|
||||
return { body: await readFile(join(root, 'index.html')), type: MIME['.html'] }
|
||||
}
|
||||
|
||||
async function respond(req, res, { root, csp }) {
|
||||
async function respond(req, res, { root, csp, mounts }) {
|
||||
const head = req.method === 'HEAD'
|
||||
if (req.method !== 'GET' && !head) return send(res, { status: 405, csp })
|
||||
const path = requestPath(req.url)
|
||||
if (path === null) return send(res, { status: 400, csp })
|
||||
try {
|
||||
const answer = await route(root, path)
|
||||
const answer = await route(root, path, mounts)
|
||||
send(res, { status: 200, ...answer, csp, head })
|
||||
} catch {
|
||||
send(res, { status: 500, csp })
|
||||
}
|
||||
}
|
||||
|
||||
/** Starts the server; `port` 0 picks a free one. */
|
||||
export function startServer({ root = DIST_DIR, port = 0, csp = 'with' } = {}) {
|
||||
/** Starts the server; `port` 0 picks a free one; `mounts` see --r4. */
|
||||
export function startServer({
|
||||
root = DIST_DIR,
|
||||
port = 0,
|
||||
csp = 'with',
|
||||
mounts = {},
|
||||
} = {}) {
|
||||
const policy = cspVariant(productionCsp(), csp)
|
||||
const server = createServer((req, res) =>
|
||||
respond(req, res, { root, csp: policy }),
|
||||
respond(req, res, { root, csp: policy, mounts }),
|
||||
)
|
||||
return new Promise((done, fail) => {
|
||||
server.once('error', fail)
|
||||
@@ -143,6 +175,7 @@ async function main() {
|
||||
options: {
|
||||
port: { type: 'string', default: '4173' },
|
||||
csp: { type: 'string', default: 'with' },
|
||||
r4: { type: 'boolean', default: false },
|
||||
},
|
||||
})
|
||||
if (!['with', 'without'].includes(values.csp)) {
|
||||
@@ -151,8 +184,10 @@ async function main() {
|
||||
const server = await startServer({
|
||||
port: Number(values.port),
|
||||
csp: values.csp,
|
||||
mounts: values.r4 ? R4_MOUNTS : {},
|
||||
})
|
||||
console.log(`serving apps/app/dist on ${server.url}`)
|
||||
if (values.r4) console.log(`R4 import page on ${server.url}/r4/`)
|
||||
console.log(`Content-Security-Policy: ${server.csp}`)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user