hs: port loops/hs RPC test infrastructure to architecture's test runner

Two additions from loops/hs needed for the new WebSocket socket tests:
- unhandledRejection suppressor — synchronous test harness doesn't await RPC promises
- Fake setTimeout/clearTimeout + __hsFlushTimers — drain RPC timeout tests synchronously

Plan update: mark E36 WebSocket as DONE (previously "design-done, pending review").

Skipped: loops/hs's tests/playwright/generate-sx-tests.py — architecture's version
is 1468 lines vs loops/hs's 290; arch's is the further-evolved version.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-14 07:26:43 +00:00
parent c560f3d70d
commit 22411f7f80
2 changed files with 20 additions and 1 deletions

View File

@@ -14,6 +14,25 @@ const SX_DIR = path.join(WASM_DIR, 'sx');
eval(fs.readFileSync(path.join(WASM_DIR, 'sx_browser.bc.js'), 'utf8'));
const K = globalThis.SxKernel;
process.on('unhandledRejection', () => {});
let _fakeTimers = [];
let _fakeTimerIdCtr = 0;
const _realSetTimeout = globalThis.setTimeout;
globalThis.setTimeout = function(cb, _delay) {
const id = ++_fakeTimerIdCtr;
_fakeTimers.push({ id, cb });
return id;
};
globalThis.clearTimeout = function(id) {
const idx = _fakeTimers.findIndex(t => t.id === id);
if (idx >= 0) _fakeTimers.splice(idx, 1);
};
globalThis.__hsFlushTimers = { call: function() {
const batch = _fakeTimers.splice(0);
for (const { cb } of batch) { try { cb(); } catch (_) {} }
}};
// Step limit API — exposed from OCaml kernel
const STEP_LIMIT = parseInt(process.env.HS_STEP_LIMIT || '1000000');