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/) }) })