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

@ -11,8 +11,8 @@
// during base construction and is skipped as a base type), so the app reports
// the layer-list height directly from C++ via console.log; the test asserts on
// those. It is RED before the wasm-layer fix and GREEN after.
import { test, expect, tryLoadApp } from './utils/fixtures';
import { clickByLabel, findByType, waitForRegistry } from './utils/element-tracker';
import { test, expect } from './utils/fixtures';
import { findByType, waitForWxApp, stableShot } from './utils/element-tracker';
const APP = '/standalone/collapse-relayout/collapse-relayout_test.html';
const HEADER_LABEL = 'Layer Display Options';
@ -24,31 +24,40 @@ function reportedHeight(logs: string[], tag: string): number {
return m ? parseInt(m[1], 10) : -1;
}
// Expand the collapsible pane: click its header (wxGenericCollapsibleHeaderCtrl
// registers with the pane's label). Fall back to clicking the top of the pane.
// Expand the collapsible "Layer Display Options" pane. Its header
// (wxGenericCollapsibleHeaderCtrl) is not in the label registry, so — as the original did
// via its findByType fallback — find the wxGenericCollapsiblePane by type and click its
// header row (top-left). Deterministically wait for the pane to render first.
async function expandPane(page: import('@playwright/test').Page): Promise<boolean> {
if (await clickByLabel(page, HEADER_LABEL)) return true;
const panes = await findByType(page, 'wxGenericCollapsiblePane');
if (panes.length) {
await page.mouse.click(panes[0].screenX + 15, panes[0].screenY + 10);
return true;
}
return false;
let panes: Awaited<ReturnType<typeof findByType>> = [];
await expect
.poll(async () => {
panes = await findByType(page, 'wxGenericCollapsiblePane');
return panes.length;
}, { message: `"${HEADER_LABEL}" collapsible pane should be rendered` })
.toBeGreaterThan(0);
await page.mouse.click(panes[0].screenX + 15, panes[0].screenY + 10);
return true;
}
test.describe('collapse-relayout (Layer Display Options bug)', () => {
test('app loads with a populated layer list', async ({ page, testLogger }) => {
await page.goto(APP);
const loaded = await tryLoadApp(page);
expect(loaded, 'App should load').toBe(true);
await waitForRegistry(page);
await page.waitForTimeout(300);
await waitForWxApp(page);
await page.screenshot({ path: 'test-results/collapse-relayout-01-loaded.png', fullPage: true });
await expect
.poll(() => testLogger.consoleLogs.some(l => l.includes('[COLLAPSE_RELAYOUT] app started')), {
message: 'app-started log should be present',
})
.toBe(true);
await expect
.poll(() => reportedHeight(testLogger.consoleLogs, 'initial layerlist height') > -1, {
message: 'initial layerlist height should be reported',
})
.toBe(true);
expect(testLogger.consoleLogs.some(l => l.includes('[COLLAPSE_RELAYOUT] app started')),
'app-started log should be present').toBe(true);
await stableShot(page, 'collapse-relayout-01-loaded.png', { fullPage: true });
const initial = reportedHeight(testLogger.consoleLogs, 'initial layerlist height');
console.log('initial layerlist height =', initial);
@ -59,25 +68,31 @@ test.describe('collapse-relayout (Layer Display Options bug)', () => {
test('layer list survives expanding "Layer Display Options"', async ({ page, testLogger }) => {
await page.goto(APP);
const loaded = await tryLoadApp(page);
expect(loaded, 'App should load').toBe(true);
await waitForRegistry(page);
await page.waitForTimeout(300);
await waitForWxApp(page);
await expect
.poll(() => reportedHeight(testLogger.consoleLogs, 'initial layerlist height') > -1, {
message: 'initial layerlist height should be reported',
})
.toBe(true);
const initial = reportedHeight(testLogger.consoleLogs, 'initial layerlist height');
expect(initial, 'layer list should start with a real height').toBeGreaterThan(100);
const clicked = await expandPane(page);
expect(clicked, `"${HEADER_LABEL}" pane header should be found and clicked`).toBe(true);
await page.waitForTimeout(400);
await page.screenshot({ path: 'test-results/collapse-relayout-02-expanded.png', fullPage: true });
// The handler only logs on a real toggle — its presence proves the click
// reached the pane, and N is the list height measured right after relayout.
await expect
.poll(() => reportedHeight(testLogger.consoleLogs, 'layerlist height after toggle') > -1, {
message: 'pane toggle handler should have run',
})
.toBe(true);
await stableShot(page, 'collapse-relayout-02-expanded.png', { fullPage: true });
const afterToggle = reportedHeight(testLogger.consoleLogs, 'layerlist height after toggle');
console.log('layerlist height after toggle =', afterToggle);
expect(afterToggle, 'pane toggle handler should have run').toBeGreaterThan(-1);
// Core assertion: the list must NOT have collapsed to ~0.
expect(afterToggle, 'layer list height after expanding the pane').toBeGreaterThan(50);