Skip to content

fix: make MockAgent work with protocol-aware global dispatchers#5052

Open
mcollina wants to merge 5 commits intomainfrom
fix/5036-mockagent-global-fetch
Open

fix: make MockAgent work with protocol-aware global dispatchers#5052
mcollina wants to merge 5 commits intomainfrom
fix/5036-mockagent-global-fetch

Conversation

@mcollina
Copy link
Copy Markdown
Member

@mcollina mcollina commented Apr 17, 2026

Summary

Fixes the regression where setGlobalDispatcher(new MockAgent()) no longer intercepts Node.js native fetch() requests.

The original regression happened after legacy global-dispatcher consumers started forcing allowH2: false. That made Agent route those requests through a separate HTTP/1-only path, while MockAgent only registered mocks for the default origin path.

This PR does more than mirror a second mock bucket:

  • makes Agent explicitly protocol-aware internally by separating
    • default dispatcher entries
    • HTTP/1-only dispatcher entries
  • adds internal helper symbols for querying and mutating protocol-specific dispatcher entries
  • updates MockAgent to use those helpers instead of sharing or depending on Agent's raw pool map
  • keeps mock interceptor state attached to the logical mock registry while registering protocol-specific dispatchers into Agent
  • adds regression coverage for native fetch() and protocol-specific mock registration

This removes the brittle coupling between Agent and MockAgent around the HTTP/1-only path and preserves native fetch() interception.

Fixes: #5036

@mcollina mcollina force-pushed the fix/5036-mockagent-global-fetch branch from 12974fe to 5f15b44 Compare April 17, 2026 14:00
@mcollina mcollina changed the title fix: preserve MockAgent interception for native fetch fix: make MockAgent work with protocol-aware global dispatchers Apr 17, 2026
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.87006% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.08%. Comparing base (d64e7bb) to head (72c3bad).
⚠️ Report is 10 commits behind head on main.

Files with missing lines Patch % Lines
lib/mock/mock-agent.js 97.75% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5052      +/-   ##
==========================================
+ Coverage   93.03%   93.08%   +0.04%     
==========================================
  Files         110      110              
  Lines       35786    35934     +148     
==========================================
+ Hits        33294    33449     +155     
+ Misses       2492     2485       -7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@metcoder95
Copy link
Copy Markdown
Member

just conflicts on files

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.

MockAgent as global dispatcher broken since version 8.0.3

3 participants