pcbjam/tests/playwright-web.config.ts
Viktor Vaczi 63ed1f3c1f e2e/CI: dual-engine suites, per-engine screenshots, SwiftShader retired, prod web suite, CI-coverage gate
Squash of experiment/ff-big-modules vs main.

Big-module routing removed: native-EH shrank kicad_editor below
SpiderMonkey's x86-64 code budget (runs 29355049705/29356152413 green on
stock Firefox), so BIG_MODULE_SPECS routing and the baseline-only-JIT
crutch are gone — kicad-firefox and kicad-chromium both run the full
suite, with the module compiled the way real users' browsers compile it.

Per-engine screenshots end to end: stableShot/shotPath write
test-results/<engine>/<name>.png; baselines move to
baseline-screenshots/{chromium,firefox}/ and the whole tools/screenshots
pipeline (compare/promote/manifest/spec-map/changelog/Discord) keys on
<engine>/<name>. Previously Firefox and Chromium renders of one spec
overwrote each other and Firefox renders were never actually gated.
Seeded from CI run 29421380806 (92 new firefox baselines, +24 chromium
web-suite shots); manifest generated from the baseline tree.

One merged playwright.config.ts (kicad/asyncify/coroutine/perf as
projects); ~25 dead npm scripts dropped. The web suite is gated in CI for
the first time ever (4 rotted specs fixed, 5 broken lib-bridge specs
triaged as fixme in docs/features/web-e2e-rot/); cheap lint step after
npm ci; last 26 blind-sleep violations fixed.

SwiftShader retired: CI Chromium renders WebGL on ANGLE → Mesa llvmpipe
(--use-gl=angle --use-angle=gl --ignore-gpu-blocklist; the blocklist flag
is mandatory — llvmpipe is blocklisted and WebGL is silently unavailable
without it) in BOTH configs. Under WORKERS=4 congestion SwiftShader
transiently failed the first post-board-load draw and the recovery
cascade ended in a silent permanent Cairo fallback — that engine flip was
the "~1.2% changedRatio both directions" occ-export baseline flake.
Validated 160/160 across two 80-repeat rigs; full analysis in
docs/features/wx-parity-bugs/occ-export-context-eviction.md. Chromium
baselines shift slightly on llvmpipe — promote once from the first green
run. Deflakes the new coverage exposed: presence baselines settle before
capture; presence fixtures declare current file formats; perf gets its
own outputDir so CI evidence survives; occ-export settles the board paint
before the export dialog; menu-item waits (waitForRenderedByLabel before
clickMenuItem) in 4 specs + the TESTING.md rule.

Web suite runs the PROD build, in parallel: webServer becomes backend
`start` + the standalone's e2e:preview (build-preview.mjs: link-wasm →
stash the public/wasm symlink aside during vite build, build-demo.mjs's
move — then vite preview as the persistent server). The wasm middleware
serves /wasm/* in preview and emits COOP/COEP/CORP itself (a pthread
worker script's own response must carry COEP or Chrome kills it with
ERR_BLOCKED_BY_RESPONSE). VITE_* flags bake at build time;
VITE_ALLOW_USER_OVERRIDE joins turbo globalEnv. fullyParallel + default
workers: 5.2m → 1.4m. Determinism fixes the parallel run exposed:
shared-page specs become serial groups; locks.spec grabs alice's exact
item via the new kicadCollabTestSelectByUuid hook (cross-tab "first
footprint" order is not a ysync invariant); quit specs poll page.url()
(quit supersedes its own navigation — NS_BINDING_ABORTED on Firefox).
Suite: 51 passed / 12 skipped / 0 failed in 1.6m.

CI-coverage gate (lint:ci-coverage): every tests/**/*.spec.ts must be
reachable from the npm scripts the workflows invoke — scraped from
.github/workflows/, resolved through package.json, coverage asked from
playwright --list itself. Rules: uncovered-spec + orphan-project (with a
documented LOCAL_ONLY_PROJECTS allowlist). Gating next to
lint:determinism; 138 spec files / 13 projects accounted for.

