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
This commit is contained in:
Viktor Vaczi 2026-08-13 07:06:24 +02:00
commit 3f09a46ff5
48 changed files with 2640 additions and 546 deletions

View file

@ -101,21 +101,32 @@ const CHROMIUM_CI_ARGS = process.env.CI
}
: {};
// CI-only Firefox prefs: GPU-less CI VMs can't create a headless GL context
// (FEATURE_FAILURE_WEBGL_EXHAUSTED_DRIVERS) — run headed under Xvfb, where
// GLX + Mesa llvmpipe provides software WebGL, and bypass the no-GPU
// blocklist so the GAL canvas gets a context. CI invokes the suite via
// `xvfb-run`.
// Firefox prefs. JSPI (the wasm suspension mechanism, experiment/jspi) is
// default-on only in Firefox >=153; the bundled 144 needs the pref — set it
// UNCONDITIONALLY (a previous CI-gated blob left local runs without it).
// CI additionally runs headed under Xvfb with software-WebGL forced: GPU-less
// CI VMs can't create a headless GL context
// (FEATURE_FAILURE_WEBGL_EXHAUSTED_DRIVERS); CI invokes the suite via
// `xvfb-run`. NOTE: spreads REPLACE launchOptions wholesale — this must stay
// the single composed object, never two competing spreads.
const FIREFOX_PREFS_ALWAYS = {
'javascript.options.wasm_js_promise_integration': true,
};
const FIREFOX_CI_OPTS = process.env.CI
? {
headless: false,
launchOptions: {
firefoxUserPrefs: {
...FIREFOX_PREFS_ALWAYS,
'webgl.force-enabled': true,
},
},
}
: {};
: {
launchOptions: {
firefoxUserPrefs: { ...FIREFOX_PREFS_ALWAYS },
},
};
export default defineConfig({
globalSetup: './global-setup.ts',
@ -184,12 +195,14 @@ export default defineConfig({
},
},
{
// Asyncify-layer harnesses: the race-condition red-green battery and
// the Design-B scheduler-context gate. One heavy WASM app at a time.
// Matches EVERY spec in ./asyncify — a new harness here is covered by
// construction rather than by remembering to widen this pattern.
name: 'asyncify-firefox',
testDir: './asyncify',
// JSPI-layer harnesses: the shadow-stack red/green battery, the
// coroutine-backend contract battery, and the semantic suspension-race
// scenarios (successor of the retired ./asyncify suite). One heavy
// WASM app at a time. Matches EVERY spec in ./jspi — a new harness
// here is covered by construction rather than by remembering to widen
// this pattern.
name: 'jspi-firefox',
testDir: './jspi',
testMatch: /\.spec\.ts$/,
fullyParallel: false,
timeout: 120000,
@ -243,9 +256,13 @@ export default defineConfig({
},
},
{
name: 'asyncify-chrome',
testDir: './asyncify',
testMatch: /asyncify-races.*\.spec\.ts$/,
// System Chrome (real V8/GPU) leg of the jspi harnesses. There is no
// WebKit leg anymore: Safari has no JSPI at all (accepted trade-off of
// the migration) — the retired asyncify-webkit project had no
// successor to rename into.
name: 'jspi-chrome',
testDir: './jspi',
testMatch: /\.spec\.ts$/,
fullyParallel: false,
timeout: 120000,
use: {
@ -254,19 +271,6 @@ export default defineConfig({
permissions: ['clipboard-read', 'clipboard-write'],
},
},
{
// WebKit (Safari's engine) — project policy: every asyncify spec must be
// green in all three engines. Run via npm run test:asyncify:safari.
name: 'asyncify-webkit',
testDir: './asyncify',
testMatch: /asyncify-races.*\.spec\.ts$/,
fullyParallel: false,
timeout: 120000,
use: {
...devices['Desktop Safari'],
viewport: { width: 1280, height: 720 },
},
},
{
// Coroutine harness on system Chrome (real V8/GPU — where the KiCad
// coroutine crash historically manifested). Must be --headed on ARM Mac.