Playwright e2e: optional HAR record/replay for *.cbioportal.org#5579
Draft
alisman wants to merge 1 commit into
Draft
Playwright e2e: optional HAR record/replay for *.cbioportal.org#5579alisman wants to merge 1 commit into
alisman wants to merge 1 commit into
Conversation
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>
Contributor
There was a problem hiding this comment.
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
contexttest fixture infixtures.tswithsetupHar()that callscontext.routeFromHARscoped to*.cbioportal.org, with per-test HAR paths derived fromtestInfo. - 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. |
✅ Deploy Preview for cbioportalfrontend ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Wires Playwright's built-in
context.routeFromHARinto the e2e fixtures so backend traffic to*.cbioportal.orgcan 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:
URL scope is restricted to
*.cbioportal.org, so the local frontend bundle (localhost:3000in 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).routeFromHARis Playwright-native, requires no separate proxy process, and uses Playwright's own request interception path, which has known-good behaviour withignoreHTTPSErrorsand chromium-headless-shell.Validated locally
config.spec.tsrecord 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.PW_HAR_MODEunset, behaviour is identical to today (the fixture short-circuits before installing any route).What's NOT in this PR
remote_e2e_shardscan setPW_HAR_MODE=replayto lock in determinism.__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 underPW_HAR_MODE=replayin Docker once we have a fixture plan.Test plan
PW_HAR_MODEis unset (existing test flow unchanged)PW_HAR_MODE=recordon a spec; confirmtests/__hars__/<spec>/<test-slug>.harappearsPW_HAR_MODE=replayon the same spec; confirm tests pass🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmithwith what you need.