findings R: coverage for the demo-ledger fixes (R-2, R-3, R-4, R-9) — tests only
- R-9: tests/kicad/project-sync.spec.ts gains an effect-asserting test — stages a self-contained footprint lib (ecc83 R_Axial as SyncFixture.pretty + absolute-uri fp-lib-table via a new stageAndOpen beforeOpen hook), presses Update PCB, and asserts the board's footprint references through kicadCollabSnapshot/kicadCollabTestItemBlob (R777, then R888 after a schematic rewrite + re-sync). Red-first: the dialog report said "Add R777" while the board stayed empty when the button click never landed. - R-2: tests/kicad/via-snapshot-assert.spec.ts — two-via board, exact widths + no PCB_VIA::GetWidth wx assert line in the console. - R-4: tests/web/console-copy.spec.ts — Ctrl/Cmd+C over a console selection fires `copy` (guard stops the keydown before wx); canvas pointerdown collapses the selection. ControlOrMeta: headless engines use the HOST copy accelerator regardless of the device UA. - R-3: workers/cdn gets a vitest harness (package.json + lockfile) and test/index.test.ts with a workerd-like stub bucket (always-defined range): plain GET is 200/no Content-Range, Range → 206, HEAD/304/404/405/OPTIONS. Mutation-verified (pre-1ea35f7 gating → 2 reds). CI step added after the corpus lint; node_modules gitignored. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015j8uFzSjwRrAeJ85QWVLQa
This commit is contained in:
parent
3d19117d88
commit
9e757c5396
8 changed files with 2127 additions and 3 deletions
|
|
@ -6,6 +6,7 @@ import {
|
|||
waitUntil,
|
||||
stableShot,
|
||||
} from '../e2e/utils/element-tracker';
|
||||
import { injectFromSubmodule } from './utils/fs-inject';
|
||||
|
||||
/**
|
||||
* project-sync 0001 — "Update PCB from Schematic" in the merged WASM editor.
|
||||
|
|
@ -271,20 +272,32 @@ interface FS { mkdirTree(p: string): void; writeFile(p: string, d: string): void
|
|||
interface Mod { kicadOpenFile(p: string): unknown; }
|
||||
|
||||
/** Stage board + schematic + minimal .kicad_pro into MEMFS, then open the board. */
|
||||
async function stageAndOpen(page: import('@playwright/test').Page, sch: string): Promise<void> {
|
||||
async function stageAndOpen(
|
||||
page: import('@playwright/test').Page,
|
||||
sch: string,
|
||||
/** Runs after the project files are staged and BEFORE the board opens (e.g. lib tables). */
|
||||
beforeOpen?: (page: import('@playwright/test').Page) => Promise<void>,
|
||||
): Promise<void> {
|
||||
await page.goto('/kicad/pcbnew.html');
|
||||
await waitForEditorReady(page);
|
||||
await page.evaluate(
|
||||
({ dir, stem, pcb, sch, pro }) => {
|
||||
const w = window as unknown as { FS: FS; Module: Mod };
|
||||
const w = window as unknown as { FS: FS };
|
||||
try { w.FS.mkdirTree(dir); } catch { /* exists */ }
|
||||
w.FS.writeFile(`${dir}/${stem}.kicad_pcb`, pcb);
|
||||
w.FS.writeFile(`${dir}/${stem}.kicad_sch`, sch);
|
||||
w.FS.writeFile(`${dir}/${stem}.kicad_pro`, pro);
|
||||
w.Module.kicadOpenFile(`${dir}/${stem}.kicad_pcb`);
|
||||
},
|
||||
{ dir: DIR, stem: STEM, pcb: PCB, sch, pro: PRO },
|
||||
);
|
||||
if (beforeOpen) await beforeOpen(page);
|
||||
await page.evaluate(
|
||||
({ dir, stem }) => {
|
||||
const w = window as unknown as { Module: Mod };
|
||||
w.Module.kicadOpenFile(`${dir}/${stem}.kicad_pcb`);
|
||||
},
|
||||
{ dir: DIR, stem: STEM },
|
||||
);
|
||||
await waitUntil(
|
||||
page,
|
||||
(s: string) => document.title.includes(s),
|
||||
|
|
@ -411,3 +424,138 @@ test.describe('project-sync: update PCB from schematic (merged bundle)', () => {
|
|||
'no wasm abort during the resync flow').toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// R-9 (docs/features/findings/groups/R-fixed-during-demo-record.md): the sync
|
||||
// must APPLY. The tests above prove the dialog is reached; DIALOG_UPDATE_PCB's
|
||||
// report can still say "done" while nothing lands on the board (the O-1
|
||||
// failure class the demo ledger hit). This one presses Update PCB and asserts
|
||||
// the BOARD EFFECT — the schematic's footprint exists on the board with the
|
||||
// schematic's reference — through the collab snapshot embind, never the
|
||||
// dialog text. A self-contained footprint library (the ecc83 demo's
|
||||
// footprints.pretty, staged into MEMFS with an absolute-uri project
|
||||
// fp-lib-table) makes the placement resolvable offline.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
const FP_LIB_NICK = 'SyncFixture';
|
||||
const FP_NAME = 'R_Axial_DIN0207_L6.3mm_D2.5mm_P7.62mm_Horizontal';
|
||||
const FP_LIB_DIR = `${DIR}/${FP_LIB_NICK}.pretty`;
|
||||
|
||||
/** The schematic with the resistor pointed at the staged fixture library. */
|
||||
function resistorSchWithFixtureLib(ref: string): string {
|
||||
return resistorSch(ref).replace('"Resistor_THT:', `"${FP_LIB_NICK}:`);
|
||||
}
|
||||
|
||||
/** Stage the .pretty + a project fp-lib-table (absolute uri; no env expansion needed). */
|
||||
async function stageFootprintLib(page: import('@playwright/test').Page): Promise<void> {
|
||||
await injectFromSubmodule(
|
||||
page,
|
||||
`kicad/demos/ecc83/footprints.pretty/${FP_NAME}.kicad_mod`,
|
||||
`${FP_LIB_DIR}/${FP_NAME}.kicad_mod`,
|
||||
);
|
||||
await page.evaluate(
|
||||
({ dir, nick, libDir }) => {
|
||||
const w = window as unknown as { FS: FS };
|
||||
w.FS.writeFile(
|
||||
`${dir}/fp-lib-table`,
|
||||
`(fp_lib_table\n (version 7)\n (lib (name "${nick}")(type "KiCad")(uri "${libDir}")(options "")(descr ""))\n)\n`,
|
||||
);
|
||||
},
|
||||
{ dir: DIR, nick: FP_LIB_NICK, libDir: FP_LIB_DIR },
|
||||
);
|
||||
}
|
||||
|
||||
interface SnapMod {
|
||||
kicadCollabSnapshot(): string;
|
||||
kicadCollabTestItemBlob(uuid: string): string;
|
||||
}
|
||||
|
||||
/** Click a visible wx button by label (registry coords, real mouse click — the
|
||||
* proven recipe from occ-export.spec.ts; a `&` mnemonic may prefix the label). */
|
||||
async function clickWxButton(page: import('@playwright/test').Page, label: string): Promise<void> {
|
||||
const pos = await page.evaluate((wanted: string) => {
|
||||
const el = (window.wxElementRegistry?.findAll({ visible: true }) ?? []).find(
|
||||
(e) => (e.label === wanted || e.label === `&${wanted}`) && (e.typeName ?? '').includes('Button'),
|
||||
);
|
||||
return el ? { x: el.centerX, y: el.centerY } : null;
|
||||
}, label);
|
||||
expect(pos, `wx button "${label}" found`).not.toBeNull();
|
||||
await page.mouse.click(pos!.x, pos!.y);
|
||||
}
|
||||
|
||||
/** After an apply the dialog is in its "done" state (OK disabled, Close is the
|
||||
* default) and Escape no longer resolves it — press Close explicitly. */
|
||||
async function closeDialogByButton(page: import('@playwright/test').Page): Promise<void> {
|
||||
await clickWxButton(page, 'Close');
|
||||
await waitUntil(
|
||||
page,
|
||||
() => {
|
||||
const r = window.wxElementRegistry;
|
||||
return !!r && !!r.findAll && !r.findAll({ visible: true })
|
||||
.some((e) => e.typeName === 'wxDialog');
|
||||
},
|
||||
'DIALOG_UPDATE_PCB closed via Close',
|
||||
{ timeout: 30000 },
|
||||
);
|
||||
}
|
||||
|
||||
/** References of every footprint currently on the board (from the item blobs). */
|
||||
async function boardFootprintRefs(page: import('@playwright/test').Page): Promise<string[]> {
|
||||
return page.evaluate(() => {
|
||||
const m = (window as unknown as { Module: SnapMod }).Module;
|
||||
const snap = JSON.parse(m.kicadCollabSnapshot()) as { added: Array<{ id: string; type: string }> };
|
||||
return snap.added
|
||||
.filter((i) => i.type === 'FOOTPRINT')
|
||||
.map((i) => /\(property "Reference" "([^"]*)"/.exec(m.kicadCollabTestItemBlob(i.id))?.[1] ?? '?');
|
||||
});
|
||||
}
|
||||
|
||||
/** Press Update PCB and wait until the board carries exactly the expected references. */
|
||||
async function updateAndExpectRefs(page: import('@playwright/test').Page, refs: string[]): Promise<void> {
|
||||
await clickWxButton(page, 'Update PCB');
|
||||
await expect
|
||||
.poll(() => boardFootprintRefs(page), {
|
||||
message: `board footprints after Update PCB should be ${JSON.stringify(refs)}`,
|
||||
timeout: 60000,
|
||||
intervals: [500],
|
||||
})
|
||||
.toEqual(refs);
|
||||
}
|
||||
|
||||
test.describe('project-sync: Update PCB applies to the board (R-9)', () => {
|
||||
test('the schematic footprint lands on the board, and a re-sync tracks a reference change', async ({ page }) => {
|
||||
test.setTimeout(240000);
|
||||
const consoleLines: string[] = [];
|
||||
page.on('console', (m) => consoleLines.push(m.text()));
|
||||
page.on('pageerror', (e) => consoleLines.push(`pageerror: ${e.message}`));
|
||||
|
||||
await stageAndOpen(page, resistorSchWithFixtureLib('R777'), stageFootprintLib);
|
||||
await page.waitForFunction(
|
||||
() => {
|
||||
const m = (window as unknown as { Module?: Partial<SnapMod> }).Module;
|
||||
return typeof m?.kicadCollabSnapshot === 'function'
|
||||
&& typeof m?.kicadCollabTestItemBlob === 'function';
|
||||
},
|
||||
null,
|
||||
{ timeout: 30000 },
|
||||
);
|
||||
expect(await boardFootprintRefs(page), 'board starts empty').toEqual([]);
|
||||
|
||||
// First sync: the effect, not the report.
|
||||
await openSyncDialog(page);
|
||||
await updateAndExpectRefs(page, ['R777']);
|
||||
await assertSchFrameHidden(page);
|
||||
await closeDialogByButton(page);
|
||||
|
||||
// The schematic changes underneath (live sibling restage) — re-sync must
|
||||
// apply the NEW reference, not a cached parse.
|
||||
await rewriteSchematic(page, resistorSchWithFixtureLib('R888'));
|
||||
await openSyncDialog(page);
|
||||
await updateAndExpectRefs(page, ['R888']);
|
||||
await assertSchFrameHidden(page);
|
||||
await closeDialogByButton(page);
|
||||
|
||||
expect(consoleLines.some((s) => s.includes('Aborted(')),
|
||||
'no wasm abort during the apply flow').toBe(false);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
112
tests/kicad/via-snapshot-assert.spec.ts
Normal file
112
tests/kicad/via-snapshot-assert.spec.ts
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
import { test, expect, type Page } from "./fixtures";
|
||||
import { execSync } from "child_process";
|
||||
import * as path from "path";
|
||||
|
||||
/**
|
||||
* repro for R-2 (docs/features/findings/groups/R-fixed-during-demo-record.md)
|
||||
*
|
||||
* `itemToJson` (wasm/bindings/pcbnew_embind.cpp) once called the layerless
|
||||
* virtual `PCB_VIA::GetWidth()` — since the padstack refactor that is a
|
||||
* wxCHECK trap ("Warning: PCB_VIA::GetWidth called without a layer argument",
|
||||
* pcbnew/pcb_track.cpp) — once per via per snapshot. The value came back
|
||||
* right (the wxCHECK's fallback IS the ALL_LAYERS slot), so no spec noticed;
|
||||
* on a big board every collab baseline/snapshot was an assert storm in the
|
||||
* console. The fix passes `PADSTACK::ALL_LAYERS`.
|
||||
*
|
||||
* Oracle: the wx assert line in the console (the wasm build logs asserts via
|
||||
* wxMessageOutputDebug and continues — wxTrap is a no-op there), plus the
|
||||
* via width itself. Harness: pcbnew-collab.html (wizard-skipping seed), a
|
||||
* two-via board written into MEMFS.
|
||||
*/
|
||||
|
||||
const VIA1 = "aaaaaaaa-0000-4000-8000-00000000c001";
|
||||
const VIA2 = "aaaaaaaa-0000-4000-8000-00000000c002";
|
||||
|
||||
const VIA_PCB = `(kicad_pcb
|
||||
\t(version 20241229)
|
||||
\t(generator "pcbnew")
|
||||
\t(generator_version "9.0")
|
||||
\t(general (thickness 1.6))
|
||||
\t(paper "A4")
|
||||
\t(layers
|
||||
\t\t(0 "F.Cu" signal)
|
||||
\t\t(2 "B.Cu" signal)
|
||||
\t\t(25 "Edge.Cuts" user)
|
||||
\t)
|
||||
\t(setup)
|
||||
\t(net 0 "")
|
||||
\t(via (at 80 80) (size 1.4) (drill 0.6) (layers "F.Cu" "B.Cu") (net 0) (uuid "${VIA1}"))
|
||||
\t(via (at 90 80) (size 0.8) (drill 0.4) (layers "F.Cu" "B.Cu") (net 0) (uuid "${VIA2}"))
|
||||
)
|
||||
`;
|
||||
|
||||
const VIA_WIDTH_ASSERT =
|
||||
/PCB_VIA::GetWidth called without a layer argument|assert "false" failed in GetWidth\(\)/;
|
||||
|
||||
interface FS { mkdirTree(p: string): void; writeFile(p: string, d: string): void; }
|
||||
interface Mod { kicadOpenFile(p: string): unknown; kicadCollabSnapshot(): string; }
|
||||
|
||||
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(
|
||||
() => {
|
||||
const m = (window as unknown as { Module?: Partial<Mod> }).Module;
|
||||
return typeof m?.kicadOpenFile === "function" && typeof m?.kicadCollabSnapshot === "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 { FS: FS; Module: Mod };
|
||||
const dir = "/home/kicad/documents";
|
||||
try { w.FS.mkdirTree(dir); } catch { /* exists */ }
|
||||
const p = `${dir}/vias.kicad_pcb`;
|
||||
w.FS.writeFile(p, content);
|
||||
w.Module.kicadOpenFile(p);
|
||||
}, VIA_PCB);
|
||||
await expect.poll(() => page.title(), { timeout: 30000 }).toMatch(/vias/i);
|
||||
}
|
||||
|
||||
test.beforeAll(() => {
|
||||
execSync("node collab/build.mjs", { cwd: path.resolve(__dirname, ".."), stdio: "inherit" });
|
||||
});
|
||||
|
||||
test("snapshotting a board with vias emits their width without a GetWidth assert (R-2)", async ({
|
||||
page,
|
||||
testLogger,
|
||||
}) => {
|
||||
test.setTimeout(180000);
|
||||
await bootAndOpen(page);
|
||||
|
||||
// Several snapshots: pre-fix this was one assert PER VIA PER SNAPSHOT.
|
||||
const snaps = await page.evaluate(() => {
|
||||
const m = (window as unknown as { Module: Mod }).Module;
|
||||
return [0, 1, 2].map(() => JSON.parse(m.kicadCollabSnapshot()));
|
||||
});
|
||||
const last = snaps[snaps.length - 1] as { added: Array<{ id: string; type: string; width?: number; drill?: number }> };
|
||||
const byId = new Map(last.added.map((i) => [i.id, i]));
|
||||
|
||||
for (const [id, mm] of [[VIA1, 1.4], [VIA2, 0.8]] as const) {
|
||||
const via = byId.get(id);
|
||||
expect(via, `via ${id} present in snapshot`).toBeTruthy();
|
||||
expect(via!.type).toBe("PCB_VIA");
|
||||
// internal units are nm; the (size …) is the whole-stack width.
|
||||
expect(via!.width, `via ${id} width`).toBe(Math.round(mm * 1_000_000));
|
||||
expect(via!.drill, `via ${id} drill`).toBeGreaterThan(0);
|
||||
}
|
||||
|
||||
const assertLines = [...testLogger.consoleLogs, ...testLogger.errors].filter((l) =>
|
||||
VIA_WIDTH_ASSERT.test(l),
|
||||
);
|
||||
expect(assertLines, "no PCB_VIA::GetWidth assert in the console").toEqual([]);
|
||||
});
|
||||
105
tests/web/console-copy.spec.ts
Normal file
105
tests/web/console-copy.spec.ts
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
import { test, expect, type Page } from '@playwright/test';
|
||||
|
||||
/**
|
||||
* repro for R-4 (docs/features/findings/groups/R-fixed-during-demo-record.md)
|
||||
*
|
||||
* wx's window-level keydown handler forwards every non-printable chord to the
|
||||
* wasm app and `preventDefault`s it (wxwidgets/src/wasm/app.cpp,
|
||||
* `preventDefault = !KeyEventIsPlainPrintable(...)`). Ctrl/Cmd+C is such a
|
||||
* chord, so the browser's native "copy selection" never ran: log text in the
|
||||
* console panel could be selected but not copied. WasmTool now intercepts the
|
||||
* chord in the CAPTURE phase when the selection lives in the console and stops
|
||||
* propagation, so the default copy fires; and a canvas pointerdown collapses a
|
||||
* stale console selection so it cannot steal the editor's own Ctrl+C.
|
||||
*
|
||||
* Oracle: a `copy` event on the document. Cancelling the keydown suppresses
|
||||
* the copy default, so with the guard removed no `copy` event fires. Engine-
|
||||
* neutral (no clipboard-read permission needed). The chord is ControlOrMeta+C:
|
||||
* headless engines honour the HOST platform's copy accelerator (Meta on a mac
|
||||
* dev box, Control on Linux CI) regardless of the device UA — a plain
|
||||
* Control+C never copies on macOS (probed on both engines). The guard checks
|
||||
* metaKey || ctrlKey, so either spelling exercises it.
|
||||
*/
|
||||
|
||||
const SCOPE = 'default';
|
||||
|
||||
async function bootBoard(page: Page): Promise<void> {
|
||||
await page.goto(`/${SCOPE}/projects/demo/demo.kicad_pcb?user=copy-probe`);
|
||||
await expect(page.locator('#canvas')).toBeVisible({ timeout: 120000 });
|
||||
await expect
|
||||
.poll(() => page.title(), {
|
||||
message: 'editor never reached the expected title',
|
||||
timeout: 120000,
|
||||
intervals: [1000],
|
||||
})
|
||||
.toMatch(/demo — PCB Editor/i);
|
||||
}
|
||||
|
||||
test('Ctrl+C copies a console-log selection instead of being eaten by wx', async ({ page }) => {
|
||||
test.setTimeout(300000); // one full pcbnew wasm boot
|
||||
|
||||
await bootBoard(page);
|
||||
|
||||
// Open the console footer (closed state is the "console (N)" tab).
|
||||
await page.getByRole('button', { name: /console \(/ }).first().click();
|
||||
const log = page.locator('pre.select-text');
|
||||
await expect(log).toBeVisible({ timeout: 10000 });
|
||||
await expect.poll(() => log.innerText()).not.toBe('');
|
||||
|
||||
// Select the log text and arm the oracle.
|
||||
await page.evaluate(() => {
|
||||
const w = window as unknown as { __copyFired: number; __keydownPrevented: boolean | null };
|
||||
w.__copyFired = 0;
|
||||
w.__keydownPrevented = null;
|
||||
document.addEventListener('copy', () => { w.__copyFired++; });
|
||||
// Bubble-phase listener on window = after wx's handler; records whether the
|
||||
// chord's default was cancelled (the failure mode).
|
||||
// Diagnostics (window capture = same node as the guard, fires after it;
|
||||
// document capture = only reachable if the guard did NOT stop propagation).
|
||||
const d = window as unknown as { __diag: Record<string, unknown> };
|
||||
d.__diag = { winCapture: 0, docCapture: 0, docPreventedAtBubble: null as boolean | null };
|
||||
window.addEventListener('keydown', (e) => {
|
||||
if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 'c') {
|
||||
(d.__diag.winCapture as number)++;
|
||||
d.__diag.active = document.activeElement?.tagName + '#' + (document.activeElement?.id || '');
|
||||
}
|
||||
}, true);
|
||||
document.addEventListener('keydown', (e) => {
|
||||
if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 'c') (d.__diag.docCapture as number)++;
|
||||
}, true);
|
||||
document.addEventListener('keydown', (e) => {
|
||||
if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 'c') d.__diag.docPreventedAtBubble = e.defaultPrevented;
|
||||
});
|
||||
const pre = document.querySelector('pre.select-text');
|
||||
if (!pre) throw new Error('console <pre> not found');
|
||||
const range = document.createRange();
|
||||
range.selectNodeContents(pre);
|
||||
const sel = window.getSelection();
|
||||
sel?.removeAllRanges();
|
||||
sel?.addRange(range);
|
||||
});
|
||||
expect(await page.evaluate(() => window.getSelection()?.isCollapsed)).toBe(false);
|
||||
|
||||
await page.keyboard.press('ControlOrMeta+c');
|
||||
console.log('[R-4 diag]', JSON.stringify(await page.evaluate(() => (window as unknown as { __diag: unknown }).__diag)));
|
||||
|
||||
await expect
|
||||
.poll(() => page.evaluate(() => (window as unknown as { __copyFired: number }).__copyFired), {
|
||||
message: 'no copy event — wx swallowed Ctrl+C with the selection in the console',
|
||||
timeout: 5000,
|
||||
})
|
||||
.toBeGreaterThan(0);
|
||||
|
||||
// A canvas pointerdown collapses the console selection (wx preventDefaults the
|
||||
// native collapse), so a stale log selection cannot keep stealing Ctrl+C.
|
||||
await page.evaluate(() => {
|
||||
const c = document.querySelector('#canvas') as HTMLCanvasElement;
|
||||
c.dispatchEvent(new PointerEvent('pointerdown', { bubbles: true, cancelable: true, clientX: 10, clientY: 10 }));
|
||||
});
|
||||
await expect
|
||||
.poll(() => page.evaluate(() => window.getSelection()?.isCollapsed ?? true), {
|
||||
message: 'console selection should collapse on canvas pointerdown',
|
||||
timeout: 5000,
|
||||
})
|
||||
.toBe(true);
|
||||
});
|
||||
Loading…
Reference in a new issue