pcbjam/tests/kicad/frame-runtime.spec.ts
Istvan Matejcsok bbeef6d20e feat(wasm): kicad_editor — merge the pcbnew+eeschema kifaces into ONE bundle (Part 2)
All four editors (PCB / Footprint / Schematic / Symbol) are now runtime --frame
choices of a single kicad_editor.wasm (178 MB at -O1 vs 147+82 separate; shared
wx/common/boost linked once). One editor per page load, as before; frames pcb /
fpedit / sch / symedit.

- wasm/editor/: the merged executable target (single_top + both kiface library sets,
  whole-archive pcbcommon) + the safety-net focus-walk Kiface() dispatch TU. Gated by
  KICAD_WASM_MERGED_EDITOR (kicad submodule bump carries the fork side: per-engine
  Kiface/getter binding + ODR renames + dual-kiface launcher).
- wasm/bindings/: per-editor collab entries renamed pcbCollab*/schCollab* (JS names
  unchanged); duplicate kicadOpenFile/kicadCollabOnSave + shared-name registrations
  guarded behind KICAD_MERGED_EMBIND; new kicad_editor_embind.cpp registers each
  shared JS name once, dispatching on the live frame.
- Build: kicad_editor app (build wrapper, target case arms, 3-object embind compile
  with the ABI-critical flags, STUB_APP=pcbnew); docker/build.sh "all" =
  kicad_editor calculator pl_editor gerbview (pcbnew/eeschema stay as explicit debug
  apps); scripts/kicad/audit-merged-symbols.sh = repeatable ODR-collision audit (run
  on kicad bumps).
- Frontend: Bundle type (bundle ≠ tool); TOOL_BUNDLE maps all four editors to
  kicad_editor; explicit --frame tokens for pcbnew (pcb) and eeschema (sch); publish
  list = the 4 real bundles.
- Tests/CI: five harnesses load kicad_editor.js with explicit frame tokens;
  PCBNEW_FAMILY_SPECS renamed BIG_MODULE_SPECS + the 8 eeschema-family specs (they
  now boot the merged module — SpiderMonkey x86 CI OOM routing); frame-runtime spec
  covers all four frames from the one bundle.

Validated so far: frame-runtime 4/4 (each frame boots with the right title, no
aborts, no duplicate embind registration); 24-spec merged-module regression green;
3D raytracer renders. Known pre-existing failure: 3d-viewer title-bar drag deadlock,
fixed on main by 7630c7e (2N+8 pthread pre-warm) — picked up by the follow-up rebase.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-02 17:56:02 +02:00

81 lines
3.3 KiB
TypeScript

import { test, expect } from '@playwright/test';
/**
* Editor-unification runtime-frame validation.
*
* Since Part 2 ALL FOUR editors are served by the ONE merged kicad_editor bundle
* (pcbnew + eeschema kifaces statically linked): each harness loads kicad_editor.js
* with its frame token in Module.arguments —
* - PCB Editor --frame=pcb (also the bundle's build-time default)
* - Footprint Editor --frame=fpedit
* - Schematic Editor --frame=sch
* - Symbol Editor --frame=symedit
* parsed in kicad/common/single_top.cpp (mirroring kicad/kicad.cpp's --frame parser).
*
* This asserts the decisive fact the launch-smoke specs don't: that the merged
* bundle actually opens the REQUESTED frame. The window title is the discriminator —
* a dropped/ignored token would land on the build default ("PCB Editor") or a
* sibling editor's title.
*/
interface FrameCase {
harness: string;
/** title the requested editor frame settles on */
titleRe: RegExp;
/** any OTHER editor's title — must NOT appear (would mean --frame went wrong) */
wrongRe: RegExp;
}
const CASES: FrameCase[] = [
{ harness: 'pcbnew.html',
titleRe: /PCB Editor/i,
wrongRe: /Schematic Editor|Symbol Editor|Footprint Editor/i },
{ harness: 'footprint_editor.html',
titleRe: /Footprint Editor/i,
wrongRe: /PCB Editor|Schematic Editor|Symbol Editor/i },
{ harness: 'eeschema.html',
titleRe: /Schematic Editor/i,
wrongRe: /PCB Editor|Footprint Editor|Symbol Editor/i },
{ harness: 'symbol_editor.html',
titleRe: /Symbol Editor/i,
wrongRe: /PCB Editor|Schematic Editor|Footprint Editor/i },
];
test.describe('editor-unification runtime frame (--frame)', () => {
for (const tc of CASES) {
test(`${tc.harness} opens its editor frame from the merged bundle`, async ({ page }) => {
const consoleLines: string[] = [];
page.on('console', (m) => consoleLines.push(m.text()));
page.on('pageerror', (e) => consoleLines.push(`pageerror: ${e.message}`));
await page.goto(`/kicad/${tc.harness}`);
// The runtime came up.
await expect(page.locator('#canvas')).toBeVisible({ timeout: 120000 });
// The frame sets the document title once it is up; poll until it settles.
await expect
.poll(() => page.title(), {
message: `${tc.harness}: never reached the expected editor title`,
timeout: 120000,
intervals: [1000],
})
.toMatch(tc.titleRe);
const title = await page.title();
// eslint-disable-next-line no-console
console.log(`[frame-runtime] ${tc.harness} -> title=${JSON.stringify(title)}`);
// The runtime --frame flag actually selected the right frame: no sibling
// editor's title.
expect(title, `${tc.harness}: opened the requested editor, not a sibling`).not.toMatch(tc.wrongRe);
// No WASM abort during load — and no duplicate embind registration (the
// merged dispatcher must register each shared JS name exactly once).
const aborted = consoleLines.some((l) => /Aborted\(|Cannot register public name/.test(l));
expect(aborted, 'no WASM abort / duplicate embind registration during load').toBe(false);
await page.screenshot({ path: `test-results/frame-runtime-${tc.harness}.png`, scale: 'device' });
});
}
});