Skip to content

test: fix all test type errors and typecheck tests in CI - #298

Merged
mattpodwysocki merged 5 commits into
mainfrom
chore/test-type-errors
Oct 26, 2026
Merged

mattpodwysocki merged 5 commits into
mainfrom
chore/test-type-errors

Conversation

@mattpodwysocki

Copy link
Copy Markdown
Contributor

Follow-up to #296, stacked on it (base is feat/mcp-sdk-v2; retarget to main once #296 merges).

tsconfig.test.json covers src/ and test/, but nothing ran it, so test type errors piled up: about 200 on main, plus about 250 more from SDK v2 typing structuredContent as an open object. This gets them to 0 and adds npm run typecheck to CI so they stay there.

What changed

  • Helpers in test/utils/resultTestUtils.ts:
    • structuredOf<ToolOutput>(result) reads structured content as the tool's own exported output type, so a test that checks a field the schema doesn't have won't compile.
    • textOf / resourceTextOf read text content and throw on the wrong content type instead of quietly reading undefined.
  • CI: new typecheck script (tsc -p tsconfig.test.json) runs before the tests. tsconfig.test.json gets noEmit. Without it a plain tsc -p tsconfig.test.json writes .js files next to the sources, which is likely how the files in chore: remove compiled versionUtils-cjs output from src #297 got committed.
  • BasePrompt.test.ts uses a small subclass that exposes validateArguments instead of reaching into a protected method. HttpRequest mocks are typed with vi.fn<HttpRequest>.

Tests that turned out to be wrong

  • input-schema-validation.test.ts: the check that no tool schema uses z.tuple() never looked inside arrays. Under zod 4, ZodArray._def.type is the string 'array', not the item schema. It uses zod 4's accessors now, and the negative test covers a tuple nested in an array.
  • structured-content.test.ts: it imported MapboxApiBasedTool.output.schema.js, which has never existed, and called super() without the required httpRequest.
  • cleanResponseData.test.ts: it used an old directions input shape. It now builds the input with DirectionsInputSchema.parse, so it can't drift again.
  • SimplifyTool: a || Infinity fallback meant one comparison could never fail.
  • The Difference, Intersect and Union tests passed a token to run(), which those tools don't take. That dead argument is removed.

No other assertions changed. Reads through structuredOf are a bit stricter than the old ?. chains: a missing structuredContent now fails with a TypeError instead of comparing against undefined.

Testing

  • npm run typecheck: 0 errors (was about 450)
  • npm test: 96 files, 1080 tests passing
  • Lint: 0 errors

🤖 Generated with Claude Code

mattpodwysocki and others added 3 commits October 21, 2026 15:18
Swaps @modelcontextprotocol/sdk 1.x for the v2 packages
(@modelcontextprotocol/server and /core, plus /client and /node for tests
and scripts). Ran the official v1-to-v2 codemod, then:

- Replace the SDK output-validation patch with lenientOutputSchema, a
  Standard Schema wrapper that keeps the real schema in tools/list but only
  warns on a mismatch. Tools that return text only get structuredContent {}.
- Make publishJsonSchema2020 a deprecated no-op, since v2 publishes JSON
  Schema 2020-12 natively. Kept for hosted's adapter.
- Remove OptimizationV2Tool, which was never registered and used the
  experimental tasks API that v2 drops.
- Move test request contexts to the v2 shape (http.authInfo) so the token
  checks actually run.
- Replace the patch tests, which never went through the SDK, with tests
  that make a real tools/call.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Follow-up to #296. Adds structuredOf/textOf/resourceTextOf test helpers,
fixes the ~450 errors tsconfig.test.json reported (about 200 already on
main, the rest from SDK v2's open structuredContent type), adds noEmit to
tsconfig.test.json and runs `npm run typecheck` in CI.

Fixes tests the errors exposed: the zod 4 tuple traversal that never looked
inside arrays, a structured-content test importing a nonexistent file, a
stale directions input shape, and a SimplifyTool comparison that couldn't
fail.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mattpodwysocki
mattpodwysocki requested a review from a team as a code owner October 21, 2026 23:15
@mattpodwysocki mattpodwysocki added the enhancement New feature or request label Oct 21, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ctufts
ctufts previously approved these changes Oct 23, 2026
@mattpodwysocki
mattpodwysocki changed the base branch from feat/mcp-sdk-v2 to main October 23, 2026 21:26
@mattpodwysocki
mattpodwysocki dismissed ctufts’s stale review October 23, 2026 21:26

The base branch was changed.

# Conflicts:
#	CHANGELOG.md
#	src/utils/versionUtils-cjs.cjs
#	src/utils/versionUtils-cjs.d.cts
#	test/prompts/BasePrompt.test.ts
#	test/tools/difference-tool/DifferenceTool.test.ts
#	test/tools/intersect-tool/IntersectTool.test.ts
#	test/tools/union-tool/UnionTool.test.ts
@mattpodwysocki
mattpodwysocki merged commit e8c0c99 into main Oct 26, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants