Repository navigation
[v1.x] test(server): read SSE streams until expected events arrive instead of assuming one fetch chunk - #3174
Draft
MuhammadFaizan-prog wants to merge 1 commit into
Conversation
…t of modelcontextprotocol#2662) fetch may deliver separately written SSE events in separate chunks (Node 26.7 does), so the batch and replay tests read until the expected event text arrives instead of asserting on a single read(). Refs modelcontextprotocol#2661 Co-authored-by: jstar0 <54024410+jstar0@users.noreply.github.com>
|
commit: |
This branch has not been deployed
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.
v1.x port of #2662. Refs #2661.
Problem
Two tests in
test/server/streamableHttp.test.tscallreader.read()once and then assert on more than one SSE event:should handle batch request messages with SSE stream for responses: expects both thereq-1andreq-2responses in the first chunk.should store and replay MCP server tool notifications: expects the replayed notification in the first chunk after reconnecting withLast-Event-ID.fetchgives no guarantee that separately written SSE events share a chunk. On Node 26.7.0 they arrive in separate reads, so onv1.xas it is:The transport behaves correctly; only the tests assume coalescing. The same file passes on Node 22.
Change (test-only)
Adds the same
readSSEUntil(response, predicate, timeoutMs = 2000)helper as #2662: it accumulates decoded chunks until the predicate holds, the stream ends, or the timeout cancels the reader, then releases the lock. It is used at the three single-read sites in the two tests. The replay test now cancels throughsseResponse.body.cancel()because the helper has released the reader. No production code changes, so no changeset.I kept this to the two failing tests. The extra cleanup in #2662's follow-up commit (folding the other inline read loops into the helper) is left out to keep the v1.x diff minimal.
Testing
npm run typecheck, Prettier and ESLint are clean on the changed file.Credit
The failure report, repro and the read-until-predicate approach come from @jstar0 (#2661). The helper is the one from #2662. @Parithosh-Varma and @shi-felix also prepared ports for
main.AI disclosure
I used an AI assistant (Hark) to reproduce the failure on Node 26 and to draft this patch and description. I reviewed every line, ran the tests myself, and can explain the change.