[test-improver] Improve tests for mcp/tool_result#5788
Merged
Conversation
Add missing test cases for decodeContentData and convertContentItem: - Audio content with missing data field - Image/audio content with unsupported data type (default branch) - Image content with nil data value - Resource content where JSON unmarshal fails decodeContentData: 85.7% → 100% convertContentItem: 96.4% → 100% Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds unit tests to internal/mcp/tool_result_test.go to cover previously-untested error branches in decodeContentData and convertContentItem, raising both to 100% coverage.
Changes:
- New subtests for missing audio
data, unsupported data type (int), and nil data value in image content. - New top-level test for resource JSON that fails to unmarshal into
sdk.ResourceContents.
Show a summary per file
| File | Description |
|---|---|
| internal/mcp/tool_result_test.go | Adds four tests exercising error paths of decodeContentData and the resource-unmarshal branch of convertContentItem. |
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: 0
This was referenced May 16, 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.
Test Improvements:
tool_result_test.goFile Analyzed
internal/mcp/tool_result_test.gointernal/mcpinternal/mcp/tool_result.goImprovements Made
1. Increased Coverage
datafieldint) — coversdecodeContentDatadefault:branchnildata valuejson.Unmarshalintosdk.ResourceContentsfailsdecodeContentData85.7%,convertContentItem96.4%decodeContentData100%,convertContentItem100%2. Better Testing Patterns
assert.Error,assert.ErrorContains,assert.Nil) consistent with the file's style3. Cleaner & More Stable Tests
Test Execution
All tests pass:
Coverage improvement in
tool_result.go:Why These Changes?
tool_result.gois central to MCP response handling — it converts every backend tool result into the SDK format. The uncovered branches represent real error conditions (unsupported data types, unmarshalable resources) that could surface from misbehaving backends. Adding these tests ensures the error paths are exercised and their error messages are validated.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:
invalidhostthatdoesnotexist12345.comSee Network Configuration for more information.