Files
faunosteo/packages/core-wasm/tests/global-setup.ts
T
bchanot 343d6f4c1f feat(workspace): R2.4 core runtime — lazy load, poison on trap, offline re-instantiation, per-generation sheet handles
packages/core-wasm: browser-safe CoreRuntime (synchronous calls once ready;
a WebAssembly.RuntimeError poisons the instance, the call answers internal,
a fresh instance comes from the kept compiled module and a glue record
imported in advance; at most 3 recoveries per page; retry after a load
failure), SheetSession (handle rebuilt per instance generation, never
called on a dropped one; invalid_sheet without poisoning), Node source.
crates/wasm: SheetHandle (sheet held in the module memory). Two builds:
pkg/ shipped without trap exports (checked), pkg-proofs/ for the trap
tests; BUILD_STAMP (hash of the Rust sources) refused when missing or
stale by the vitest global setup instead of skipping. Failure envelope
carries a numeric found version; compact JS-number output.
2026-10-14 00:12:04 +02:00

26 lines
927 B
TypeScript

/**
* Vitest global setup of every suite that runs the core: refuses to run on a missing or
* stale module instead of skipping (R2 plan rev 2). The stamp is the hash of the Rust
* sources the module is compiled from (scripts/wasm-stamp.mjs), written by
* `pnpm wasm:build` into both builds.
*/
import { existsSync, readFileSync } from 'node:fs'
import { fileURLToPath } from 'node:url'
import { wasmStamp } from '../../../scripts/wasm-stamp.mjs'
export default function checkCoreBuilds(): void {
const expected = wasmStamp()
for (const build of ['pkg', 'pkg-proofs']) {
const file = fileURLToPath(
new URL(`../${build}/BUILD_STAMP`, import.meta.url),
)
const found = existsSync(file) ? readFileSync(file, 'utf8').trim() : null
if (found !== expected) {
throw new Error(
`packages/core-wasm/${build} is ${found ? 'stale' : 'missing'}: run \`pnpm wasm:build\``,
)
}
}
}