The runtime is JSPI-only; this removes everything that still pretended otherwise. Three exhaustive sweeps (C++/JS+build+CI/tests+docs) drove the inventory; every deletion verified by grep closure + full gates. Broken-right-now fixes: - deploy-staging.yml passed the retired opt_level input — the workflow could not even start. Removed. - env.sh carried dead exports with a live -sASYNCIFY=1 inside (WASM_LDFLAGS/PTHREAD_LDFLAGS, zero consumers). Removed; the WASM_LEGACY_EXCEPTIONS rationale rewritten to the real reason. - docker/build.sh exported PCBJAM_ASYNC_BACKEND (read nowhere). Gone. Dead weight removed: - binaryen submodule (nothing builds or invokes it), wasm-opt-bench workflow + scripts/bench/, get-wasm-opt.sh, diagnostics.js (242 lines of Asyncify-API-only code), the KICAD_PIPELINE background-postprocess scaffolding (existed to parallelize the deleted wasm-opt phase; the postprocess is a seconds-long node script and now runs inline), build-monitor's dead asyncify rows, sched-context orphan build output, dead .gitignore entries, the .jspi-assets spike dir (the two wf-result research JSONs moved to docs/features/async/migration-evidence/). - bindings: fiber_park.h + its 12 embind registrations (broken-if- called under JSPI), the kicadOpenFileStart/OPEN_JOB starter route, main_stack_runner.h + 5 includes, the always-null context-sleep weak hook in nanosleep_yield.c. - shim: the backend field (installed-flag idempotency instead), noteContextWait (dead both sides), the __wxAsyncifyDump alias (+ the WasmTool fallback and string-dump normalize branch). - web: the emscripten-6-ignored mainScriptUrlOrBlob option in boot.ts (gerber-demo keeps it: it loads the deployed CDN release, which predates emscripten 6 — noted inline). Conditionals: all 'backend === jspi' checks reduced to scheduler- presence checks; races_quiescent re-keyed from Asyncify.state (vacuous) to real backlog quiescence (resumeReady/mutatorQueue — NOT _windowLive, which is the probing activation's own window by definition). Renames (identifiers only, no file renames): ASYNC_LINK_FLAGS→ JSPI_LINK_FLAGS and Makefile ASYNC_LDFLAGS→JSPI_LDFLAGS, kicadCollabFiberBusy→kicadCollabBusy (embind + web + tests), collab_common.h fiber*→apply*/coroutine naming, asyncifySignatures→ wasmTrapSignatures (lists byte-identical). Tests: the two remaining vacuous [wx-asyncify]/fiber-resume-refused asserts re-keyed to live JSPI beacons; eeschema-load's failure message no longer sends the developer to a deleted script; wait-beacons' dead families/parser deleted; lane-0 legacy-glue guards removed (lane 0 is unconstructible); the embind test.fail re-gated with the JSPI reason (plain embind invokers cannot suspend — verified still failing); lint-determinism now scans tests/jspi (166 files clean); eeschema-collab local-move gated to chromium (~50% flaky on FF even solo; pcbnew twin covers both engines). Docs: DEBUG.md rewritten as the JSPI debugging guide; build.md describes the single-phase build; docs/features/async/README.md banner-marked historical and repointed at the NEW 23-jspi-runtime.md (current architecture: export census, turnstile, libcontext ownership + refusal contract, embind call shapes, the em-pthread service-wrapper trick, exception policy, known gaps). Gates on the cleaned tree: test:e2e 725 passed / 0 failed (after the quiescence-probe fix; the 3 other reds were verified contention flakes solo-green or the documented FF gate), web 76/0, jspi 18/18 both engines, vitest 295/295 + 17/17, all lints green, live-app census clean. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016X9eh1s5sTx1o9Em9KBuwR
211 lines
9.2 KiB
TypeScript
211 lines
9.2 KiB
TypeScript
import { test, expect } from './fixtures';
|
|
import * as path from 'path';
|
|
import { PNG } from 'pngjs';
|
|
import {
|
|
clickByTooltip,
|
|
clickMenuBarItem,
|
|
clickMenuItemByText,
|
|
findByTooltip,
|
|
stableShot,
|
|
waitForEditorReady,
|
|
} from '../e2e/utils/element-tracker';
|
|
import { injectFileIntoMemfs } from './utils/fs-inject';
|
|
|
|
/**
|
|
* eeschema simulator end-to-end (docs/features/ngspice-split/): the historic
|
|
* kill-point was SIMULATOR_FRAME never opening (no dlopen for libngspice);
|
|
* now NGSPICE binds the sharedspice client stub and the engine runs in the
|
|
* lazy ngspice_service worker. These specs drive the REAL UI path:
|
|
* project open → Inspect → Simulator → Run → plot, asserting the RPC/event
|
|
* plumbing (window.__ngspiceEvents / __ngspiceLog from the harness provider,
|
|
* tests/kicad/utils/ngspice-service.ts) and the rendered result.
|
|
*
|
|
* Fixture: the complete kicad demo rectifier project — its 1N4148 lives in a
|
|
* sibling diode.mod pulled in via `.include`, so a passing transient also
|
|
* proves the client stub's netlist file shipping (a missing model fails the
|
|
* run with "unable to find definition of model").
|
|
*/
|
|
|
|
const RECTIFIER_DIR = path.resolve(__dirname, '..', '..',
|
|
'kicad', 'demos', 'simulation', 'rectifier');
|
|
const MEMFS_DIR = '/home/kicad/documents/rectifier';
|
|
const PROJECT_FILES = ['rectifier.kicad_sch', 'rectifier.kicad_pro', 'diode.mod',
|
|
'rectifier_schlib.kicad_sym', 'sym-lib-table', 'rectifier.wbk'];
|
|
|
|
async function loadRectifier(page: import('@playwright/test').Page): Promise<void> {
|
|
for (const f of PROJECT_FILES)
|
|
await injectFileIntoMemfs(page, path.join(RECTIFIER_DIR, f), `${MEMFS_DIR}/${f}`);
|
|
|
|
await page.evaluate((sch: string) => {
|
|
(window as any).Module.kicadOpenFile(sch);
|
|
}, `${MEMFS_DIR}/rectifier.kicad_sch`);
|
|
|
|
await expect
|
|
.poll(async () => page.title(), { timeout: 120000 })
|
|
.toMatch(/rectifier/i);
|
|
}
|
|
|
|
// Open Inspect → Simulator and return the new top-level window's DOM id.
|
|
async function openSimulator(page: import('@playwright/test').Page): Promise<string> {
|
|
const idsBefore = await page.$$eval('#window-container [id^="window-"]',
|
|
(els) => els.map((e) => e.id));
|
|
|
|
expect(await clickMenuBarItem(page, 'Inspect'), 'Inspect menu').toBe(true);
|
|
await clickMenuItemByText(page, 'Simulator');
|
|
|
|
await page.waitForFunction((before: string[]) => {
|
|
const ids = Array.from(
|
|
document.querySelectorAll('#window-container [id^="window-"]'),
|
|
(e) => e.id);
|
|
return ids.some((id) => !before.includes(id));
|
|
}, idsBefore, { timeout: 60000 });
|
|
|
|
const idsAfter = await page.$$eval('#window-container [id^="window-"]',
|
|
(els) => els.map((e) => e.id));
|
|
const simWin = idsAfter.find((id) => !idsBefore.includes(id));
|
|
expect(simWin, 'simulator window appeared').toBeTruthy();
|
|
return simWin!;
|
|
}
|
|
|
|
// Run the loaded workbook's analysis and wait for the background run to
|
|
// finish (the bg 'finished' event lands after ngspice's thread joins).
|
|
async function runSimulation(page: import('@playwright/test').Page): Promise<void> {
|
|
const evtsBefore = await page.evaluate(
|
|
() => (window as any).__ngspiceEvents.length as number);
|
|
|
|
// The simulator window div appears while the frame ctor is still
|
|
// suspended in the init RPC; the toolbar registers its tools only after
|
|
// init completes and the frame first paints. The Run tool's
|
|
// ENABLE(!simRunning) condition is a wxUpdateUIEvent check, and the WASM
|
|
// port only reliably re-evaluates those when input events pump the loop —
|
|
// after a run finishes, the last input was the click that started it, so
|
|
// nudge the mouse each poll or the toolbar can hold its stale
|
|
// "running" state forever.
|
|
await expect
|
|
.poll(async () => {
|
|
await page.mouse.move(4, 4);
|
|
await page.mouse.move(8, 8);
|
|
const el = await findByTooltip(page, 'Run Simulation', { elementType: 'tool' });
|
|
return !!el && el.enabled;
|
|
}, { timeout: 60000 })
|
|
.toBe(true);
|
|
|
|
expect(await clickByTooltip(page, 'Run Simulation', { elementType: 'tool' }),
|
|
'Run tool').toBe(true);
|
|
|
|
await page.waitForFunction((n: number) => {
|
|
const evts = (window as any).__ngspiceEvents as Array<{ kind: string; finished?: boolean }>;
|
|
return evts.slice(n).some((e) => e.kind === 'bg' && e.finished === true);
|
|
}, evtsBefore, { timeout: 120000 });
|
|
}
|
|
|
|
function distinctColors(png: PNG): number {
|
|
const colors = new Set<number>();
|
|
// 8x8 grid sampling, same spirit as the 3d-viewer render check.
|
|
const stepX = Math.max(1, Math.floor(png.width / 8));
|
|
const stepY = Math.max(1, Math.floor(png.height / 8));
|
|
|
|
for (let y = 0; y < png.height; y += stepY) {
|
|
for (let x = 0; x < png.width; x += stepX) {
|
|
const i = (png.width * y + x) << 2;
|
|
colors.add((png.data[i] << 16) | (png.data[i + 1] << 8) | png.data[i + 2]);
|
|
}
|
|
}
|
|
return colors.size;
|
|
}
|
|
|
|
test.describe('eeschema simulator', () => {
|
|
test.describe.configure({ mode: 'serial' });
|
|
test.setTimeout(300000);
|
|
|
|
test('Inspect → Simulator opens the frame; service fetches lazily', async ({ page, testLogger }) => {
|
|
const ngspiceFetches: string[] = [];
|
|
page.on('request', (r) => {
|
|
if (r.url().includes('ngspice_service')) ngspiceFetches.push(r.url());
|
|
});
|
|
|
|
await page.goto('/kicad/eeschema.html');
|
|
await waitForEditorReady(page);
|
|
await loadRectifier(page);
|
|
|
|
expect(ngspiceFetches,
|
|
'ngspice_service must NOT be fetched before the simulator opens')
|
|
.toHaveLength(0);
|
|
|
|
await openSimulator(page);
|
|
await stableShot(page, 'eeschema-sim-frame.png');
|
|
|
|
// NGSPICE::init_dll ran inside the frame ctor → the client stub's init
|
|
// RPC booted the worker.
|
|
expect(ngspiceFetches.length,
|
|
'ngspice_service fetched lazily by the simulator open')
|
|
.toBeGreaterThan(0);
|
|
|
|
const all = [...testLogger.consoleLogs, ...testLogger.errors];
|
|
expect(all.filter((l) => l.includes('Aborted(')), 'no aborts').toHaveLength(0);
|
|
});
|
|
|
|
test('transient run: live console stream, vectors reach the plot, plot renders', async ({ page, testLogger }) => {
|
|
await page.goto('/kicad/eeschema.html');
|
|
await waitForEditorReady(page);
|
|
await loadRectifier(page);
|
|
const simWin = await openSimulator(page);
|
|
|
|
await runSimulation(page);
|
|
|
|
const evts = await page.evaluate(() => (window as any).__ngspiceEvents as Array<{
|
|
kind: string; lines?: string[]; finished?: boolean; t: number }>);
|
|
|
|
// Live streaming: console/status output must precede the finish event.
|
|
const finishT = evts.filter((e) => e.kind === 'bg' && e.finished).map((e) => e.t)[0];
|
|
const streamed = evts.filter(
|
|
(e) => (e.kind === 'char' || e.kind === 'stat') && e.t <= finishT);
|
|
expect(streamed.length, 'ngspice output streamed during the run')
|
|
.toBeGreaterThan(3);
|
|
|
|
// The model shipped via .include resolved (a miss fails the run with
|
|
// "unable to find definition" and produces no transient).
|
|
const charText = evts.flatMap((e) => e.lines ?? []).join('\n');
|
|
expect(charText, 'no missing-model errors').not.toMatch(/unable to find definition/i);
|
|
|
|
// The plot pulled real vector data through get_vec_info.
|
|
const vecPulls = await page.evaluate(() =>
|
|
((window as any).__ngspiceLog as Array<{ kind: string; length?: number }>)
|
|
.filter((l) => l.kind === 'get_vec_info' && (l.length ?? 0) > 100).length);
|
|
expect(vecPulls, 'plot fetched transient vectors').toBeGreaterThan(0);
|
|
|
|
// The plot area rendered something beyond a flat background.
|
|
const shot = await page.locator(`#${simWin}`).screenshot({
|
|
scale: 'css', animations: 'disabled' });
|
|
const png = PNG.sync.read(shot);
|
|
expect(distinctColors(png), 'plot window shows structure (axes/trace)')
|
|
.toBeGreaterThan(6);
|
|
|
|
await stableShot(page, 'eeschema-sim-plot.png');
|
|
|
|
const all = [...testLogger.consoleLogs, ...testLogger.errors];
|
|
expect(all.filter((l) => l.includes('Aborted(')), 'no aborts').toHaveLength(0);
|
|
const corruption = all.filter((l) =>
|
|
l.includes('index out of bounds') || l.includes('indirect call to null')
|
|
|| l.includes('uncaught exception: unwind'));
|
|
expect(corruption, 'no wasm trap').toHaveLength(0);
|
|
});
|
|
|
|
test('a second run after the first succeeds (engine reset path)', async ({ page, testLogger }) => {
|
|
await page.goto('/kicad/eeschema.html');
|
|
await waitForEditorReady(page);
|
|
await loadRectifier(page);
|
|
await openSimulator(page);
|
|
|
|
await runSimulation(page);
|
|
await runSimulation(page);
|
|
|
|
const finishCount = await page.evaluate(() =>
|
|
((window as any).__ngspiceEvents as Array<{ kind: string; finished?: boolean }>)
|
|
.filter((e) => e.kind === 'bg' && e.finished === true).length);
|
|
expect(finishCount, 'two completed runs').toBeGreaterThanOrEqual(2);
|
|
|
|
const all = [...testLogger.consoleLogs, ...testLogger.errors];
|
|
expect(all.filter((l) => l.includes('Aborted(')), 'no aborts').toHaveLength(0);
|
|
});
|
|
});
|