Product fixes kept from the investigations (reachable on real GPUs too):
wx 7799fd1be5 — paint flags clear before dispatch + Invalidate always
propagates; kicad 3dcfea5e45 — SwiftShader pass-boundary flush +
per-instance font texture + first-frame GL-error drain (GAL recovery
recovers instead of falling back to Cairo) + the user-facing eeschema
switch navigates again under __EMSCRIPTEN__ (project-sync's
FaceRegistered gate had rerouted it into the hidden sync player; caught
by the newly-gated web suite).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018eUxiPApHgGiu9NFyQfhAq
2026-07-17 12:21:54 +02:00

165 lines
7 KiB
TypeScript

import { defineConfig, devices } from '@playwright/test';
/**
* E2E config for the React WEB APP (web/standalone editor at :3048 + the
* @pcbjam/backend-example reference backend at :3060), as opposed to the
* merged playwright.config.ts which drives the standalone tool harness HTMLs
* under tests/apps. Kept separate because this suite runs a different server
* stack (`pnpm dev` two-server turbo), its own globalSetup health checks and a
* fixed base URL.
*
* These tests exercise the real web open paths: navigate to /:scope/projects/:name/<file>,
* let WasmTool boot the tool in-document (boot.ts), drive the project into MEMFS
* and auto-open the file (open-flow.ts via Module.kicadOpenFile), and assert the
* editor loaded wizard-free.
*
* The backend serves a single project off the local filesystem — no DB, no
* seeding. The suite runs against the PRODUCTION stack: the standalone is
* `vite build`-built and served by `vite preview` (build-preview.mjs — wasm
* stays out of dist/, served same-origin at /wasm via the serveWasm plugin),
* and the backend runs its no-watch `start` script. Locally an already-running
* stack on the ports is reused as before (the common dev case); CI always
* cold-starts both servers with the env below, pointing PROJECT_DIR at the
* committed tests/fixtures/demo project (slug "demo").
*
* All projects use the BUNDLED browsers so the suite runs identically on CI
* (no system-Chrome channel; ANGLE/Mesa-llvmpipe GL for GPU-less runners).
*/
const FRONTEND_URL = process.env.WEB_APP_URL ?? 'http://localhost:3048';
// Keep the cold-started stack consistent with WEB_APP_URL overrides (e.g. a
// sibling worktree squatting :3048): vite binds the URL's port and the backend
// allows that origin, so overriding one env var relocates the whole frontend.
const FRONTEND_PORT = new URL(FRONTEND_URL).port || '3048';
// Backend counterpart — same override story for :3060 squatters. BACKEND_URL
// is the var global-setup-web.ts already probes; the cold-started reference
// backend binds its port and the editor is pointed at it.
const BACKEND_URL = process.env.BACKEND_URL ?? 'http://localhost:3060';
const BACKEND_PORT = new URL(BACKEND_URL).port || '3060';
// Bundled Chromium on GPU-less CI: WebGL via ANGLE over desktop GL (Mesa
// llvmpipe under the Xvfb display CI provides) — NOT SwiftShader, which under
// multi-worker contention transiently fails WebGL calls and drove KiCad's GAL
// error-recovery into silent Cairo fallbacks (the occ-export flake; see
// docs/features/wx-parity-bugs/occ-export-context-eviction.md). Keep this in
// lockstep with CHROMIUM_CI_ARGS in playwright.config.ts. --ignore-gpu-blocklist
// is mandatory: llvmpipe is on Chromium's software-GL blocklist and WebGL is
// silently unavailable without it.
const CHROMIUM_CI_ARGS = process.env.CI
? {
launchOptions: {
args: ['--use-gl=angle', '--use-angle=gl', '--ignore-gpu-blocklist'],
},
}
: {};
// Headless Firefox can't create a GL context on GPU-less CI VMs — run headed
// under Xvfb (the CI step wraps in xvfb-run) with the no-GPU blocklist bypassed,
// same as the kicad-firefox project in playwright.config.ts.
const FIREFOX_CI_OPTS = process.env.CI
? {
headless: false,
launchOptions: { firefoxUserPrefs: { 'webgl.force-enabled': true } },
}
: {};
export default defineConfig({
globalSetup: './web/global-setup-web.ts',
testDir: './web',
// On CI, keep Playwright's start-of-run cleanup away from test-results/ — the
// engine-scoped gate screenshots of the main e2e invocation accumulate there.
outputDir: process.env.CI ? 'pw-artifacts/web' : 'test-results',
fullyParallel: true,
forbidOnly: !!process.env.CI,
// retries:0 — same determinism doctrine as the merged config (the suite's
// blind sleeps were replaced with condition waits when it was wired into CI).
retries: 0,
// Parallel workers (Playwright default ≈ 50% of cores), same as the merged
// config — the kicad suite already runs 4 workers of giant wasm runtimes on
// the same class of CI runner. Cross-worker isolation holds: each worker is
// its own browser instance, so BroadcastChannel rooms and IndexedDB stores
// never cross, and presence/comments specs mint per-run users via ?user=.
workers: undefined,
reporter: 'html',
timeout: 180000, // tool wasm download + boot + open can take minutes
use: {
baseURL: FRONTEND_URL,
trace: 'retain-on-failure',
screenshot: 'only-on-failure',
},
projects: [
{
name: 'web-firefox',
testIgnore: /mobile-.*\.spec\.ts/,
use: {
...devices['Desktop Firefox'],
viewport: { width: 1280, height: 720 },
...FIREFOX_CI_OPTS,
},
},
{
name: 'web-chromium',
testIgnore: /mobile-.*\.spec\.ts/,
use: {
...devices['Desktop Chrome'],
viewport: { width: 1280, height: 720 },
...CHROMIUM_CI_ARGS,
},
},
{
// Canvas-only mobile mode (features/mobile): Pixel 7 emulation on the
// bundled Chromium (mobile emulation is Chromium-only).
name: 'web-mobile',
testMatch: /mobile-.*\.spec\.ts/,
use: { ...devices['Pixel 7'], ...CHROMIUM_CI_ARGS },
},
],
// Two independent prod servers, started in parallel and health-checked on
// their URLs. cwd (not --dir/--filter from tests/): corepack resolves pnpm
// from the packageManager pin in web/package.json only when the process
// STARTS in web/ — launched from tests/ it falls back to latest pnpm, which
// needs a newer Node than CI's. Locally an already-running stack is reused
// (the common dev case — note that stack must have set the VITE_* flags
// below itself, and a dev server is accepted too).
webServer: [
{
// Reference backend, prod mode (tsx src/server.ts, no watch).
command: 'pnpm --filter @pcbjam/backend-example start',
cwd: '../web',
url: `${BACKEND_URL}/health`,
reuseExistingServer: !process.env.CI,
timeout: 180000,
env: {
...process.env,
// resolved against web/backend/ (the backend's cwd)
PROJECT_DIR: '../../tests/fixtures/demo',
PORT: BACKEND_PORT,
CORS_ORIGIN: FRONTEND_URL,
},
},
{
// Standalone editor: vite build → vite preview (build-preview.mjs).
// The VITE_* flags are baked in at BUILD time here (the dev server used
// to read them live): API base, the browser-local IDB project store the
// missing-file tool-switch spec needs, and per-run e2e identity via
// ?user= (0009). turbo.json lists them in globalEnv so the build cache
// re-keys when they change.
command: 'pnpm --filter @pcbjam/standalone e2e:preview',
cwd: '../web',
url: FRONTEND_URL,
reuseExistingServer: !process.env.CI,
// Cold build (turbo: shared + sync-client + standalone) + preview boot.
timeout: 600000,
env: {
...process.env,
STANDALONE_PORT: FRONTEND_PORT,
VITE_API_BASE_URL: BACKEND_URL,
VITE_LOCAL_PROJECTS: 'idb',
VITE_ALLOW_USER_OVERRIDE: '1',
},
},
],
});