Skip to content

Playwright e2e: optional HAR record/replay for *.cbioportal.org#5579

Draft
alisman wants to merge 1 commit into
cBioPortal:masterfrom
alisman:playwright-har-replay
Draft

Playwright e2e: optional HAR record/replay for *.cbioportal.org#5579
alisman wants to merge 1 commit into
cBioPortal:masterfrom
alisman:playwright-har-replay

Conversation

@alisman

@alisman alisman commented May 15, 2026

Copy link
Copy Markdown
Collaborator

Summary

Wires Playwright's built-in context.routeFromHAR into the e2e fixtures so backend traffic to *.cbioportal.org can optionally be served from per-test HAR files instead of the live network.

The goal is reducing screenshot flakiness caused by API response timing variance — same test, same code, but the DOM lands in a slightly different state at screenshot time depending on the order N XHRs finished in. Replaying from a HAR makes that byte-identical run to run.

Opt-in via env var:

PW_HAR_MODE=record pnpm exec playwright test tests/config.spec.ts
PW_HAR_MODE=replay pnpm exec playwright test tests/config.spec.ts
# unset → fixture is a no-op (today's behaviour)

URL scope is restricted to *.cbioportal.org, so the local frontend bundle (localhost:3000 in LOCALDEV) and third-party APIs (OncoKB, Genome Nexus) flow through untouched — the HAR captures only the variable-timing backend, not the code under test.

Why this over the earlier proxy attempt

A previous spike (#5578) put mitmproxy in front of the suite. Same goal but it interacted badly with LOCALDEV mode in CI (response replays mangled enough flows that the React app didn't hydrate). routeFromHAR is Playwright-native, requires no separate proxy process, and uses Playwright's own request interception path, which has known-good behaviour with ignoreHTTPSErrors and chromium-headless-shell.

Validated locally

  • config.spec.ts record then replay: 4/4 pass on both passes.
  • patient-screenshot.spec.ts: re-baselined under replay, then three back-to-back replays produced byte-identical pixels every time. The flaky screenshot diff that historically wanders between 0 % and 2 % goes to a flat 0 % under HAR replay.
  • With PW_HAR_MODE unset, behaviour is identical to today (the fixture short-circuits before installing any route).

What's NOT in this PR

  • No HAR fixtures committed. Each test's HAR is ~5 MB; committing them naïvely would balloon the repo. The directory is gitignored. I'd like a decision on persistence strategy (commit / git-LFS / refresh-on-schedule-and-cache / external blob store) before we flip CI to replay mode.
  • No CI integration. Default behaviour (no env var) leaves the suite hitting the real backend, same as today. Once we have fixtures somewhere durable, remote_e2e_shards can set PW_HAR_MODE=replay to lock in determinism.
  • No regenerated __snapshots__/. Canonical screenshot baselines under __snapshots__/ were captured against the live network, so they won't match HAR-replayed renders pixel-perfectly. A follow-up should regenerate them under PW_HAR_MODE=replay in Docker once we have a fixture plan.

Test plan

  • Confirm fixture is a no-op when PW_HAR_MODE is unset (existing test flow unchanged)
  • Try PW_HAR_MODE=record on a spec; confirm tests/__hars__/<spec>/<test-slug>.har appears
  • Try PW_HAR_MODE=replay on the same spec; confirm tests pass
  • Run replay multiple times in a row; confirm determinism

🤖 Generated with Claude Code


View in Codesmith
Need help on this PR? Tag @codesmith with what you need.

  • Let Codesmith autofix CI failures and bot reviews

Wire context.routeFromHAR into the existing fixtures so cbioportal API
responses can be served from disk for byte-stable replays. Off by
default; opt in per-run with PW_HAR_MODE=record to capture or
PW_HAR_MODE=replay to serve from the captured HAR. URL scope is
restricted to *.cbioportal.org so the local frontend bundle and
third-party APIs (OncoKB, Genome Nexus) flow through untouched.

Per-test HAR (tests/__hars__/<spec>/<test-slug>.har) rather than
per-spec because routeFromHAR's update mode overwrites on context
close, which would clobber across tests sharing a file.

Validated locally on patient-screenshot.spec.ts: three back-to-back
replays produced byte-identical screenshots. HAR fixtures are
gitignored for now (~5 MB per test); committing/LFS strategy is left
to a follow-up.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 15, 2026 16:12

Copilot AI 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.

Pull request overview

Adds an opt-in HAR record/replay mechanism to the Playwright e2e fixture, routing *.cbioportal.org traffic through per-test HAR files when PW_HAR_MODE=record|replay is set. With the env var unset, the fixture is a no-op.

Changes:

  • Extend the context test fixture in fixtures.ts with setupHar() that calls context.routeFromHAR scoped to *.cbioportal.org, with per-test HAR paths derived from testInfo.
  • Gitignore the tests/**/__hars__/ directory.
  • Document the workflow in the e2e README.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
end-to-end-test-playwright/fixtures.ts Adds HAR mode handling and per-test HAR path generation, wired into the context fixture.
end-to-end-test-playwright/.gitignore Ignores recorded HAR fixtures.
end-to-end-test-playwright/README.md Documents the optional HAR record/replay workflow.

@netlify

netlify Bot commented May 15, 2026

Copy link
Copy Markdown

Deploy Preview for cbioportalfrontend ready!

Name Link
🔨 Latest commit 5872414
🔍 Latest deploy log https://app.netlify.com/projects/cbioportalfrontend/deploys/6a0745fb4f34b10008a88f27
😎 Deploy Preview https://deploy-preview-5579.preview.cbioportal.org
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@alisman alisman marked this pull request as draft May 15, 2026 19:54
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.

2 participants