pcbjam/tests/jspi/jspi-coroutine.spec.ts

55 lines
2.3 KiB
TypeScript
Raw Normal View History

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
import { test, expect } from '../e2e/utils/fixtures';
// Contract battery for the JSPI libcontext coroutine backend
// (kicad/thirdparty/libcontext/libcontext.cpp under PCBJAM_JSPI). The harness
// (tests/apps/standalone/jspi-coroutine) is a wx-free MiniCoro that mirrors
// tool/coroutine.h's protocol exactly — INVOCATION_ARGS, callerStub with the
// finish_fcontext hook, jumpIn/jumpOut, CONTINUE_AFTER_ROOT — over the real
// libcontext.cpp. 15 cases: create/run/finish, yield chains, nested
// call-in-call routed by enterer inference, RunMainStack payload propagation,
// ghost-resume refusal (dead tombstones), mid-body release census.
//
// Output contract: per-case "[JSPI_CORO] CASE <name> PASS|FAIL" then
// "[JSPI_CORO] SUMMARY passed=<n> failed=<n>".
const EXPECTED_PASSES = 15;
function findSummary(logs: string[]) {
return logs.find((l) => l.includes('[JSPI_CORO] SUMMARY'));
}
function assertSummary(logs: string[]) {
const summary = findSummary(logs)!;
const match = summary.match(/passed=(\d+)\s+failed=(\d+)/);
expect(match, `summary parseable: ${summary}`).not.toBeNull();
expect(Number(match![1]), 'all cases pass').toBe(EXPECTED_PASSES);
expect(Number(match![2]), 'no case fails').toBe(0);
const fails = logs.filter((l) => l.includes('[JSPI_CORO] CASE') && l.includes('FAIL'));
expect(fails, `FAIL cases: ${fails.join(' || ')}`).toHaveLength(0);
const fatal = logs.filter((l) => l.includes('[JSPI_CORO] FATAL'));
expect(fatal, `harness fatal: ${fatal.join(' || ')}`).toHaveLength(0);
}
test.describe('JSPI coroutine backend contract battery', () => {
test('single-thread build: 15/15 protocol cases pass', async ({ page, testLogger }) => {
await page.goto('/standalone/jspi-coroutine/');
await expect
.poll(() => findSummary(testLogger.consoleLogs) ?? null, {
timeout: 60000,
message: 'harness should emit its SUMMARY line',
})
.not.toBeNull();
assertSummary(testLogger.consoleLogs);
});
test('pthread build: 15/15 protocol cases pass', async ({ page, testLogger }) => {
await page.goto('/standalone/jspi-coroutine/?pt=1');
await expect
.poll(() => findSummary(testLogger.consoleLogs) ?? null, {
timeout: 60000,
message: 'pthread harness should emit its SUMMARY line',
})
.not.toBeNull();
assertSummary(testLogger.consoleLogs);
});
});