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.
This commit is contained in:
1 parent
22fea8736d
commit
343d6f4c1f
22 files changed
+783
-180
No files matched your search
@@ -9,8 +9,8 @@ import { fileURLToPath } from 'node:url'
|
||||
import { ReportZoneSchema, SheetRefSchema } from './n-1/domain'
|
||||
|
||||
import type { ReportZone, SheetRef } from '../types/index'
|
||||
import { callCore, loadCore, type CoreModule } from '../src/index'
|
||||
import { coreBuilt } from './helpers/core'
|
||||
import type { CoreRuntime } from '../src/index'
|
||||
import { nodeCoreRuntime } from '../src/node'
|
||||
|
||||
const FIXTURES = [
|
||||
'apps/app/tests/fixtures/report-v3.demo.json',
|
||||
@@ -32,17 +32,17 @@ function repoFile(relative: string): string {
|
||||
)
|
||||
}
|
||||
|
||||
function prettyByCore(core: CoreModule, text: string): string {
|
||||
const outcome = callCore<string>(core, 'pretty_json', text)
|
||||
function prettyByCore(core: CoreRuntime, text: string): string {
|
||||
const outcome = core.call<string>('pretty_json', text)
|
||||
if (!outcome.ok) throw new Error(`${outcome.kind}: ${outcome.detail ?? ''}`)
|
||||
return outcome.value
|
||||
}
|
||||
|
||||
describe.skipIf(!coreBuilt)('serialisation contract (wasm)', () => {
|
||||
describe('serialisation contract (wasm)', () => {
|
||||
it.each(FIXTURES)(
|
||||
'%s: core pretty output equals JSON.stringify(…, null, 2)',
|
||||
async (relative) => {
|
||||
const core = await loadCore()
|
||||
const core = await nodeCoreRuntime()
|
||||
const text = repoFile(relative)
|
||||
const expected = JSON.stringify(JSON.parse(text), null, 2)
|
||||
expect(prettyByCore(core, text)).toBe(expected)
|
||||
@@ -50,7 +50,7 @@ describe.skipIf(!coreBuilt)('serialisation contract (wasm)', () => {
|
||||
)
|
||||
|
||||
it('prints every number as JavaScript does', async () => {
|
||||
const core = await loadCore()
|
||||
const core = await nodeCoreRuntime()
|
||||
const text = JSON.stringify(NUMBER_CASES)
|
||||
expect(prettyByCore(core, text)).toBe(
|
||||
JSON.stringify(JSON.parse(text), null, 2),
|
||||
@@ -58,9 +58,8 @@ describe.skipIf(!coreBuilt)('serialisation contract (wasm)', () => {
|
||||
})
|
||||
|
||||
it('writes optional fields absent and nullable fields null, readable by the Zod schemas', async () => {
|
||||
const core = await loadCore()
|
||||
const bare = callCore<ReportZone>(
|
||||
core,
|
||||
const core = await nodeCoreRuntime()
|
||||
const bare = core.call<ReportZone>(
|
||||
'report_zone',
|
||||
JSON.stringify({ annotationId: 'hip', viewId: 'main' }),
|
||||
)
|
||||
@@ -72,8 +71,7 @@ describe.skipIf(!coreBuilt)('serialisation contract (wasm)', () => {
|
||||
expect(Object.keys(bare.value)).toEqual(['annotationId', 'viewId'])
|
||||
expect(ReportZoneSchema.parse(bare.value)).toEqual(bare.value)
|
||||
|
||||
const full = callCore<ReportZone>(
|
||||
core,
|
||||
const full = core.call<ReportZone>(
|
||||
'report_zone',
|
||||
JSON.stringify({
|
||||
viewId: 'main',
|
||||
@@ -93,8 +91,7 @@ describe.skipIf(!coreBuilt)('serialisation contract (wasm)', () => {
|
||||
},
|
||||
})
|
||||
|
||||
const sheet = callCore<SheetRef>(
|
||||
core,
|
||||
const sheet = core.call<SheetRef>(
|
||||
'sheet_ref',
|
||||
JSON.stringify({
|
||||
sheetId: 'faunosteo-cheval',
|
||||
@@ -105,8 +102,7 @@ describe.skipIf(!coreBuilt)('serialisation contract (wasm)', () => {
|
||||
expect(sheet.ok && sheet.value.versionId).toBeNull()
|
||||
if (sheet.ok) expect(SheetRefSchema.parse(sheet.value)).toEqual(sheet.value)
|
||||
|
||||
const refused = callCore(
|
||||
core,
|
||||
const refused = core.call(
|
||||
'report_zone',
|
||||
JSON.stringify({ annotationId: 'a', viewId: 'v', unresolved: false }),
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user