Repository navigation
test(node): read SSE streams until expected events arrive - #3099
Open
ruqayya-parveen wants to merge 1 commit into
Open
ruqayya-parveen wants to merge 1 commit into
ruqayya-parveen wants to merge 1 commit into
Conversation
Several streamableHttp tests called reader.read() once and asserted that multiple SSE events shared one fetch chunk. On Node 26 fetch can deliver them in separate chunks, so the tests failed although the transport was correct. Add a readSSEUntil helper and use it in the two affected tests. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
@modelcontextprotocol/client
@modelcontextprotocol/codemod
@modelcontextprotocol/core
@modelcontextprotocol/server
@modelcontextprotocol/server-legacy
@modelcontextprotocol/express
@modelcontextprotocol/fastify
@modelcontextprotocol/hono
@modelcontextprotocol/node
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.
Several streamableHttp tests called
reader.read()once and asserted that multiple SSE eventsshared one fetch chunk. On Node 26 fetch can deliver them in separate chunks, so the tests
failed although the transport was correct. Add a
readSSEUntilhelper and use it in the twoaffected tests.
Fixes #2661.
Motivation and Context
packages/middleware/node/test/streamableHttp.test.tsassumed that every SSE event written bythe server arrives in the first
reader.read()result. That is a property of how the runtimechunks the response body, not of the transport. On Node v26.7.0 the events can be split across
chunks, and two tests fail before reading the later events:
should handle batch request messages with SSE stream for responsesreads only thereq-1event and fails before
req-2.should store and replay MCP server tool notificationsreads an earlier{}event and failsbefore "Second notification from MCP server".
The change:
readSSEUntil(reader, expected, timeoutMs)test helper. It reads until theaccumulated text contains every expected string. It throws, including the text received so far,
if the stream ends early or the 5s timeout is hit.
Last-Event-IDfrom the event that carries the "Firstnotification" message. Before, it took the first
id:in the chunk, which could belong to theearlier
{}event.Test-only change. No library code is touched, so no changeset.
How Has This Been Tested?
pnpm build:allpnpm --filter @modelcontextprotocol/node test -- test/streamableHttp.test.tspasses (all 5test files in the package, 105 tests) on Node v22.22.2.
prettier --checkis clean on the changed file.original failure. The helper removes the single-chunk assumption, but confirmation on Node 26
(locally or in CI) would be welcome.
Breaking Changes
None. Test-only change.
Types of changes
Checklist
Additional context
Only the two tests named in the issue are changed. Other tests in this file also call
reader.read()once, but they don't assert on several events at a time, so I left them aloneto keep the change small.
push, the pre-push hook will have run lint, build and typecheck, so tick it only if the hook
passed.