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:
parent
d9264549bf
commit
4c3a4cacd4
102 changed files with 2867 additions and 3407 deletions
|
|
@ -2,7 +2,7 @@ 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';
|
||||
import { clickMenuBarItem, clickMenuItem, waitForEditorReady } from '../e2e/utils/element-tracker';
|
||||
|
||||
/**
|
||||
* Probe spec: drives the wizard, opens File menu, clicks Open, then dumps
|
||||
|
|
@ -18,32 +18,6 @@ import { clickByLabel, clickMenuBarItem, clickMenuItem } from '../e2e/utils/elem
|
|||
* 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 });
|
||||
// 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;
|
||||
|
|
@ -190,8 +164,12 @@ test.describe('PCB load probe', () => {
|
|||
await page.goto('/kicad/pcbnew.html');
|
||||
});
|
||||
|
||||
// NOTE: This is a one-shot DIAGNOSTIC probe (always green; its value is the logged
|
||||
// state dumps + screenshots). The fixed waits below are intentional "let state evolve,
|
||||
// then capture it" intervals, not readiness races — they are exempt from the no-sleep
|
||||
// guard on purpose. Regression specs (load-pcb, occ-export, …) use deterministic waits.
|
||||
test('inspect File→Open dialog state', async ({ page }) => {
|
||||
await completeWizard(page);
|
||||
await waitForEditorReady(page);
|
||||
|
||||
await page.screenshot({ path: 'test-results/probe-00-after-wizard.png', scale: 'css' });
|
||||
|
||||
|
|
@ -212,7 +190,7 @@ test.describe('PCB load probe', () => {
|
|||
// Click File menu
|
||||
const fileClicked = await clickMenuBarItem(page, 'File');
|
||||
console.log(`[PROBE] File menu clicked: ${fileClicked}`);
|
||||
await page.waitForTimeout(500);
|
||||
await page.waitForTimeout(500); // eslint-disable-line -- diagnostic one-shot; intentional state-capture interval
|
||||
|
||||
await page.screenshot({ path: 'test-results/probe-01-file-menu-open.png', scale: 'css' });
|
||||
await dumpRegistry(page, 'file-menu-open');
|
||||
|
|
@ -226,13 +204,13 @@ test.describe('PCB load probe', () => {
|
|||
// 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);
|
||||
await page.waitForTimeout(3000); // eslint-disable-line -- diagnostic one-shot; intentional state-capture interval
|
||||
|
||||
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);
|
||||
await page.waitForTimeout(3000); // eslint-disable-line -- diagnostic one-shot; intentional state-capture interval
|
||||
await page.screenshot({ path: 'test-results/probe-03-late.png', scale: 'css' });
|
||||
await dumpRegistry(page, 'late');
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue