[test-improver] Improve tests for mcp package - #7067
Conversation
… path
- Add TestConvertToCallToolResult_ContentItemErrorPropagation: table-driven
test covering the previously-unreachable 'return nil, err' on line 86-88
of convertMapToCallToolResult via the full ConvertToCallToolResult public API
- Exercises both []interface{} and []map[string]interface{} content slice types
- Brings convertMapToCallToolResult coverage from 95.8% to 100%
- Add t.Parallel() to all top-level test functions in the file for faster
parallel test execution
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR improves test coverage for the internal/mcp tool-result conversion layer by adding a new table-driven test that exercises an previously-uncovered error-propagation branch in convertMapToCallToolResult, and by parallelizing the package’s top-level tests to reduce runtime.
Changes:
- Added a new
TestConvertToCallToolResult_ContentItemErrorPropagationto drive failures through the publicConvertToCallToolResultAPI and validate error propagation fromconvertContentItem. - Added
t.Parallel()to top-level tests ininternal/mcp/tool_result_test.goto allow concurrent execution.
Show a summary per file
| File | Description |
|---|---|
internal/mcp/tool_result_test.go |
Adds coverage for error propagation in content-item conversion and parallelizes top-level tests. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 1/1 changed files
- Comments generated: 1
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
@copilot fix the failing ci check https://github.com/github/gh-aw-mcpg/actions/runs/27066716486/job/79888766757?pr=7067 |
Fixed in commit |
Test Improvements: tool_result_test.go
File Analyzed
internal/mcp/tool_result_test.gointernal/mcpImprovements Made
1. Increased Coverage — Close the
convertMapToCallToolResultgapThe previously uncovered path was
return nil, errat line 86–88 oftool_result.go— the error-propagation branch insideconvertMapToCallToolResult's item-conversion loop. This branch was never reachable via the publicConvertToCallToolResultAPI because:TestDecodeContentDataandTestConvertContentItem_*calledconvertContentItemdirectly, bypassing the wrapping function.TestConvertMapToCallToolResult_ContentItemCastFailurefailed at the earlier type-assertion check (line 70–72), not inside the item loop.New test:
TestConvertToCallToolResult_ContentItemErrorPropagationA table-driven test with 4 cases that go through the full
ConvertToCallToolResult → convertMapToCallToolResultcall chain to exercise line 86–88:[]interface{}[]interface{}datafield[]interface{}[]interface{}datafield[]map[string]interface{}[]map[string]interface{}datafield[]interface{}convertMapToCallToolResultat 95.8%convertMapToCallToolResultat 100.0%tool_result.gofunctions now at 100%2. Cleaner & More Stable Tests
t.Parallel()to all 11 top-level test functions in the file — tests that are stateless (no shared mutable state, not.Setenv()) now run concurrently, reducing total test time.require.Error+require.Nilfor fail-fast assertions at the subtest level.Test Execution
All tests pass with improved coverage:
Full suite (all packages):
Why These Changes?
tool_result.gois a critical conversion layer between raw backend JSON responses and the typed MCP SDKCallToolResult. The previously uncovered error path inconvertMapToCallToolResultcould silently mask content-item conversion failures — a bug here would corrupt tool responses. Making this path explicitly tested via the public API ensures the error propagation contract is enforced.The
t.Parallel()additions are purely mechanical quality improvements: the test functions are already stateless, so enabling parallel execution costs nothing and speeds upgo test -vruns.Generated by Test Improver Workflow
Focuses on better patterns, increased coverage, and more stable tests
Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
index.crates.ioSee Network Configuration for more information.