[test-improver] Improve tests for mcp package connection utilities#1590
Closed
github-actions[bot] wants to merge 1 commit intomainfrom
Closed
[test-improver] Improve tests for mcp package connection utilities#1590github-actions[bot] wants to merge 1 commit intomainfrom
github-actions[bot] wants to merge 1 commit intomainfrom
Conversation
…st.go - Replace documentation-only test with real unit tests using testify assertions - Add TestConnection_ServerIDField: verifies serverID field attribution behavior - Add TestNormalizeInputSchema: comprehensive table-driven tests for NormalizeInputSchema (previously untested in schema.go) - Add TestNormalizeInputSchema_NonObjectTypes, _AdditionalProperties, _DoesNotMutateOriginal, _NilSchemaReturnsIndependentMaps - Add TestMarshalToResponse: tests the marshalToResponse helper - Add TestRequireSession: verifies error on nil session - Add TestCallSDKMethod_UnsupportedMethod: verifies unsupported method error - Add TestCallSDKMethod_SessionRequiredMethods: all 6 SDK methods return session error when session is nil Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Mar 5, 2026
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.
File Analyzed
internal/mcp/connection_stderr_test.gointernal/mcpImprovements Made
1. Replaced Documentation-Only Test With Real Assertions
The original file contained a single
TestConnection_MultipleServersStderrLoggingtest that consisted entirely of comment-style documentation and threet.Log()calls — no assertions whatsoever. It was essentially a code comment dressed as a test. This PR replaces it with meaningful unit tests that actually verify behavior.2. New Coverage:
NormalizeInputSchema(Previously Untested)internal/mcp/schema.goexportsNormalizeInputSchemabut had zero test coverage. Added comprehensive table-driven tests:TestNormalizeInputSchema— 5 cases covering nil schema, object schema with/without properties, schema with properties but no type, empty schemaTestNormalizeInputSchema_NonObjectTypes— string, array, and integer schemas are returned as-is (no properties added)TestNormalizeInputSchema_AdditionalProperties— schemas withadditionalPropertiesskip empty-properties injectionTestNormalizeInputSchema_DoesNotMutateOriginal— verifies the function never mutates the caller's schema mapTestNormalizeInputSchema_NilSchemaReturnsIndependentMaps— each nil call returns an independent map (mutation isolation)3. New Coverage:
connection.goHelper FunctionsThree unexported helpers in
connection.gowere also untested:TestMarshalToResponse— 3 sub-tests: map input, nil input, struct input; verifies JSONRPC=2.0 and correct JSON round-tripTestRequireSession— verifies that a nil session returns a clear"SDK session not available"errorTestCallSDKMethod_UnsupportedMethod— verifies the default switch case returns an"unsupported method: ..."errorTestCallSDKMethod_SessionRequiredMethods— all 6 MCP methods (tools/list, tools/call, resources/list, resources/read, prompts/list, prompts/get) return a session error when session is nil4. Preserved Documentation Value
The serverID attribution behavior (the original reason for the file) is now documented via
TestConnection_ServerIDField, which actually asserts that theserverIDfield is stored correctly on theConnectionstruct, while the doc comment preserves the historical context about before/after log line attribution.Why These Changes?
connection_stderr_test.gowas the weakest test file in the repository — it had no assertions and provided zero coverage. Meanwhile,schema.go'sNormalizeInputSchemafunction (which has 5 distinct code paths) was completely untested despite being called on every tool registration. This PR addresses both gaps in a single file by adding real tests for themcppackage's utility functions.Generated by Test Improver Workflow
Focuses on better patterns, increased coverage, and more stable tests