Skip to content

test(e2e): hermeticize Playwright E2E and visual suites - #319

Merged
jgindin merged 5 commits into
mainfrom
pr1-e2e-stabilization
Nov 16, 2026
Merged

jgindin merged 5 commits into
mainfrom
pr1-e2e-stabilization

Conversation

@jgindin

@jgindin jgindin commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Description

Summary

  • Hermeticize the Playwright E2E and visual regression suites: mock
    renderers.json via context.route to serve local sample URLs and abort
    any external GitHub Pages requests.
  • Build bridge and catalog artifacts deterministically before Playwright
    runs, cap local workers to 4, disable interactive HTML reports, and add
    no-sandbox launch flags.
  • Synchronize Monaco editor text updates without arbitrary timeouts and
    prioritize JSON syntax markers over semantic schema errors, backfilling
    syntax line coordinates when V8 parse errors omit offsets.
  • Replace console-log races with addInitScript postMessage wire-taps, add
    stub iframe GET_CATALOG responders in component gallery specs, and guard
    localStorage.clear() with a sessionStorage sentinel across reloads.
  • Filter out-of-bounds in-flight resize reports on uncommitted demo cards
    and extend the freshCommit convergence window to 6000ms.

Commits

73d4f115 fix(shell): prioritize monaco syntax errors and card sizing convergence
9fb00250 test(e2e): hermeticize Playwright E2E and visual suites
2adf3246 test(e2e): remove guest listener leak in setMonacoContent

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):

Verification

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 passed
  • yarn test, yarn lint, yarn tsc, yarn prettier:check,
    yarn generate:demos:check all exit 0

Pre-launch Checklist

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread shell/e2e/helpers.ts Resolved
Comment thread shell/src/app/utils/json.ts Resolved
@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

⚡ A2UI Composer PR Preview

Your automated preview is successfully live (commit acf707d):
👉 Launch PR Preview

Note: This environment will be wiped automatically when the PR is merged or closed.

@wrenj wrenj left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@jgindin jgindin Nov 13, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread shell/e2e/helpers.ts
catalogId: '${catalogId}',
title: '${title}',
description: 'Stub Catalog Description',
version: '${version}',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@jgindin jgindin Nov 13, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in commit d5f4f1c on stacked PR #325 (pr7-qa-cleanup): serialized catalogPayload via JSON.stringify(catalogPayload) inside stubRendererHtml instead of interpolating raw strings.

{
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",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@jgindin jgindin Nov 13, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in commit d5f4f1c on stacked PR #325 (pr7-qa-cleanup): extracted the E2E sample preflight build check into scripts/ensure-e2e-samples.mjs (including samples/react-slack-catalog/dist) and added "build:samples" to root package.json.

Comment thread shell/e2e/helpers.ts Outdated
Comment on lines +201 to +209
const timeoutId = setTimeout(() => {
window.removeEventListener('message', handler);
resolve();
}, timeoutMs);
window.addEventListener('message', handler);
}),
10_000,
)
.catch(() => {});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +176 to +178
if (ch === ',') {
i++;
state = 'value';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread shell/e2e/helpers.ts Outdated
}

/** Local renderers configuration for hermetic test mocking. */
export const LOCAL_RENDERERS_PAYLOAD = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread shell/e2e/helpers.ts
* 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> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines 516 to 520
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)};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 653254d8: simplified getFirstErrorMarker(syntaxOnly) into a flag-free getFirstSyntaxErrorMarker() and removed the schema-marker fallback branch and its spec.

Comment on lines +50 to +52
await expect(inspector).toHaveScreenshot('message-inspector-drawer.png', {
maxDiffPixelRatio: process.env['CI'] ? 0.02 : 0.05,
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 653254d8: removed the redundant maxDiffPixelRatio overrides in message-inspector.visual.ts so it uses the global default from playwright.config.ts.

@jgindin
jgindin added this pull request to stack #332 November 16, 2026 13:16
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.
@jgindin
jgindin force-pushed the pr1-e2e-stabilization branch from 2adf324 to 653254d Compare November 16, 2026 21:21
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.
@jgindin
jgindin merged commit b763258 into main Nov 16, 2026
15 checks passed
@jgindin
jgindin deleted the pr1-e2e-stabilization branch November 16, 2026 22:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants