pcbjam/tests/kicad/presence-locks-pcbnew.spec.ts
Viktor Vaczi 63ed1f3c1f e2e/CI: dual-engine suites, per-engine screenshots, SwiftShader retired, prod web suite, CI-coverage gate
Squash of experiment/ff-big-modules vs main.

Big-module routing removed: native-EH shrank kicad_editor below
SpiderMonkey's x86-64 code budget (runs 29355049705/29356152413 green on
stock Firefox), so BIG_MODULE_SPECS routing and the baseline-only-JIT
crutch are gone — kicad-firefox and kicad-chromium both run the full
suite, with the module compiled the way real users' browsers compile it.

Per-engine screenshots end to end: stableShot/shotPath write
test-results/<engine>/<name>.png; baselines move to
baseline-screenshots/{chromium,firefox}/ and the whole tools/screenshots
pipeline (compare/promote/manifest/spec-map/changelog/Discord) keys on
<engine>/<name>. Previously Firefox and Chromium renders of one spec
overwrote each other and Firefox renders were never actually gated.
Seeded from CI run 29421380806 (92 new firefox baselines, +24 chromium
web-suite shots); manifest generated from the baseline tree.

One merged playwright.config.ts (kicad/asyncify/coroutine/perf as
projects); ~25 dead npm scripts dropped. The web suite is gated in CI for
the first time ever (4 rotted specs fixed, 5 broken lib-bridge specs
triaged as fixme in docs/features/web-e2e-rot/); cheap lint step after
npm ci; last 26 blind-sleep violations fixed.

SwiftShader retired: CI Chromium renders WebGL on ANGLE → Mesa llvmpipe
(--use-gl=angle --use-angle=gl --ignore-gpu-blocklist; the blocklist flag
is mandatory — llvmpipe is blocklisted and WebGL is silently unavailable
without it) in BOTH configs. Under WORKERS=4 congestion SwiftShader
transiently failed the first post-board-load draw and the recovery
cascade ended in a silent permanent Cairo fallback — that engine flip was
the "~1.2% changedRatio both directions" occ-export baseline flake.
Validated 160/160 across two 80-repeat rigs; full analysis in
docs/features/wx-parity-bugs/occ-export-context-eviction.md. Chromium
baselines shift slightly on llvmpipe — promote once from the first green
run. Deflakes the new coverage exposed: presence baselines settle before
capture; presence fixtures declare current file formats; perf gets its
own outputDir so CI evidence survives; occ-export settles the board paint
before the export dialog; menu-item waits (waitForRenderedByLabel before
clickMenuItem) in 4 specs + the TESTING.md rule.

Web suite runs the PROD build, in parallel: webServer becomes backend
`start` + the standalone's e2e:preview (build-preview.mjs: link-wasm →
stash the public/wasm symlink aside during vite build, build-demo.mjs's
move — then vite preview as the persistent server). The wasm middleware
serves /wasm/* in preview and emits COOP/COEP/CORP itself (a pthread
worker script's own response must carry COEP or Chrome kills it with
ERR_BLOCKED_BY_RESPONSE). VITE_* flags bake at build time;
VITE_ALLOW_USER_OVERRIDE joins turbo globalEnv. fullyParallel + default
workers: 5.2m → 1.4m. Determinism fixes the parallel run exposed:
shared-page specs become serial groups; locks.spec grabs alice's exact
item via the new kicadCollabTestSelectByUuid hook (cross-tab "first
footprint" order is not a ysync invariant); quit specs poll page.url()
(quit supersedes its own navigation — NS_BINDING_ABORTED on Firefox).
Suite: 51 passed / 12 skipped / 0 failed in 1.6m.

CI-coverage gate (lint:ci-coverage): every tests/**/*.spec.ts must be
reachable from the npm scripts the workflows invoke — scraped from
.github/workflows/, resolved through package.json, coverage asked from
playwright --list itself. Rules: uncovered-spec + orphan-project (with a
documented LOCAL_ONLY_PROJECTS allowlist). Gating next to
lint:determinism; 138 spec files / 13 projects accounted for.

