Skip to content

fix: preserve MockAgent interceptors for legacy global fetch - #5648

Merged
mcollina merged 1 commit into
nodejs:mainfrom
pacocartones:codex/mockagent-global-fetch
Aug 5, 2026
Merged

fix: preserve MockAgent interceptors for legacy global fetch#5648
mcollina merged 1 commit into
nodejs:mainfrom
pacocartones:codex/mockagent-global-fetch

Conversation

@pacocartones

Copy link
Copy Markdown
Contributor

Summary

Fixes the regression where MockAgent interceptors are bypassed by Node.js global fetch after setGlobalDispatcher().

Dispatcher1Wrapper correctly forces legacy consumers onto HTTP/1.1 with allowH2: false. The internal Agent then uses its #http1-only pool key, but MockAgent only initialized mocks under the normal origin key. That allowed the internal agent to create a plain pool and make a real request even after disableNetConnect().

This creates the HTTP/1.1-only mock dispatcher before delegation and shares the registered interceptors with the normal-origin mock dispatcher. The legacy bridge keeps its HTTP/1.1 guarantee; only the mock selection path is fixed.

Regression coverage

The new subprocess test uses Node.js global fetch, a MockAgent, and disableNetConnect(). It expects the configured JSON response, so it fails if the request escapes the mock.

Validation

  • npm run lint -- lib/mock/mock-agent.js test/node-test/global-dispatcher-version.js
  • node --test test/node-test/global-dispatcher-version.js
  • node --test test/mock-pool.js
  • git diff --check

Fixes #5036.

Signed-off-by: pacocartones <manusanchezhl@gmail.com>
@codecov-commenter

codecov-commenter commented Aug 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.44%. Comparing base (c8d80e6) to head (5499b8c).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5648      +/-   ##
==========================================
+ Coverage   93.42%   93.44%   +0.01%     
==========================================
  Files         110      110              
  Lines       38710    38722      +12     
==========================================
+ Hits        36165    36182      +17     
+ Misses       2545     2540       -5     

☔ View full report in Codecov by Harness.
📢 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.

@pacocartones

Copy link
Copy Markdown
Contributor Author

CI triage for the current head:\n\n- Both CodeQL analyses fail during autobuild because the repository configuration requires 4.37.3 while the runner is using 4.36.2; this is before analysis of this PR's change.\n- The Node 24 coverage job has one failing file: est/http2-request-never-settles.js. It is outside this diff and is the known high-churn HTTP/2 test being isolated in #5643.\n\nThe focused MockAgent regression and coverage remain green. I have not retried the unrelated jobs to avoid adding CI noise.

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm

@mcollina
mcollina merged commit 4ae29b2 into nodejs:main Aug 5, 2026
35 of 38 checks passed
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