fix: preserve MockAgent interceptors for legacy global fetch - #5648
Merged
Conversation
Signed-off-by: pacocartones <manusanchezhl@gmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
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. |
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
Fixes the regression where
MockAgentinterceptors are bypassed by Node.js globalfetchaftersetGlobalDispatcher().Dispatcher1Wrappercorrectly forces legacy consumers onto HTTP/1.1 withallowH2: false. The internalAgentthen uses its#http1-onlypool key, butMockAgentonly initialized mocks under the normal origin key. That allowed the internal agent to create a plain pool and make a real request even afterdisableNetConnect().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, aMockAgent, anddisableNetConnect(). 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.jsnode --test test/node-test/global-dispatcher-version.jsnode --test test/mock-pool.jsgit diff --checkFixes #5036.