Skip to content

test: cover SSE connections end to end - #9

Merged
koistya merged 1 commit into
kriasoft:mainfrom
zenyr:fix/header-merge
Sep 30, 2026
Merged

koistya merged 1 commit into
kriasoft:mainfrom
zenyr:fix/header-merge

Conversation

@zenyr

@zenyr zenyr commented Mar 21, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

The header-merge fix this PR proposed (merging through Headers so Headers-instance request headers survive) landed in main with #11. This PR now adds the missing end-to-end coverage for it: before this, no test connected over SSE successfully.

  • test/utils/legacy-sse-server.ts: a minimal legacy HTTP+SSE MCP server. The SDK v2 server package no longer ships one. GET /sse announces a POST endpoint, and responses come back over the stream.
  • A new test in src/mcp-client.test.ts connects over SSE and checks that:
    • server headers reach both the event stream (GET) and the POSTs;
    • the SDK's own headers win on conflict (Accept: text/event-stream, Content-Type: application/json);
    • the header timeout doesn't cut the stream once it's established.
  • The narrower header test, which stopped at the first request, is removed.
await connect(
  { type: "sse", url: sse.url, headers: { "X-Api-Key": "secret", "Content-Type": "text/plain" } },
  { timeout: 100 },
);

Verification

  • bun run validate: 98 pass, 1 skip. The new test also passed 20 repeated runs.
  • Mutation checks: the new test fails against the original spread-based merge (Accept becomes */*), against reversed header precedence, and against a timeout that isn't cleared once headers arrive.

No test connected over SSE successfully, so the header injection fixed in kriasoft#11 (Headers instances were spread into nothing, dropping the transport's Accept header) had no end-to-end guard. A minimal legacy SSE server fixture stands in for the one the SDK v2 server package dropped; the test checks that server headers reach both the event stream and the POSTs, that SDK headers win on conflict, and that the header timeout leaves an established stream open. It replaces the narrower header test that stopped at the first request.
@koistya koistya changed the title fix: preserve downstream SSE headers when injecting server headers test: cover SSE connections end to end Sep 30, 2026
@koistya
koistya merged commit c891aea into kriasoft:main Sep 30, 2026
1 check passed
@koistya

koistya commented Sep 30, 2026

Copy link
Copy Markdown
Member

@zenyr sorry this sat in the queue for so long 😅 Both #8 and this one are merged now. You found two real bugs in the OAuth/SSE plumbing, and your header fix pretty much matches what ended up in main. Huge thanks, and PRs from you are always welcome 🍻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants