pcbjam/tests/apps/standalone/jspi-coroutine/boot-check.cjs
Viktor Vaczi 3f09a46ff5 jspi: migration phases 0-7 — build knob, scheduler shim, test successor suite
Toolchain: emsdk 6.0.6 (versions.sh; cache-hash keys on it). Build knob
PCBJAM_ASYNC_BACKEND=jspi|asyncify: build-kicad-target.sh links editors with
-sJSPI + -sJSPI_EXPORTS=@scripts/common/jspi-exports.txt + --pre-js
jspi-scheduler.js (no DYNCALLS, no post-link asyncify pipeline); wx build
stamps the backend and forces clean on flip or unknown provenance;
docker/build.sh passes the knob, seeds the emscripten ports cache from the
volume every launch, jspi postprocess = patch-env-shim only.

scripts/common/shims/jspi-scheduler.js: the JSPI successor scheduler —
token-wait registry, resume turnstile (one armed resume between engine
re-entries, SP swaps only at microtask boundaries), green-region spill
stacks (16-aligned tops), S1 embind mutator FIFO lane + parker wraps, S6
shutdown, libctx integration hooks (suspend/end/quarantine + g_current
arm/clear), SuspendError attributor, lost-wake + stuck-window watchdogs,
__wxWaitDump observability.

Embind: PARKER registrations get emscripten::async() under PCBJAM_JSPI
(wasm/bindings/pcbjam_async_policy.h). nanosleep yields route via the shim.

Tests: tests/asyncify -> tests/jspi successor suite (jspi-stack red/green
shadow-stack battery, jspi-coroutine MiniCoro harness, suspend-races
semantic scenarios + __wxWaitDump books coherence); projects jspi-firefox/
jspi-chrome (asyncify-webkit retired — no JSPI in WebKit); unconditional
Firefox JSPI pref; guard-beacons -> wait-beacons (+wxScheduler/libctxJspi
families); Makefile.wasm links test apps against JSPI with the shim as a
tracked link prerequisite.

Web: WasmTool setRo await + __wxWaitDump forensics, open-flow contained
promise, scheduler-shim.test.ts retargeted (8 green).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NDeBaKKhQztd8KiVtHuyXr
2026-08-13 07:06:24 +02:00

58 lines
2.5 KiB
JavaScript

// Boot-check a built wx test app under JSPI in bundled Chromium (+ optionally
// Firefox with the pref). Usage: node boot-check.cjs <app.html> [firefox]
const path = require('path');
const http = require('http');
const fs = require('fs');
const PW = '/Users/V/IdeaProjects/pcbjam-private/pcbjam/tests/node_modules/playwright';
const { chromium, firefox } = require(PW);
const APPS = '/Users/V/IdeaProjects/kicad-wasm-jspi/tests/apps';
const page_url = process.argv[2] || 'minimal_test.html';
const useFirefox = process.argv[3] === 'firefox';
const MIME = { '.html': 'text/html', '.mjs': 'text/javascript', '.js': 'text/javascript', '.wasm': 'application/wasm', '.data': 'application/octet-stream' };
const server = http.createServer((req, res) => {
const f = path.join(APPS, decodeURIComponent(req.url.split('?')[0]));
try {
const body = fs.readFileSync(f);
res.writeHead(200, {
'Content-Type': MIME[path.extname(f)] ?? 'application/octet-stream',
'Cross-Origin-Opener-Policy': 'same-origin',
'Cross-Origin-Embedder-Policy': 'require-corp',
});
res.end(body);
} catch {
res.writeHead(404).end();
}
});
server.listen(0, '127.0.0.1', async () => {
const launcher = useFirefox ? firefox : chromium;
const opts = useFirefox
? { firefoxUserPrefs: { 'javascript.options.wasm_js_promise_integration': true } }
: {};
const browser = await launcher.launch(opts);
const page = await browser.newPage();
const lines = [];
page.on('console', (m) => lines.push(m.text()));
page.on('pageerror', (e) => lines.push('PAGEERROR: ' + e.message));
await page.goto(`http://127.0.0.1:${server.address().port}/${page_url}`);
await new Promise((r) => setTimeout(r, 12000));
// Probe scheduler state + DOM
const probe = await page.evaluate(() => ({
scheduler: globalThis.__wxScheduler ? globalThis.__wxScheduler.backend : null,
dump: globalThis.__wxWaitDump ? globalThis.__wxWaitDump() : null,
windows: document.querySelectorAll('.wx-window, [id^=wx]').length,
bodyChildren: document.body.children.length,
})).catch((e) => ({ error: String(e) }));
await browser.close();
server.close();
console.log('=== console (last 30) ===');
for (const l of lines.slice(-30)) console.log(l);
console.log('=== probe ===');
console.log(JSON.stringify(probe, null, 1));
const bad = lines.filter((l) => /PAGEERROR|SuspendError|RuntimeError|abort/i.test(l));
console.log(bad.length ? 'BOOT: ERRORS(' + bad.length + ')' : 'BOOT: CLEAN');
});