fix(mock): emit request body lifecycle hooks#5367
Open
marko1olo wants to merge 4 commits into
Open
Conversation
Mock dispatch now forwards request bodies through onBodySent/onRequestSent before resolving the mocked reply, including async iterable bodies. Co-authored-by: OpenAI Codex <codex@openai.com> Signed-off-by: marko1olo <barsukdana@gmail.com>
Do not continue request body lifecycle processing or resolve a mock response after the mock request controller has been aborted. Co-authored-by: OpenAI Codex <codex@openai.com> Signed-off-by: marko1olo <barsukdana@gmail.com>
Signed-off-by: marko1olo <barsukdana@gmail.com>
Signed-off-by: marko1olo <barsukdana@gmail.com>
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.
This relates to...
Fixes #3843.
Rationale
MockAgentdispatches currently skip request body lifecycle callbacks, so code that works with real dispatchers cannot be tested accurately with mocks. The mock dispatcher should emitonBodySent(chunk)for request body chunks andonRequestSent()once request body dispatch has completed, while preserving the existing mocked reply behavior.Changes
Features
N/A
Bug Fixes
onBodySent(chunk)andonRequestSent()fromMockAgentdispatches before resolving the mocked replyonResponseErrorBreaking Changes and Deprecations
N/A
Validation
node --test --test-timeout=30000 --test-name-pattern "request body lifecycle hooks|request sent hook|async iterable request body errors|replayed async iterable bodies|match request bodies when lifecycle hooks|replay async iterable request bodies|request body lifecycle hook errors|delayed replies after request sent aborts|stop reading async iterable request bodies|request start aborts" test/mock-agent.jsnode --test --test-timeout=30000 --test-name-pattern "dispatch onBodySent" test/node-test/client-dispatch.jsnpm run lint -- --no-cache lib/mock/mock-utils.js test/mock-agent.jsgit diff --check origin/main..HEADNote:
npx borp --timeout 180000 --expose-gc -p "test/mock-agent.js"did not complete locally before the wrapper timeout in this Windows environment, so I used focused Node test runs for the changed behavior and adjacent dispatcher behavior.AI-assisted contribution: implemented with OpenAI Codex and reviewed locally before submission.
Status