Product fixes kept from the investigations (reachable on real GPUs too):
wx 7799fd1be5 — paint flags clear before dispatch + Invalidate always
propagates; kicad 3dcfea5e45 — SwiftShader pass-boundary flush +
per-instance font texture + first-frame GL-error drain (GAL recovery
recovers instead of falling back to Cairo) + the user-facing eeschema
switch navigates again under __EMSCRIPTEN__ (project-sync's
FaceRegistered gate had rerouted it into the hidden sync player; caught
by the newly-gated web suite).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018eUxiPApHgGiu9NFyQfhAq
2026-07-17 12:21:54 +02:00

334 lines
11 KiB
TypeScript

import type { Page } from "@playwright/test";
import { test, expect } from "./fixtures";
/**
* pcbnew selection soft-locks — C++ veto e2e (collab-presence 0007).
*
* Seeds the remote lock set directly via kicadCollabSetRemote (`locks` field)
* and drives REAL input against it:
* - a drag-move gesture starting on a locked footprint must not move it
* (selectPoint's aOnDrag strip + the move request filter), while the SAME
* gesture moves it once the lock clears (the control that proves the
* gesture itself works);
* - plain selection of a locked item stays possible (inspection semantics);
* - kicadCollabReleaseSelection unselects exactly the contested uuids
* (the tiebreak-loser path), leaving the rest selected;
* - kicadCollabTestGetLocked mirrors the seeded set.
*
* The awareness/tiebreak loop lives in TS (unit-tested) and in the two-tab
* tests/web/locks.spec.ts.
*/
const SEG1 = "44444444-0000-0000-0000-000000000001";
const FP1 = "66666666-0000-0000-0000-000000000001";
const SAMPLE_PCB = `(kicad_pcb
\t(version 20241229)
\t(generator "pcbnew")
\t(generator_version "9.0")
\t(general
\t\t(thickness 1.6)
\t)
\t(paper "A4")
\t(layers
\t\t(0 "F.Cu" signal)
\t\t(2 "B.Cu" signal)
\t\t(37 "F.SilkS" user)
\t\t(25 "Edge.Cuts" user)
\t)
\t(setup)
\t(net 0 "")
\t(footprint "TestLib:R"
\t\t(layer "F.Cu")
\t\t(uuid "${FP1}")
\t\t(at 100 100)
\t\t(attr smd)
\t\t(fp_rect (start -2 -2) (end 2 2) (layer "F.SilkS") (stroke (width 0.3) (type solid)) (uuid "66666666-0000-0000-0000-0000000000cc"))
\t\t(pad "1" smd rect
\t\t\t(at 0 0)
\t\t\t(size 3 3)
\t\t\t(layers "F.Cu")
\t\t\t(uuid "66666666-0000-0000-0000-0000000000dd")
\t\t)
\t)
\t(segment (start 50.8 50.8) (end 101.6 50.8) (width 0.2) (layer "F.Cu") (net 0) (uuid "${SEG1}"))
)
`;
type FS = { mkdirTree(p: string): void; writeFile(p: string, d: string): void };
type Mod = {
kicadOpenFile(p: string): unknown;
kicadCollabPresenceStart(): void;
kicadCollabSetRemote(j: string): void;
kicadCollabGetViewport(): string;
kicadCollabGetSelection(): string;
kicadCollabGetPos(id: string): string;
kicadCollabReleaseSelection(uuidsJson: string, holder: string): void;
kicadCollabTestGetLocked(): string;
kicadCollabTestSelectComponent(): string;
kicadCollabTestSelectFirst(): string;
kicadCollabTestClearSelection(): boolean;
};
type LocksWindow = {
FS: FS;
Module: Mod;
kicadCollab?: Record<string, unknown>;
};
function hasAbort(l: { consoleLogs: string[]; errors: string[] }): boolean {
return [...l.consoleLogs, ...l.errors].some((s) => s.includes("Aborted("));
}
async function bootAndOpen(page: Page): Promise<void> {
await page.goto("/kicad/pcbnew-collab.html");
await expect(page.locator("#canvas")).toBeVisible({ timeout: 90000 });
await page.waitForFunction(() => !!window.wxElementRegistry, null, { timeout: 90000 });
await page.waitForFunction(
() => {
const m = (window as unknown as { Module?: Partial<Mod> }).Module;
return (
typeof m?.kicadOpenFile === "function" &&
typeof m?.kicadCollabTestGetLocked === "function"
);
},
null,
{ timeout: 90000 },
);
await page.waitForFunction(
() =>
!!window.wxElementRegistry &&
window.wxElementRegistry
.findAll({ visible: true })
.some((e) => /Frame$/.test(e.typeName) || (e.name || "").endsWith("Frame")),
null,
{ timeout: 90000 },
);
await page.evaluate(
({ content }) => {
const w = window as unknown as LocksWindow;
const dir = "/home/kicad/documents";
try {
w.FS.mkdirTree(dir);
} catch {
/* exists */
}
const p = `${dir}/locks.kicad_pcb`;
w.FS.writeFile(p, content);
w.Module.kicadOpenFile(p);
},
{ content: SAMPLE_PCB },
);
await expect
.poll(() => page.title(), { timeout: 60000, intervals: [500] })
.toMatch(/locks/i);
await page.evaluate(() => {
(window as unknown as LocksWindow).Module.kicadCollabPresenceStart();
});
}
/** Seed (or clear) the remote lock set for FP1. */
function setLock(page: Page, locked: boolean): Promise<void> {
return page.evaluate(
({ fp, locked: isLocked }) => {
const w = window as unknown as LocksWindow;
w.Module.kicadCollabSetRemote(
JSON.stringify({
peers: [],
locks: isLocked ? [{ uuid: fp, name: "bob" }] : [],
}),
);
},
{ fp: FP1, locked },
);
}
/** The footprint's current screen position via the exported GAL transform. */
async function fpScreenPos(page: Page): Promise<{ x: number; y: number }> {
const glId = await page.evaluate(() => {
const visible = Array.from(document.querySelectorAll('[id^="glcanvas-"]'))
.map((c) => c as HTMLCanvasElement)
.find(
(c) =>
window.getComputedStyle(c).display !== "none" &&
c.getBoundingClientRect().width > 0,
);
return visible?.id ?? null;
});
expect(glId).toBeTruthy();
const box = await page.locator(`#${glId}`).boundingBox();
expect(box).toBeTruthy();
const { vp, pos } = await page.evaluate(() => {
const w = window as unknown as LocksWindow;
return {
vp: JSON.parse(w.Module.kicadCollabGetViewport()),
pos: w.Module.kicadCollabGetPos("66666666-0000-0000-0000-000000000001"),
};
});
const [wx, wy] = pos.split(",").map(Number);
return {
x: box!.x + (wx - vp.cx) * vp.scale + vp.w / 2,
y: box!.y + (wy - vp.cy) * vp.scale + vp.h / 2,
};
}
const fpPos = (page: Page) =>
page.evaluate(() =>
(window as unknown as LocksWindow).Module.kicadCollabGetPos(
"66666666-0000-0000-0000-000000000001",
),
);
/**
* The real pcbnew move flow: click-select the footprint, then the `M` hotkey
* (pcbnew's default LEFT-DRAG gesture is rubber-band select, not move — the
* eeschema spec covers the drag-gesture path where dragging DOES move).
* `M` routes through EDIT_TOOL::Move → RequestSelection → the locked-items
* client filter — exactly the veto under test. The drop is a click at the
* offset position.
*/
async function moveViaHotkey(page: Page): Promise<void> {
const at = await fpScreenPos(page);
await page.mouse.click(at.x, at.y); // select (allowed — inspection semantics)
// The click routes through the real selection tool — wait for the selection to
// actually land before arming the move (the bridge getter is the observable).
// Depending on zoom the hit lands the footprint OR its pad — either is fine:
// EDIT_TOOL::Move on a board pad substitutes the parent footprint anyway.
await expect
.poll(
() =>
page.evaluate(
() =>
JSON.parse((window as unknown as LocksWindow).Module.kicadCollabGetSelection())
.length,
),
{ timeout: 10000, message: "click never landed a selection" },
)
.toBeGreaterThan(0);
await page.mouse.move(at.x, at.y);
await page.keyboard.press("m");
// Move-tool arming has no JS-observable (and in the locked case the request is
// vetoed before any state changes — silence IS the expected outcome).
await page.waitForTimeout(500); // eslint-disable-line -- documented interaction dwell: tool arming
await page.mouse.move(at.x + 120, at.y + 80, { steps: 10 });
await page.mouse.click(at.x + 120, at.y + 80); // drop (no-op if move never started)
// Bounded chance for a wrongful move to surface before the caller's negative
// position assert; the unlocked control leg proves the gesture via its own poll.
await page.waitForTimeout(800); // eslint-disable-line -- documented interaction dwell: negative-assert window
await page.keyboard.press("Escape"); // leave no half-open tool between phases
await page.waitForTimeout(300); // eslint-disable-line -- documented interaction dwell: tool teardown
}
test("seeded locks are probeable and a locked footprint resists a real move", async ({
page,
testLogger,
}) => {
test.setTimeout(240000);
await bootAndOpen(page);
await setLock(page, true);
await expect
.poll(() =>
page.evaluate(() =>
JSON.parse((window as unknown as LocksWindow).Module.kicadCollabTestGetLocked()),
),
)
.toEqual([{ uuid: FP1, name: "bob" }]);
// Veto: select + M + drop must leave the locked footprint in place.
const before = await fpPos(page);
expect(before).toBeTruthy();
await moveViaHotkey(page);
expect(await fpPos(page)).toBe(before);
// Control: the SAME flow moves it once the lock clears — proving the veto
// (not a broken gesture) kept it in place above.
await setLock(page, false);
await expect
.poll(() =>
page.evaluate(() =>
JSON.parse((window as unknown as LocksWindow).Module.kicadCollabTestGetLocked()),
),
)
.toEqual([]);
await moveViaHotkey(page);
await expect
.poll(() => fpPos(page), {
timeout: 10000,
message: "control move never moved the unlocked footprint",
})
.not.toBe(before);
expect(hasAbort(testLogger)).toBe(false);
});
test("a locked item stays selectable for inspection", async ({ page, testLogger }) => {
test.setTimeout(240000);
await bootAndOpen(page);
await setLock(page, true);
// Programmatic select drives the real selection tool (no drag involved).
const id = await page.evaluate(() =>
(window as unknown as LocksWindow).Module.kicadCollabTestSelectComponent(),
);
expect(id).toBe(FP1);
await expect
.poll(() =>
page.evaluate(() =>
JSON.parse((window as unknown as LocksWindow).Module.kicadCollabGetSelection()),
),
)
.toContain(FP1);
expect(hasAbort(testLogger)).toBe(false);
});
test("ReleaseSelection unselects exactly the contested uuids", async ({
page,
testLogger,
}) => {
test.setTimeout(240000);
await bootAndOpen(page);
// Select the footprint plus (if distinct) the first top-level item through
// the real tool — TestSelectFirst may pick the footprint itself, so assert
// set-minus semantics rather than counts.
await page.evaluate(() => {
const w = window as unknown as LocksWindow;
w.Module.kicadCollabTestSelectComponent();
w.Module.kicadCollabTestSelectFirst();
});
await expect
.poll(() =>
page.evaluate(() =>
JSON.parse((window as unknown as LocksWindow).Module.kicadCollabGetSelection()),
),
)
.toContain(FP1);
const preRelease: string[] = await page.evaluate(() =>
JSON.parse((window as unknown as LocksWindow).Module.kicadCollabGetSelection()),
);
// Lose the tiebreak on the footprint only.
await page.evaluate(
({ fp }) =>
(window as unknown as LocksWindow).Module.kicadCollabReleaseSelection(
JSON.stringify([fp]),
"bob",
),
{ fp: FP1 },
);
// Exactly the contested uuid drops; anything else selected survives.
await expect
.poll(() =>
page.evaluate(() =>
JSON.parse((window as unknown as LocksWindow).Module.kicadCollabGetSelection()),
),
)
.toEqual(preRelease.filter((u) => u !== FP1));
expect(hasAbort(testLogger)).toBe(false);
});