[test-improver] Improve tests for mcp tool_result package#4254
Merged
Conversation
Add two new test cases to internal/mcp/tool_result_test.go: 1. Cover the json.Unmarshal error fallback in ConvertToCallToolResult when the 'content' field is a non-array value (e.g. a string), bringing ConvertToCallToolResult coverage from 93.1% to 100%. 2. Document ParseToolArguments behavior with null JSON input (yields nil map, not an empty map), covering the previously-untested null-JSON path. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Improves test coverage and documentation of edge-case behavior in the internal/mcp tool result utilities, specifically around ConvertToCallToolResult fallback parsing and ParseToolArguments handling of null JSON.
Changes:
- Adds a test covering
ConvertToCallToolResult’s fallback behavior when"content"is present but not an array. - Adds a test documenting that
ParseToolArgumentsreturns anilmap (without error) when arguments are JSONnull.
Show a summary per file
| File | Description |
|---|---|
internal/mcp/tool_result_test.go |
Adds subtests to cover previously untested parsing fallback and to document null-arguments behavior. |
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 Apr 21, 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/mcpImprovements Made
1. Increased Coverage
✅ Added test for
ConvertToCallToolResultwhen thecontentfield is a non-array value (e.g. a JSON string) — triggers thejson.Unmarshalerror fallback that wraps raw bytes as a text content item✅ Added test documenting
ParseToolArgumentsbehavior withnullJSON input — shows it returns anilmap (not empty map) without errorConvertToCallToolResultcoverage: 93.1% → 100%ParseToolArgumentscoverage: maintained at 100%NewErrorCallToolResultcoverage: maintained at 100%2. Cleaner & More Stable Tests
t.Run()subtest style in the file (not table-driven, consistent with surrounding code)require/assertfrom testify for precise, idiomatic assertionsTest Execution
All
internal/mcptests pass:Note:
TestFetchAndFixSchema_NetworkErrorininternal/configis a pre-existing failure unrelated to this PR (network test making a real HTTP request that returns 403 in CI).Why These Changes?
ConvertToCallToolResulthad an untested fallback path: when the response JSON has acontentfield that is not an array (e.g.{"content": "some string"}), the typed struct unmarshal fails and the function falls back to wrapping the raw bytes as a text content item. This path was completely untested.The
ParseToolArgumentsnull-JSON test documents a subtle but important behavior: passingnullJSON yields anilmap (not an empty map), which callers should be aware of.Generated by Test Improver Workflow
Focuses on better patterns, increased coverage, and more stable tests
Warning
The following domain was blocked by the firewall during workflow execution:
invalidhostthatdoesnotexist12345.comTo allow these domains, add them to the
network.allowedlist in your workflow frontmatter:See Network Configuration for more information.