Files
faunosteo/scripts/browser/lib/app-build.mjs
T
bchanot 08f01ef363 test(tests): R4.3d browser proofs on the production build: app import baseline on the Rust path, CSP with and without the keyword, leak series, WebKit repetition
Same perimeter as the TS baseline (226 files, 3 engines, real Home page): 666/678 outcome
and message agreements, the 12 others the 4 declared files; W5 0 long tasks (TS 91 and
173 ms); 50 MiB file in WebKit 145/126 MiB against 324 with the worker read and 76 for the
TS. CSP: editor opens with the keyword, the engine message without, in 3 engines, the
worker's wasm-eval refusal reported by Chromium and Firefox. Leak series on the app:
Chromium ≤ 2 MiB per import after init, Firefox GC sawtooth reclaimed, WebKit grows with
same-tab navigations (control too) and levels off on one page; 20/20 WebKit workers closed.
2026-10-18 19:48:31 +02:00

60 lines
2.0 KiB
JavaScript

import { execFileSync } from 'node:child_process'
import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs'
import { join } from 'node:path'
import { sha256 } from './inputs.mjs'
import { DIST_DIR, REPO_ROOT } from './paths.mjs'
/**
* The harness measures a production build that embeds the reference sheet.
* It never builds by itself: the build command is printed instead, so a run
* always names the build it measured (mtime, chunk sizes and digests, HEAD).
* `headCommit` is HEAD when the run starts, which can differ from the commit
* the build was made from: the chunk digests identify the build itself.
*/
export const BUILD_COMMAND =
'SHEET_BUNDLE=draft corepack pnpm --filter @faunosteo/app build'
// A build without the sheet (SHEET_BUNDLE=none) leaves a 40-byte stub chunk.
const MIN_SHEET_CHUNK_BYTES = 10_000
function assetSize(pattern) {
const assets = join(DIST_DIR, 'assets')
const name = readdirSync(assets).find((file) => pattern.test(file))
if (!name) return null
const path = join(assets, name)
return {
name,
bytes: statSync(path).size,
sha256: sha256(readFileSync(path)),
}
}
function headCommit() {
try {
const args = ['-C', REPO_ROOT, 'rev-parse', '--short', 'HEAD']
return execFileSync('git', args, { encoding: 'utf8' }).trim()
} catch {
return null
}
}
export function checkBuild() {
const index = join(DIST_DIR, 'index.html')
if (!existsSync(index)) {
throw new Error(`no build in apps/app/dist: run ${BUILD_COMMAND}`)
}
const sheet = assetSize(/^_virtual_faunosteo-sheet-.*\.js$/)
if (!sheet || sheet.bytes < MIN_SHEET_CHUNK_BYTES) {
throw new Error(`the build carries no sheet: run ${BUILD_COMMAND}`)
}
return {
distDir: 'apps/app/dist',
builtAt: statSync(index).mtime.toISOString(),
sheetChunk: sheet,
entryChunk: assetSize(/^index-.*\.js$/),
wasm: assetSize(/\.wasm$/),
importWorker: assetSize(/^import\.worker-.*\.js$/),
headCommit: headCommit(),
}
}