Skip to content

test(core): add unit tests for normalizeHeaders and createFetchWithInit#1374

Merged
felixweinberger merged 10 commits intomodelcontextprotocol:mainfrom
k61b:test/transport-utilities
Mar 27, 2026
Merged

test(core): add unit tests for normalizeHeaders and createFetchWithInit#1374
felixweinberger merged 10 commits intomodelcontextprotocol:mainfrom
k61b:test/transport-utilities

Conversation

@k61b
Copy link
Copy Markdown
Contributor

@k61b k61b commented Jan 9, 2026

Add unit tests for normalizeHeaders and createFetchWithInit in packages/core/src/shared/transport.ts.

Motivation and Context

These utility functions are used by both SSEClientTransport and StreamableHTTPClientTransport but had no dedicated unit tests. Adding coverage helps catch regressions and documents expected behavior.

How Has This Been Tested?

pnpm -C packages/core test
# 441 tests passed

Breaking Changes

None. Test-only change.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

(This is a test-only change)

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

Tests cover:

  • normalizeHeaders: undefined, Headers instance, array of tuples, plain objects
  • createFetchWithInit: base init passthrough, option merging, header merging precedence

Copilot AI review requested due to automatic review settings January 9, 2026 15:38
@k61b k61b requested a review from a team as a code owner January 9, 2026 15:38
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jan 9, 2026

⚠️ No Changeset found

Latest commit: 87ce712

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Jan 9, 2026

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/client@1374

@modelcontextprotocol/server

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/server@1374

@modelcontextprotocol/express

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/express@1374

@modelcontextprotocol/hono

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/hono@1374

@modelcontextprotocol/node

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/node@1374

commit: 87ce712

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 normalizeHeaders validate handling of undefined, Headers instances, arrays of tuples, and plain objects
  • Tests for createFetchWithInit verify base initialization passthrough, option merging, and header merging precedence

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/core/test/shared/transport.test.ts
Comment thread packages/core/test/shared/transport.test.ts
Comment thread packages/core/test/shared/transport.test.ts
Comment thread packages/core/test/shared/transport.test.ts
Comment thread packages/core/test/shared/transport.test.ts
Comment thread packages/core/test/shared/transport.test.ts
Comment thread packages/core/test/shared/transport.test.ts
Comment thread packages/core/test/shared/transport.test.ts
Comment thread packages/core/test/shared/transport.test.ts
@k61b k61b force-pushed the test/transport-utilities branch from 76779f6 to 3f7ef90 Compare January 9, 2026 15:58
@felixweinberger
Copy link
Copy Markdown
Contributor

@claude review

Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Copy Markdown
Contributor

@felixweinberger felixweinberger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems fine to add, thanks!

@felixweinberger felixweinberger merged commit 905b1e5 into modelcontextprotocol:main Mar 27, 2026
13 checks passed
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.

3 participants