test(determinism): deterministic waits + stableShot screenshots; drop blind sleeps/ifs/retries

Make the Playwright e2e + kicad suites deterministic so screenshot flake stops
tracing to timing races.

- Blind page.waitForTimeout -> condition waits (expect.poll, web-first
  assertions, waitUntil) + readiness helpers (waitForWxApp, waitForCanvasApp).
  Remaining sleeps are documented interaction dwells (annotated).
- Defensive "if element exists" branches -> loud asserts; label-fallback chains
  -> normalized clickMenuItemByText. First-run wizard for/if loops removed by
  seeding calculator/gerbview/pcbnew HTMLs.
- Screenshots: new stableShot(page, name) settles the render in-page (canvas
  hash over rAF) then writes a raw PNG to test-results/ for the existing offline
  gate (tools/screenshots vs baseline-screenshots). Replaces toHaveScreenshot,
  which did inline compare + its own baselines and had decoupled the specs from
  the real gate. scale:'css' pinned.
- retries: 0 in both configs.
- Guard: tests/tools/lint-determinism.ts (npm run lint:determinism) bans blind
  sleeps / toHaveScreenshot / inline retries / swallowed catches in specs;
  documented exceptions carry a marker. Rules in tests/TESTING.md.

Assertions, coverage, and renders unchanged (semantic-equivalence reviewed;
captures pixel-identical modulo inherent timer/timestamp/3d-raytrace variance).
Both suites green at retries:0 (e2e 340, kicad 92); ~35-61% faster.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BVX1pHMvRPYHdp6ZfEawrk
This commit is contained in:
Viktor Vaczi 2026-07-07 10:50:24 +02:00
commit 4c3a4cacd4
102 changed files with 2867 additions and 3407 deletions

View file

@ -1,37 +1,36 @@
// wxAuiManager Tests - AUI docking system KiCad uses extensively
import { test, expect, MAIN_CANVAS, tryLoadApp, getCanvasBox } from './utils/fixtures';
import { clickAuiButton, clickAuiPaneContent, findRenderedByLabel, findRenderedByType } from './utils/element-tracker';
import { test, expect, MAIN_CANVAS, waitForWxApp, getCanvasBox } from './utils/fixtures';
import { clickAuiButton, clickAuiPaneContent, findRenderedByLabel, findRenderedByType, stableShot } from './utils/element-tracker';
test.describe('wxAuiManager Tests', () => {
test('AUI test app loads successfully', async ({ page, testLogger }) => {
await page.goto('/standalone/aui/aui_test.html');
const loaded = await tryLoadApp(page);
await page.screenshot({ path: 'test-results/aui-01-loaded.png', fullPage: true });
await waitForWxApp(page);
const hasStartup = testLogger.consoleLogs.some(l => l.includes('AUI test app started'));
expect(loaded, 'AUI app should load').toBe(true);
await stableShot(page, 'aui-01-loaded.png', { fullPage: true });
expect(testLogger.errors.filter(e => !e.includes('favicon'))).toHaveLength(0);
});
test('AUI dockable panels are visible', async ({ page, testLogger }) => {
await page.goto('/standalone/aui/aui_test.html');
const loaded = await tryLoadApp(page);
expect(loaded, 'App should load').toBe(true);
await waitForWxApp(page);
await page.screenshot({ path: 'test-results/aui-02-panels.png', fullPage: true });
await expect
.poll(() => testLogger.consoleLogs.some(l => l.includes('dockable panels')), {
message: 'AUI dockable panels log should be emitted',
})
.toBe(true);
const hasPanelsLog = testLogger.consoleLogs.some(l => l.includes('dockable panels'));
expect(hasPanelsLog).toBe(true);
await stableShot(page, 'aui-02-panels.png', { fullPage: true });
});
test('Panel close button can be clicked', async ({ page, testLogger }) => {
await page.goto('/standalone/aui/aui_test.html');
const loaded = await tryLoadApp(page);
expect(loaded, 'App should load').toBe(true);
await waitForWxApp(page);
// Find all AUI parts to verify they're registered
const auiParts = await findRenderedByType(page, 'auipart');
@ -40,15 +39,13 @@ test.describe('wxAuiManager Tests', () => {
// Click on Properties panel close button using element registry
const clicked = await clickAuiButton(page, 'close', 'Properties');
expect(clicked, 'Properties close button should be found and clicked').toBe(true);
await page.waitForTimeout(500);
await page.screenshot({ path: 'test-results/aui-03-close-clicked.png', fullPage: true });
await stableShot(page, 'aui-03-close-clicked.png', { fullPage: true });
});
test('Panel can be dragged', async ({ page, testLogger }) => {
await page.goto('/standalone/aui/aui_test.html');
const loaded = await tryLoadApp(page);
expect(loaded, 'App should load').toBe(true);
await waitForWxApp(page);
const box = await getCanvasBox(page);
@ -61,37 +58,34 @@ test.describe('wxAuiManager Tests', () => {
await page.mouse.down();
await page.mouse.move(box.x + 300, box.y + 200, { steps: 10 });
await page.mouse.up();
await page.waitForTimeout(500);
await page.screenshot({ path: 'test-results/aui-04-dragged.png', fullPage: true });
await stableShot(page, 'aui-04-dragged.png', { fullPage: true });
});
test('Multiple panels can be interacted with', async ({ page, testLogger }) => {
await page.goto('/standalone/aui/aui_test.html');
const loaded = await tryLoadApp(page);
expect(loaded, 'App should load').toBe(true);
await waitForWxApp(page);
// Click in Properties panel using element tracking
const propsClicked = await clickAuiPaneContent(page, 'Properties');
expect(propsClicked, 'Should be able to click Properties pane').toBe(true);
await page.waitForTimeout(200);
await page.waitForTimeout(200); // eslint-disable-line -- documented interaction dwell: no observable event; lets the pane-content click commit before the next click
// Click in Layers panel using element tracking
const layersClicked = await clickAuiPaneContent(page, 'Layers');
expect(layersClicked, 'Should be able to click Layers pane').toBe(true);
await page.waitForTimeout(200);
await page.waitForTimeout(200); // eslint-disable-line -- documented interaction dwell: no observable event; lets the pane-content click commit before the next click
// Click in Messages panel using element tracking
const messagesClicked = await clickAuiPaneContent(page, 'Messages');
expect(messagesClicked, 'Should be able to click Messages pane').toBe(true);
await page.waitForTimeout(200);
await page.waitForTimeout(200); // eslint-disable-line -- documented interaction dwell: no observable event; lets the pane-content click commit before the next click
// Click in Event Log panel using element tracking
const eventLogClicked = await clickAuiPaneContent(page, 'Event Log');
expect(eventLogClicked, 'Should be able to click Event Log pane').toBe(true);
await page.waitForTimeout(200);
await page.screenshot({ path: 'test-results/aui-05-multi-panel.png', fullPage: true });
await stableShot(page, 'aui-05-multi-panel.png', { fullPage: true });
expect(testLogger.errors.filter(e => !e.includes('favicon'))).toHaveLength(0);
});