test(core): add unit tests for normalizeHeaders and createFetchWithInit#1374
Conversation
|
@modelcontextprotocol/client
@modelcontextprotocol/server
@modelcontextprotocol/express
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
There was a problem hiding this comment.
Pull request overview
This PR adds comprehensive unit tests for two utility functions (normalizeHeaders and createFetchWithInit) in the transport module that previously lacked dedicated test coverage. The tests verify various input formats for header normalization and proper merging behavior for fetch initialization options.
Key changes:
- New test file with 142 lines covering two utility functions
- Tests for
normalizeHeadersvalidate handling of undefined, Headers instances, arrays of tuples, and plain objects - Tests for
createFetchWithInitverify base initialization passthrough, option merging, and header merging precedence
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
76779f6 to
3f7ef90
Compare
|
@claude review |
There was a problem hiding this comment.
LGTM, straightforward test-only addition for existing utility functions.
Extended reasoning...
Overview
This PR adds a single new test file (packages/core/test/shared/transport.test.ts) with unit tests for normalizeHeaders and createFetchWithInit — two utility functions exported from packages/core/src/shared/transport.ts. No production code is modified.
Security risks
None. This is a test-only change that adds no production code, no new dependencies, and no changes to any runtime behavior.
Level of scrutiny
Low scrutiny warranted. This is a new test file covering existing, stable utility functions. The tests correctly exercise the implementation's code paths: undefined/Headers/array/object normalization, baseInit passthrough, option merging with call-time override precedence, and header merge behavior. The author addressed all Copilot review suggestions (adding empty-init and Headers-passthrough test cases) with reasonable justifications.
Other factors
- All existing tests pass per the PR description (441 tests).
- No changeset needed since this is test-only.
- The test patterns (vi.fn globals, describe/test structure) are consistent with the project's vitest configuration (
globals: true).
felixweinberger
left a comment
There was a problem hiding this comment.
Seems fine to add, thanks!
Add unit tests for
normalizeHeadersandcreateFetchWithInitinpackages/core/src/shared/transport.ts.Motivation and Context
These utility functions are used by both
SSEClientTransportandStreamableHTTPClientTransportbut had no dedicated unit tests. Adding coverage helps catch regressions and documents expected behavior.How Has This Been Tested?
Breaking Changes
None. Test-only change.
Types of changes
(This is a test-only change)
Checklist
Additional context
Tests cover:
normalizeHeaders: undefined, Headers instance, array of tuples, plain objectscreateFetchWithInit: base init passthrough, option merging, header merging precedence