test(e2e): mock static asset endpoints to remove from allowlist (MMQA-1778)#29576
Conversation
…-1778) Adds default mocks for three categories of static asset / health-check requests, then removes the corresponding allowlist entries. - HEAD https://clients3.google.com/generate_204 → 204 (RN NetInfo reachability probe; flows through global.fetch via shim.js) - GET .../contract-metadata/<branch>/images/*.svg → minimal SVG - GET .../nativeCurrencyLogos/*.svg → minimal SVG Uses regex matchers so the mocks cover the whole category — new tokens, branch renames, and platform-subset divergence don't reintroduce live requests. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsE2E Test Selection:
Impact: DEFAULT_MOCKS is used in FixtureHelper.ts which is the core fixture infrastructure for ALL E2E tests. The change converts live network calls to deterministic mocks, which is an improvement but could affect tests that display token icons or rely on the Google connectivity check. Why these tags:
The change is low-risk (improving test determinism) but since it touches DEFAULT_MOCKS used globally, a representative cross-section of tests should validate the mocking infrastructure works correctly. Performance Test Selection: |
|



Description
Tier 2 of MMQA-1364 (allowlist reduction). Adds default mock matchers for three categories of static asset / health-check requests, then removes the corresponding entries from
mock-e2e-allowlist.ts.^https://clients3\.google\.com/generate_204$(HEAD)204 No Content, empty body^https://raw\.githubusercontent\.com/MetaMask/contract-metadata/[^/]+/images/.+\.svg$(GET)200, minimal<svg xmlns="http://www.w3.org/2000/svg"/>^https://token\.api\.cx\.metamask\.io/assets/nativeCurrencyLogos/.+\.svg$(GET)200, minimal SVGWhy regex, not exact URLs. The previous allowlist enumerated five specific token icons that today's specs happened to load. Any new spec, new default token, branch rename (
master→main), or platform-subset divergence would reintroduce live requests. Regex matchers cover the entire category (any branch, any future token icon) with one entry — a one-time fix instead of a moving target.generate_204origin. Confirmed it is fired by@react-native-community/netinfo'sInternetReachability._checkInternetReachabilityvia JS-layerfetch. That path is patched byshim.js, so the request reaches mockttp at/proxy?url=…and the matcher fires. (Method isHEAD, hence the newHEADfield onDEFAULT_MOCKS.)Files changed
tests/api-mocking/mock-responses/defaults/static-assets.ts— new default mock file with the three matcherstests/api-mocking/mock-responses/defaults/index.ts— imported and spread intoDEFAULT_MOCKS.GET+ newHEADfieldtests/api-mocking/mock-e2e-allowlist.ts— removed 7 entries (1 generate_204, 5 GitHub raw token SVGs, 1 token.api nativeCurrencyLogos ethereum.svg)Out of scope
https://api.avax.network/ext/bc/C/rpc— Tier 4 investigationhttps://metamask.github.io/test-dapp/metamask-fox.svg— handled by MMQA-1367Changelog
CHANGELOG entry: null
Related issues
MMQA-1778 — parent epic MMQA-1364
Manual testing steps
Screenshots/Recordings
Before
tests/api-mocking/mock-e2e-allowlist.tsallowlisted 7 entries that bypassedvalidateLiveRequests():What this meant on every E2E run:
HEAD https://clients3.google.com/generate_204and Google answered. The allowlist silenced the warning, sovalidateLiveRequests()did not flag it.@metamask/notification-services-controller).token.apiSVG went live whenever the Ethereum native-currency logo was loaded (referenced inapp/constants/urls.ts:144and the Ramp Quotes constants).After
Allowlist with the 7 entries gone —
ALLOWLISTED_URLSdrops from 16 to 9:What happens on every E2E run now:
204with empty body. NetInfo'sreachabilityTest(response.status === 204) passes; the wallet sees the network as reachable. No live request to Google.<svg xmlns="http://www.w3.org/2000/svg"/>). Icons render (visual fidelity not asserted in E2E). No live request toraw.githubusercontent.comfor any token icon — current or future.token.api.cx.metamask.iofor any chain's logo.validateLiveRequests()records zero leaks for these endpoints.Pre-merge author checklist
Performance checks (if applicable)
trace()for usage andaddTokenfor an exampleFor performance guidelines and tooling, see the Performance Guide.
Pre-merge reviewer checklist
Note
Low Risk
Low risk: changes are confined to the E2E mocking layer, replacing live allowlisted static/health-check requests with deterministic mocks (including adding default
HEADmocks).Overview
Reduces E2E live network allowlisting by removing specific static/health-check URLs (Google
generate_204and token SVG icon URLs) frommock-e2e-allowlist.tsand handling them via default mocks instead.Adds
STATIC_ASSETS_MOCKSwith regex-based matchers that return a204forHEAD https://clients3.google.com/generate_204and a minimal SVG for GitHub contract-metadata andtoken.apinative currency logo.svgrequests, and wires these intoDEFAULT_MOCKS(including a newHEADentry).Reviewed by Cursor Bugbot for commit 7c90df2. Bugbot is set up for automated code reviews on this repo. Configure here.