Conversation
beforeRequest is typed as returning CallbackRequestResult | void, and an inspection-only callback that returns nothing is explicitly supported: the in-process path reads its result as modifiedReq?.response, and serialize() sends undefined over the wire for exactly that case. The receiving side didn't expect it. It passed the result straight into withDeserializedCallbackBuffers, which reads .body off it, so every such callback failed the request with "Cannot read properties of undefined (reading 'body')" whenever the rule ran behind an admin server. beforeResponse, a few lines below, already guards this. beforeRequest now does the same, and its channel.request type admits undefined, matching what serialize() declares on the other end.
pimterry
force-pushed
the
main
branch
2 times, most recently
from
September 18, 2026 11:35
6f8b6f5 to
8a5c3fe
Compare
Contributor
Author
|
#214 fixes that flaky test |
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.
The problem
beforeRequestis documented and typed as returning nothing when a callback onlywants to inspect a request:
Both halves of the local path honour that.
PassThroughStepImpl.handlereads theresult as
modifiedReq?.response/modifiedReq?.method, andPassThroughStep.serializedeliberately putsundefinedon the wire for it:The receiving half doesn't.
PassThroughStepImpl.deserializepassed that valuestraight into
withDeserializedCallbackBuffers, which reads.bodyoff it, andtyped the channel response as non-optional so the compiler couldn't see it
coming. Every inspection-only
beforeRequesttherefore failed its request whenthe rule was running behind an admin server:
beforeResponse, a few lines further down, already guards exactly this withif (callbackResult && typeof callbackResult !== 'string').Reproduction
The remote equivalent of the existing test
"should be able to run a callback that checks the request's data":Still reproduces on 4.6.3, the current release.
The change
beforeRequestnow returns the callback result untouched when it is falsy, theway
beforeResponsedoes, and itschannel.requesttype admitsundefined,matching what
serialize()declares on the other end. No behaviour changes forcallbacks that do return a result.
Test plan
test/integration/remote-client.spec.ts, next tothe other
beforeRequestpassthrough tests. Confirmed it fails with theerror above before the fix and passes after.
mocha 'test/**/*.spec.ts'(thetest:nodesuite) on this branch: 830passing, 6 pending. Two full runs each produced one failure, but a
different one each time (
client-error-eventsheader overflow, thenhttps.spec.tsTLS-bypass timeout), and neither touches this code path -they look like pre-existing flakiness in this environment. A run on
unmodified
mainwas clean.