pcbjam/tests/kicad/load-pcb-probe.spec.ts

248 lines
8.7 KiB
TypeScript
Raw Normal View History

import * as fs from 'fs';
import * as path from 'path';
import type { Page } from '@playwright/test';
import { test, expect } from './fixtures';
import { clickByLabel, clickMenuBarItem, clickMenuItem } from '../e2e/utils/element-tracker';
/**
* Probe spec: drives the wizard, opens File menu, clicks Open, then dumps
* everything we need to know about the wxFileDialog state what frame paints,
* what directory the dialog starts in, what list items are registered, what
* the OK/Cancel button labels are, and which MEMFS directories exist.
*
* Output:
* tests/logs/kicad/load-pcb-probe/<test-name>.log (everything via console)
* tests/test-results/probe-*.png (screenshots)
*
* This is a one-shot investigation, not a regression test. It always passes;
* the value is the captured state.
*/
async function completeWizard(page: Page): Promise<void> {
await expect(page.locator('#canvas')).toBeVisible({ timeout: 90000 });
await page.waitForFunction(() => !!window.wxElementRegistry, null, { timeout: 90000 });
fix(e2e): make the firefox kicad suite pass on GPU-less CI runners CI runs (Hetzner 27329612719, Ubicloud 27330989479) failed 22/41 identically, in two buckets, both firefox-environment issues (the suite is firefox-only: test:kicad -> --project=firefox): 1. No WebGL: headless Firefox can't create ANY GL context on a GPU-less VM (blocklist bypass still dies with FEATURE_FAILURE_WEBGL_EXHAUSTED_DRIVERS), so the GAL canvas failed and an error dialog blocked every UI flow. Fix: run headed under xvfb (GLX + Mesa llvmpipe software GL) with webgl.force-enabled — workflows now wrap the e2e step in xvfb-run. 2. pcbnew wasm OOM: the ~190M module OOMs Firefox's optimizing wasm JIT at compile ("InternalError: out of memory") and the app never boots. Fix: javascript.options.wasm_optimizingjit=false (baseline-only compile). Both prefs are CI-gated in playwright-kicad.config.ts; local runs keep stock behavior. Boot got slower (baseline JIT), so the wizard helpers now wait for the registry to have actual UI ENTRIES (the registry OBJECT exists pre-boot) instead of clicking into a fixed 10x500ms window. Validated in a local docker repro of the CI env (playwright:v1.57.0 image, no GPU): pl_editor canvas, gerbview wizard+canvas, and pcbnew wizard (on a properly asyncified 187M module) all pass; before the fix they reproduced the exact CI signatures. Known-fail left on CI: zoom-cursor — the zoom-in anchors at ~ -P in headed Firefox (screen-vs-client coordinate mix-up in the wheel->GAL path, headed mode only); marked test.fixme(CI) pending a wx-wasm-layer investigation. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-11 13:22:29 +02:00
// Registry object ≠ app booted: wait for real UI entries (the wizard is the
// first window) so the bounded click loop below doesn't start too early.
// CI boots slower (baseline-JIT wasm + software GL under xvfb).
await page.waitForFunction(() => {
const registry = window.wxElementRegistry;
return !!registry && registry.findAll({}).length > 0;
}, null, { timeout: 150000 });
await page.waitForTimeout(2000);
for (let i = 1; i <= 10; i++) {
let clicked = await clickByLabel(page, 'Next >');
if (!clicked) {
clicked = await clickByLabel(page, 'Finish');
break;
}
await page.waitForTimeout(500);
}
await page.waitForTimeout(2000);
}
async function dumpRegistry(page: Page, label: string): Promise<void> {
const summary = await page.evaluate((tag: string) => {
const registry = window.wxElementRegistry;
if (!registry) {
return { tag, error: 'no registry' };
}
const stats = registry.getStats();
const renderedStats = registry.getRenderedStats?.();
const allElements = registry.findAll({ visible: true });
const frames = allElements
.filter((el) => /Frame|Dialog|Wizard/.test(el.typeName))
.slice(0, 30)
.map((el) => ({
id: el.id,
typeName: el.typeName,
label: el.label,
name: el.name,
visible: el.visible,
enabled: el.enabled,
screenX: el.screenX,
screenY: el.screenY,
width: el.width,
height: el.height,
}));
// Try to spot the file dialog specifically
const fileDialogs = allElements
.filter((el) =>
/FileDialog|FileCtrl|FileList|GenericDir/.test(el.typeName) ||
/file/i.test(el.label) ||
/file/i.test(el.name)
)
.slice(0, 50)
.map((el) => ({
id: el.id,
typeName: el.typeName,
label: el.label,
name: el.name,
visible: el.visible,
screenX: el.screenX,
screenY: el.screenY,
width: el.width,
height: el.height,
}));
const rendered = registry.findAllRendered ? registry.findAllRendered({}) : [];
const byType = rendered.reduce<Record<string, number>>((acc, item) => {
acc[item.elementType] = (acc[item.elementType] ?? 0) + 1;
return acc;
}, {});
const menuItems = rendered
.filter((r) => r.elementType === 'menuitem')
.slice(0, 60)
.map((r) => ({
id: r.id,
subType: r.subType,
label: r.label,
enabled: r.enabled,
screenX: r.screenX,
screenY: r.screenY,
}));
const listItems = rendered
.filter((r) => r.elementType === 'listitem')
.slice(0, 60)
.map((r) => ({
id: r.id,
label: r.label,
index: r.index,
screenX: r.screenX,
screenY: r.screenY,
}));
// Buttons (rendered as wxButton in elements, not in rendered registry)
const buttons = allElements
.filter((el) => /Button/.test(el.typeName))
.slice(0, 40)
.map((el) => ({
id: el.id,
typeName: el.typeName,
label: el.label,
name: el.name,
screenX: el.screenX,
screenY: el.screenY,
}));
// Text controls (path bar in dialog is usually a wxTextCtrl)
const textCtrls = allElements
.filter((el) => /TextCtrl|ComboCtrl|ComboBox|Choice/.test(el.typeName))
.slice(0, 30)
.map((el) => ({
id: el.id,
typeName: el.typeName,
label: el.label,
name: el.name,
screenX: el.screenX,
screenY: el.screenY,
width: el.width,
height: el.height,
}));
return {
tag,
stats,
renderedStats,
renderedByType: byType,
frames,
fileDialogs,
menuItems,
listItems,
buttons,
textCtrls,
};
}, label);
// Logged via console so it lands in tests/logs/kicad/load-pcb-probe/<test>.log
console.log(`[PROBE] ${label} :: ${JSON.stringify(summary)}`);
}
async function dumpMemfs(page: Page, candidates: string[]): Promise<void> {
const results = await page.evaluate((paths: string[]) => {
const out: Array<{ path: string; entries: string[] | string }> = [];
for (const p of paths) {
try {
// @ts-ignore — Emscripten FS is global on Module
const entries = (window as any).FS.readdir(p) as string[];
out.push({ path: p, entries });
} catch (e: any) {
out.push({ path: p, entries: `ERROR: ${e?.message ?? e}` });
}
}
return out;
}, candidates);
console.log(`[PROBE-FS] ${JSON.stringify(results)}`);
}
test.describe('PCB load probe', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/kicad/pcbnew.html');
});
test('inspect File→Open dialog state', async ({ page }) => {
await completeWizard(page);
feat(tests): screenshot regression + Discord review, perf-tracked New tooling in tests/tools/screenshots/ (TypeScript via tsx): - compare.ts: one pixelmatch engine (AA-excluded), connected-component "where to look" boxes, old|new+boxes|heatmap triptych, per-engine floors. - promote.ts: churn-free updater — overwrite a baseline only when decoded pixels differ beyond the floor, copying CI bytes verbatim (no re-encode churn); pulls a CI run via `gh run download` or a local --from dir. - post-discord.ts: always-on CI-on-main report (SHA + e2e status + the track-only runtime-perf table), then screenshot triptychs, batched + size-capped + flood-collapsed + 429-aware. - perf-report.ts: perf table with Δ vs the previous main run (via gh). - changelog.ts: no-build git-history baseline differ (Discord trigger B). - noise.ts / gen-manifest.ts: calibration + manifest generation. CI wiring: - wasm-build.yml: post-test step runs the gate + report on the already- produced test-results (no extra build); report-only (continue-on-error), posts only on push to main, inert without DISCORD_WEBHOOK_URL. - ci-ubicloud.yml: secrets: inherit (pass the webhook through). - screenshot-changelog.yml: ~30s no-build changelog on baseline changes. screenshot-manifest.json: canonical 354-name set + best-effort engine tags (313 chromium-swiftshader / 41 firefox-llvmpipe). Normalize scale:'device'->'css' across 18 spec files (no-op at CI DSF=1) so committed baselines are uniformly css-scaled. Design: CI's Linux render is the single source of truth; no pinned container (accept rare env drift -> re-promote); dev commits via promote. Replaces the byte-cmp compare-screenshots.sh + file-size-proxy update-baseline-screenshots.sh (kept for now until the first re-baseline). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-01 18:01:15 +02:00
await page.screenshot({ path: 'test-results/probe-00-after-wizard.png', scale: 'css' });
await dumpMemfs(page, [
'/',
'/home',
'/home/kicad',
'/home/kicad/documents',
'/home/kicad/documents/kicad',
'/home/kicad/documents/kicad/10.0',
'/home/kicad/documents/kicad/10.0/projects',
'/tmp',
'/workspace',
]);
await dumpRegistry(page, 'after-wizard');
// Click File menu
const fileClicked = await clickMenuBarItem(page, 'File');
console.log(`[PROBE] File menu clicked: ${fileClicked}`);
await page.waitForTimeout(500);
feat(tests): screenshot regression + Discord review, perf-tracked New tooling in tests/tools/screenshots/ (TypeScript via tsx): - compare.ts: one pixelmatch engine (AA-excluded), connected-component "where to look" boxes, old|new+boxes|heatmap triptych, per-engine floors. - promote.ts: churn-free updater — overwrite a baseline only when decoded pixels differ beyond the floor, copying CI bytes verbatim (no re-encode churn); pulls a CI run via `gh run download` or a local --from dir. - post-discord.ts: always-on CI-on-main report (SHA + e2e status + the track-only runtime-perf table), then screenshot triptychs, batched + size-capped + flood-collapsed + 429-aware. - perf-report.ts: perf table with Δ vs the previous main run (via gh). - changelog.ts: no-build git-history baseline differ (Discord trigger B). - noise.ts / gen-manifest.ts: calibration + manifest generation. CI wiring: - wasm-build.yml: post-test step runs the gate + report on the already- produced test-results (no extra build); report-only (continue-on-error), posts only on push to main, inert without DISCORD_WEBHOOK_URL. - ci-ubicloud.yml: secrets: inherit (pass the webhook through). - screenshot-changelog.yml: ~30s no-build changelog on baseline changes. screenshot-manifest.json: canonical 354-name set + best-effort engine tags (313 chromium-swiftshader / 41 firefox-llvmpipe). Normalize scale:'device'->'css' across 18 spec files (no-op at CI DSF=1) so committed baselines are uniformly css-scaled. Design: CI's Linux render is the single source of truth; no pinned container (accept rare env drift -> re-promote); dev commits via promote. Replaces the byte-cmp compare-screenshots.sh + file-size-proxy update-baseline-screenshots.sh (kept for now until the first re-baseline). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-01 18:01:15 +02:00
await page.screenshot({ path: 'test-results/probe-01-file-menu-open.png', scale: 'css' });
await dumpRegistry(page, 'file-menu-open');
// Click Open menu item (try common label variants)
let openClicked = await clickMenuItem(page, 'Open...');
if (!openClicked) openClicked = await clickMenuItem(page, 'Open…');
if (!openClicked) openClicked = await clickMenuItem(page, 'Open');
console.log(`[PROBE] Open menu item clicked: ${openClicked}`);
// Give the file dialog generous time to render — wxGenericFileDialog
// populates its file list by scanning the directory, which on MEMFS
// is fast but goes through the Asyncify loop.
await page.waitForTimeout(3000);
feat(tests): screenshot regression + Discord review, perf-tracked New tooling in tests/tools/screenshots/ (TypeScript via tsx): - compare.ts: one pixelmatch engine (AA-excluded), connected-component "where to look" boxes, old|new+boxes|heatmap triptych, per-engine floors. - promote.ts: churn-free updater — overwrite a baseline only when decoded pixels differ beyond the floor, copying CI bytes verbatim (no re-encode churn); pulls a CI run via `gh run download` or a local --from dir. - post-discord.ts: always-on CI-on-main report (SHA + e2e status + the track-only runtime-perf table), then screenshot triptychs, batched + size-capped + flood-collapsed + 429-aware. - perf-report.ts: perf table with Δ vs the previous main run (via gh). - changelog.ts: no-build git-history baseline differ (Discord trigger B). - noise.ts / gen-manifest.ts: calibration + manifest generation. CI wiring: - wasm-build.yml: post-test step runs the gate + report on the already- produced test-results (no extra build); report-only (continue-on-error), posts only on push to main, inert without DISCORD_WEBHOOK_URL. - ci-ubicloud.yml: secrets: inherit (pass the webhook through). - screenshot-changelog.yml: ~30s no-build changelog on baseline changes. screenshot-manifest.json: canonical 354-name set + best-effort engine tags (313 chromium-swiftshader / 41 firefox-llvmpipe). Normalize scale:'device'->'css' across 18 spec files (no-op at CI DSF=1) so committed baselines are uniformly css-scaled. Design: CI's Linux render is the single source of truth; no pinned container (accept rare env drift -> re-promote); dev commits via promote. Replaces the byte-cmp compare-screenshots.sh + file-size-proxy update-baseline-screenshots.sh (kept for now until the first re-baseline). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-01 18:01:15 +02:00
await page.screenshot({ path: 'test-results/probe-02-after-open-click.png', scale: 'css' });
await dumpRegistry(page, 'after-open-click');
// Wait a bit longer and dump again, in case the dialog paints late
await page.waitForTimeout(3000);
feat(tests): screenshot regression + Discord review, perf-tracked New tooling in tests/tools/screenshots/ (TypeScript via tsx): - compare.ts: one pixelmatch engine (AA-excluded), connected-component "where to look" boxes, old|new+boxes|heatmap triptych, per-engine floors. - promote.ts: churn-free updater — overwrite a baseline only when decoded pixels differ beyond the floor, copying CI bytes verbatim (no re-encode churn); pulls a CI run via `gh run download` or a local --from dir. - post-discord.ts: always-on CI-on-main report (SHA + e2e status + the track-only runtime-perf table), then screenshot triptychs, batched + size-capped + flood-collapsed + 429-aware. - perf-report.ts: perf table with Δ vs the previous main run (via gh). - changelog.ts: no-build git-history baseline differ (Discord trigger B). - noise.ts / gen-manifest.ts: calibration + manifest generation. CI wiring: - wasm-build.yml: post-test step runs the gate + report on the already- produced test-results (no extra build); report-only (continue-on-error), posts only on push to main, inert without DISCORD_WEBHOOK_URL. - ci-ubicloud.yml: secrets: inherit (pass the webhook through). - screenshot-changelog.yml: ~30s no-build changelog on baseline changes. screenshot-manifest.json: canonical 354-name set + best-effort engine tags (313 chromium-swiftshader / 41 firefox-llvmpipe). Normalize scale:'device'->'css' across 18 spec files (no-op at CI DSF=1) so committed baselines are uniformly css-scaled. Design: CI's Linux render is the single source of truth; no pinned container (accept rare env drift -> re-promote); dev commits via promote. Replaces the byte-cmp compare-screenshots.sh + file-size-proxy update-baseline-screenshots.sh (kept for now until the first re-baseline). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-01 18:01:15 +02:00
await page.screenshot({ path: 'test-results/probe-03-late.png', scale: 'css' });
await dumpRegistry(page, 'late');
// Final check: re-dump MEMFS so we can confirm nothing changed under us
await dumpMemfs(page, [
'/home/kicad/documents/kicad/10.0/projects',
'/tmp',
]);
// Probe is always green — the artifacts (logs + screenshots) are the result.
expect(true).toBe(true);
});
});