diff --git a/tests/hs-run-filtered.js b/tests/hs-run-filtered.js index 2d5270eb..d5baf1e1 100755 --- a/tests/hs-run-filtered.js +++ b/tests/hs-run-filtered.js @@ -14,6 +14,28 @@ const SX_DIR = path.join(WASM_DIR, 'sx'); eval(fs.readFileSync(path.join(WASM_DIR, 'sx_browser.bc.js'), 'utf8')); const K = globalThis.SxKernel; +// Auto-unwrap shim: the post-JIT-Phase-1 kernel returns numbers, strings, +// booleans, and nil as opaque value handles ({_type, __sx_handle}). Tests +// expect plain JS values from K.eval like the pre-rewrite kernel did. Wrap +// once at boot rather than touching all 23 K.eval call sites. +if (K && typeof K.eval === 'function' && K.stringify) { + const _kEval = K.eval.bind(K); + K.eval = function(expr) { + const r = _kEval(expr); + if (r && typeof r === 'object' && typeof r._type === 'string') { + switch (r._type) { + case 'number': { const s = K.stringify(r); const n = Number(s); + return Number.isInteger(n) || /^-?\d+$/.test(s) ? n : (Number.isNaN(n) ? r : n); } + case 'string': return K.stringify(r); + case 'boolean': return K.stringify(r) === 'true'; + case 'nil': return null; + default: return r; // list/dict/symbol — leave as handle + } + } + return r; + }; +} + // Step limit API — exposed from OCaml kernel const STEP_LIMIT = parseInt(process.env.HS_STEP_LIMIT || '1000000');