Repository navigation
test(e2e): hermeticize Playwright E2E and visual suites - #319
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces comprehensive updates to the E2E testing infrastructure, including hermetic mocking of local renderers configuration across various test suites, refined Playwright configurations, and improved Monaco editor synchronization. It also enhances JSON syntax error parsing and diagnostic reporting, particularly by prioritizing syntax errors over schema validation errors. The review feedback highlights three key areas for improvement: resolving a potential event listener leak in the E2E helper's message-handling promise, robustly handling IMarker.code when it is returned as an object rather than a string, and restoring a fallback guard in the JSON utility to prevent potential runtime crashes on nullish inputs.
⚡ A2UI Composer PR PreviewYour automated preview is successfully live (commit
|
wrenj
left a comment
There was a problem hiding this comment.
LGTM — hermeticizing Playwright against local sample dev servers, aborting external GitHub Pages traffic, and waiting on RENDER_A2UI / font readiness addresses the main flakiness sources. A few minor non-blocking suggestions inline.
| readNumber() || | ||
| jsonText.startsWith('true', i) || | ||
| jsonText.startsWith('false', i) || | ||
| jsonText.startsWith('null', i) |
There was a problem hiding this comment.
nit (non-blocking): startsWith('true' | 'false' | 'null', i) matches prefixes of invalid bare identifiers like trueish (advancing i past true so the scanner fails at 'i' instead of 't', which won't match rawToken === 't'). Checking that the keyword is not followed by an identifier character (e.g. /^(?:true|false|null)(?![A-Za-z0-9_$])/) keeps the token start aligned with V8's error token.
There was a problem hiding this comment.
Addressed in commit d5f4f1c on stacked PR #325 (pr7-qa-cleanup) (to avoid dismissing your approval on #319): added readKeyword() checking !/[A-Za-z0-9_$]/.test(jsonText[i + kw.length] ?? '') before advancing past true, false, or null, plus unit tests for trueish, falsehood, and nullable in json.spec.ts.
| catalogId: '${catalogId}', | ||
| title: '${title}', | ||
| description: 'Stub Catalog Description', | ||
| version: '${version}', |
There was a problem hiding this comment.
nit (non-blocking): Interpolating ${title} (and catalogId / version) directly inside single-quoted JS in the template string will break script parsing if a test passes a title containing an apostrophe or backslash. Serializing the payload object with JSON.stringify(...) avoids escaping edge cases.
| { | ||
| command: 'corepack yarn start', | ||
| command: | ||
| "node -e \"const fs = require('fs'), {execSync} = require('child_process'); if (!fs.existsSync('../bridge/dist')) execSync('corepack yarn workspace a2ui-bridge build', {stdio: 'inherit'}); if (!fs.existsSync('../samples/ng-basic-catalog/dist')) execSync('corepack yarn workspace ng-basic-catalog build', {stdio: 'inherit'}); if (!fs.existsSync('../samples/lit-basic-catalog/dist')) execSync('corepack yarn workspace lit-basic-catalog build', {stdio: 'inherit'}); if (!fs.existsSync('../samples/react-basic-catalog/dist')) execSync('corepack yarn workspace react-basic-catalog build', {stdio: 'inherit'});\" && npx ng serve", |
There was a problem hiding this comment.
nit (non-blocking): Because this inline node -e guard only checks !fs.existsSync(.../dist) (and omits react-slack-catalog), running npx playwright test locally after editing bridge/ or samples/ can silently serve stale build artifacts. Moving this preflight into a small helper script (or running workspace builds when !reuseExistingServer) would be easier to maintain.
| const timeoutId = setTimeout(() => { | ||
| window.removeEventListener('message', handler); | ||
| resolve(); | ||
| }, timeoutMs); | ||
| window.addEventListener('message', handler); | ||
| }), | ||
| 10_000, | ||
| ) | ||
| .catch(() => {}); |
There was a problem hiding this comment.
This wait resolves on timeout (and is wrapped in .catch(() => {})), so when the preview never re-renders the helper sleeps 10s and moves on, which hides regressions. willDispatchRender already filters out edits that won't render, so a missing RENDER_A2UI should fail. Could the timeout reject, attaching once the preview iframe has loaded (so guestFrame isn't null or mid-navigation from about:blank)? Also, nothing passes awaitRender, so that option can go.
There was a problem hiding this comment.
Fixed in 653254d8: setMonacoContent now waits for the preview iframe to load before attaching its listener and rejects on RENDER_A2UI timeout instead of swallowing timeouts, and the unused awaitRender option has been removed.
| if (ch === ',') { | ||
| i++; | ||
| state = 'value'; |
There was a problem hiding this comment.
findFirstInvalidTokenOffset accepts trailing commas in arrays ([1,]): after , inside [ the state goes back to value, which accepts ]. V8 gives no line/column for that error, so short arrays get no error position and nested ones ([[1,],\n]]) point at the wrong line. Splitting value_or_end (after [) from value (after ,), like objects do with prop_or_end / prop, fixes it.
There was a problem hiding this comment.
Fixed in 653254d8: findFirstInvalidTokenOffset now separates value_or_end (immediately after [) from value (after ,), rejecting trailing commas in arrays and reporting the token offset accurately.
| } | ||
|
|
||
| /** Local renderers configuration for hermetic test mocking. */ | ||
| export const LOCAL_RENDERERS_PAYLOAD = { |
There was a problem hiding this comment.
Optional: LOCAL_RENDERERS_PAYLOAD duplicates src/config.json and has already drifted (no slack entry, an extra angular id, renamed defaults), so mocked specs run against a renderer list production doesn't have. Could we load the real file (readFileSync(new URL('../src/config.json', import.meta.url), 'utf-8'), since the package is ESM) and map the sample URLs, including slack and *-dev, to RENDERER_URLS? Also, nothing fetches renderers.json, so that route can go.
There was a problem hiding this comment.
Fixed in 653254d8: LOCAL_RENDERERS_PAYLOAD is now derived dynamically from src/config.json (mapping sample URLs including slack and *-dev to RENDERER_URLS), and the unused renderers.json route interception was removed.
| * Intercepts config.json and renderers.json requests to serve local renderer endpoints | ||
| * and installs a fail-fast route abort on any external GitHub Pages traffic. | ||
| */ | ||
| export async function mockLocalRenderersConfig(target: Page | BrowserContext): Promise<void> { |
There was a problem hiding this comment.
Optional: since hermetic runs are the goal, could this be on by default instead of opt-in per file? An {auto: true} fixture in e2e/fixtures.ts that calls mockLocalRenderersConfig(context) would cover new specs and the ones that don't mock today, and remove the 26 per-file beforeEach blocks. A resetStorageOnce(page, seed?) helper would do the same for the __a2ui_e2e_cleared__ sentinel, which is now in 8 files (plus init_cleared in settings-and-configuration).
There was a problem hiding this comment.
Fixed in 653254d8: added an {auto: true} fixture in shell/e2e/fixtures.ts calling mockLocalRenderersConfig(context) and extracted resetStorageOnce(...) in shell/e2e/helpers.ts, replacing the duplicated per-file beforeEach hooks.
| return widening({...next, frame: recordHeight(next.frame, report, height)}, widened); | ||
| } | ||
| } | ||
| if (next.kind === 'widening' && laidOutElsewhere(next.width, report)) return next; | ||
| if (laidOutElsewhere(next.width, report)) return next; | ||
| next = {...next, frame: recordHeight(next.frame, report, height)}; |
There was a problem hiding this comment.
Optional: in onResizeUncommitted, the laidOutElsewhere check runs after the contentReady === false and recordOverflow branches, so a stale report from the previous width can still record a height or start widening. Should it move up to right after height === null, like in onResizeCommitted?
There was a problem hiding this comment.
Fixed in 653254d8: moved the laidOutElsewhere check up before the contentReady === false and recordOverflow branches in onResizeUncommitted (matching onResizeCommitted), with unit test coverage added in demo-card-sizing.spec.ts.
| * is present, avoiding premature fallback to schema validation markers. | ||
| */ | ||
| getFirstErrorMarker(): {line: number; column: number} | null { | ||
| getFirstErrorMarker(syntaxOnly = false): {line: number; column: number} | null { |
There was a problem hiding this comment.
Nit: both callers pass syntaxOnly = true, so the schema-marker fallback only runs in the spec. Could this become a flag-free getFirstSyntaxErrorMarker() and the fallback branch and its test go away?
There was a problem hiding this comment.
Fixed in 653254d8: simplified getFirstErrorMarker(syntaxOnly) into a flag-free getFirstSyntaxErrorMarker() and removed the schema-marker fallback branch and its spec.
| await expect(inspector).toHaveScreenshot('message-inspector-drawer.png', { | ||
| maxDiffPixelRatio: process.env['CI'] ? 0.02 : 0.05, | ||
| }); |
There was a problem hiding this comment.
Nit: on CI this is the same 0.02 as the global default in playwright.config.ts, so it only loosens local runs. If local font differences are the problem, that applies to every visual spec and belongs in the config; otherwise I'd drop the override.
There was a problem hiding this comment.
Fixed in 653254d8: removed the redundant maxDiffPixelRatio overrides in message-inspector.visual.ts so it uses the global default from playwright.config.ts.
Prioritize Monaco JSON syntax error diagnostics over semantic schema markers, backfill syntax line coordinates from Monaco when V8 parse errors omit offsets, and stabilize demo card layout height calculations.
Hermeticize Playwright end-to-end and visual regression suites to guarantee deterministic, hermetic test runs across local machines and CI containers. - Mock renderers.json via context.route to serve local sample URLs and fail-fast abort any external GitHub Pages network requests. - Ensure deterministic bridge and catalog build scripts before running Playwright suites, cap local workers to 4, disable interactive HTML reports (open: 'never'), and add no-sandbox launch flags. - Synchronize Monaco editor text updates deterministically without arbitrary timeouts, and prioritize syntax markers over schema errors. - Use addInitScript postMessage wire-taps to eliminate console logging races, and provide stub iframe GET_CATALOG handshake responders in component gallery specs. - Protect localStorage.clear() with a sessionStorage sentinel across test route reloads to prevent unexpected unmounts. - Filter out-of-bounds in-flight resize reports on uncommitted demo cards and extend freshCommit convergence window to 6000ms.
The RENDER_A2UI wait raced a guest-side frame.evaluate against a Node-side timeout. When the timeout won, the guest `message` handler stayed attached and the evaluate call remained pending for the life of the page. Move the timeout into the guest callback so the handler is removed and the timer cleared on both the message and timeout paths, and drop the Node-side Promise.race. Addresses review feedback on #319.
- Wait for a loaded preview frame and reject on RENDER_A2UI timeout in setMonacoContent; remove the unused awaitRender option. - Reject trailing commas inside arrays in findFirstInvalidTokenOffset. - Derive LOCAL_RENDERERS_PAYLOAD from src/config.json, drop the unused renderers.json route, add an auto-fixture in e2e/fixtures.ts, and extract resetStorageOnce. - Move laidOutElsewhere before contentReady/overflow in onResizeUncommitted. - Replace getFirstErrorMarker(syntaxOnly) with getFirstSyntaxErrorMarker(). - Remove redundant maxDiffPixelRatio overrides in message-inspector.visual.ts.
2adf324 to
653254d
Compare
Pre-initialize IndexedDB credential stores on a throwaway /a2a load so connectMockAgent() boots with the steady-state [Shell] log entries expected by errors-inspector.png.
Description
Summary
renderers.jsonviacontext.routeto serve local sample URLs and abortany external GitHub Pages requests.
runs, cap local workers to 4, disable interactive HTML reports, and add
no-sandbox launch flags.
prioritize JSON syntax markers over semantic schema errors, backfilling
syntax line coordinates when V8 parse errors omit offsets.
addInitScriptpostMessage wire-taps, addstub iframe
GET_CATALOGresponders in component gallery specs, and guardlocalStorage.clear()with a sessionStorage sentinel across reloads.and extend the
freshCommitconvergence window to 6000ms.Commits
45 files changed, 1208 insertions(+), 164 deletions(-)
Stack
Stacked PR 1/7 — base:
main→ merge in order pr1 → pr7.Each PR in the stack must be merged before the next one, or the next one
must be rebased onto the updated base after its predecessor merges.
Full stack (merge in this order):
pr1-e2e-stabilizationpr2-upgrade-a2ui-depspr3-bridge-v1-0pr4-shell-v1-0-corepr5-shell-v1-0-copilot-rpc-a2apr6-samples-demos-v1-0pr7-qa-cleanupVerification
Run at the tip of the stack (
pr6-samples-demos-v1-0,af82fb68):shell$ yarn e2e-headless→ 229 passed (0 failed, 0 flaky)yarn --cwd shell test:visual→ 19 passedyarn test,yarn lint,yarn tsc,yarn prettier:check,yarn generate:demos:checkall exit 0Pre-launch Checklist