Skip to content

[test-improver] Improve tests for mcp/tool_result#5788

Merged
lpcox merged 1 commit into
mainfrom
test-improver/tool-result-coverage-6d367dbe0d66cb34
May 16, 2026
Merged

[test-improver] Improve tests for mcp/tool_result#5788
lpcox merged 1 commit into
mainfrom
test-improver/tool-result-coverage-6d367dbe0d66cb34

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

Test Improvements: tool_result_test.go

File Analyzed

  • Test File: internal/mcp/tool_result_test.go
  • Package: internal/mcp
  • Implementation: internal/mcp/tool_result.go

Improvements Made

1. Increased Coverage

  • ✅ Added test for audio content with missing data field
  • ✅ Added test for image content with unsupported data type (e.g., int) — covers decodeContentData default: branch
  • ✅ Added test for image content with nil data value
  • ✅ Added test for resource content where json.Unmarshal into sdk.ResourceContents fails
  • Previous Coverage: decodeContentData 85.7%, convertContentItem 96.4%
  • New Coverage: decodeContentData 100%, convertContentItem 100%

2. Better Testing Patterns

  • ✅ New tests use existing testify assertion patterns (assert.Error, assert.ErrorContains, assert.Nil) consistent with the file's style
  • ✅ Descriptive subtest names explain the invariant being asserted
  • ✅ Comments explain why each case is important (e.g., guarding against corrupted backend responses)

3. Cleaner & More Stable Tests

  • ✅ Each subtest is independent with no shared state
  • ✅ Tests use inline data, no external dependencies

Test Execution

All tests pass:

ok  	github.com/github/gh-aw-mcpg/internal/mcp	2.325s

Coverage improvement in tool_result.go:

tool_result.go:145: decodeContentData   85.7% → 100.0%
tool_result.go:98:  convertContentItem  96.4% → 100.0%

Why These Changes?

tool_result.go is 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.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "invalidhostthatdoesnotexist12345.com"

See Network Configuration for more information.

Generated by Test Improver · ● 2.5M ·

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>
@lpcox lpcox marked this pull request as ready for review May 16, 2026 16:31
Copilot AI review requested due to automatic review settings May 16, 2026 16:31
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@lpcox lpcox merged commit 4552921 into main May 16, 2026
23 checks passed
@lpcox lpcox deleted the test-improver/tool-result-coverage-6d367dbe0d66cb34 branch May 16, 2026 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants