pcbjam/tests/apps/standalone/jspi-coroutine/browser-run.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.1 KiB
JavaScript

// Quick browser validation of the jspi-coroutine harness in bundled
// Chromium 143 (JSPI default-on) and Firefox 144 (JSPI behind pref).
// Uses the main checkout's installed Playwright. Proper spec wiring lands in
// tests/jspi/ (Phase 6).
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 DIR = __dirname;
const MIME = { '.html': 'text/html', '.mjs': 'text/javascript', '.js': 'text/javascript', '.wasm': 'application/wasm' };
async function runIn(name, launcher, opts) {
const browser = await launcher.launch(opts);
const page = await browser.newPage();
const lines = [];
page.on('console', (msg) => {
const t = msg.text();
if (t.includes('[JSPI_CORO]') || t.includes('[libctx-jspi]')) lines.push(t);
});
await page.goto(`http://127.0.0.1:${server.address().port}/index.html`);
await page.waitForFunction(
() => performance.now() > 0, // anchor; real wait below
);
const deadline = Date.now() + 30000;
while (Date.now() < deadline && !lines.some((l) => l.includes('SUMMARY'))) {
await new Promise((r) => setTimeout(r, 200));
}
await browser.close();
const summary = lines.find((l) => l.includes('SUMMARY')) ?? 'NO SUMMARY';
const fails = lines.filter((l) => l.includes('FAIL') || l.includes('FATAL'));
console.log(`${name}: ${summary}`);
for (const f of fails) console.log(`${name}: ${f}`);
return summary.includes('failed=0');
}
const server = http.createServer((req, res) => {
const f = path.join(DIR, req.url === '/' ? 'index.html' : req.url);
try {
const body = fs.readFileSync(f);
res.writeHead(200, { 'Content-Type': MIME[path.extname(f)] ?? 'application/octet-stream' });
res.end(body);
} catch {
res.writeHead(404).end();
}
});
server.listen(0, '127.0.0.1', async () => {
let ok = true;
ok = (await runIn('chromium', chromium, {})) && ok;
ok = (await runIn('firefox', firefox, {
firefoxUserPrefs: { 'javascript.options.wasm_js_promise_integration': true },
})) && ok;
server.close();
process.exit(ok ? 0 : 1);
});