Files
faunosteo/packages/core-wasm/tests/facade.test.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

53 lines
1.8 KiB
TypeScript

import { readFileSync } from 'node:fs'
import { fileURLToPath } from 'node:url'
import { nodeCoreRuntime, nodeCoreSource } from '../src/node'
const CORE_MANIFEST = new URL(
'../../../crates/core/Cargo.toml',
import.meta.url,
)
const WORKSPACE_MANIFEST = new URL('../../../Cargo.toml', import.meta.url)
const SHIPPED_DTS = new URL('../pkg/faunosteo_wasm.d.ts', import.meta.url)
describe('core facade (shipped wasm build)', () => {
it('reports the workspace version of the core', async () => {
const core = await nodeCoreRuntime()
const workspace = readFileSync(fileURLToPath(WORKSPACE_MANIFEST), 'utf8')
const version = /\[workspace\.package\][^[]*?version = "([^"]+)"/s.exec(
workspace,
)?.[1]
expect(version).toBeDefined()
expect(readFileSync(fileURLToPath(CORE_MANIFEST), 'utf8')).toContain(
'version.workspace = true',
)
expect(core.call('core_version', '')).toEqual({ ok: true, value: version })
})
it('answers with a closed outcome envelope', async () => {
const core = await nodeCoreRuntime()
expect(core.call('nope', '{}')).toMatchObject({
ok: false,
kind: 'unknown_op',
})
expect(core.call('pretty_json', '{ not json')).toMatchObject({
ok: false,
kind: 'invalid_json',
})
})
it('ships no trap export (the proofs live in pkg-proofs only)', async () => {
const glue = (await nodeCoreSource('pkg').importGlue(0)) as unknown as Record<
string,
unknown
>
for (const name of ['core_version', 'call', 'SheetHandle']) {
expect(typeof glue[name]).toBe('function')
}
expect(glue.panic_for_test).toBeUndefined()
expect(glue.recurse_for_test).toBeUndefined()
const dts = readFileSync(fileURLToPath(SHIPPED_DTS), 'utf8')
expect(dts).not.toMatch(/panic_for_test|recurse_for_test/)
})
})