Commit 4552921
authored
[test-improver] Improve tests for mcp/tool_result (#5788)
# 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]
> <details>
> <summary>Firewall blocked 1 domain</summary>
>
> 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:
>
> ```yaml
> network:
> allowed:
> - defaults
> - "invalidhostthatdoesnotexist12345.com"
> ```
>
> See [Network
Configuration](https://github.github.com/gh-aw/reference/network/) for
more information.
>
> </details>
> Generated by [Test
Improver](https://github.com/github/gh-aw-mcpg/actions/runs/25947156108/agentic_workflow)
· ● 2.5M ·
[◷](https://github.com/search?q=repo%3Agithub%2Fgh-aw-mcpg+%22gh-aw-workflow-id%3A+test-improver%22&type=pullrequests)
<!-- gh-aw-agentic-workflow: Test Improver, engine: copilot, version:
1.0.40, model: claude-sonnet-4.6, id: 25947156108, workflow_id:
test-improver, run:
https://github.com/github/gh-aw-mcpg/actions/runs/25947156108 -->
<!-- gh-aw-workflow-id: test-improver -->1 file changed
Lines changed: 55 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
507 | 507 | | |
508 | 508 | | |
509 | 509 | | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
510 | 548 | | |
511 | 549 | | |
512 | 550 | | |
| |||
523 | 561 | | |
524 | 562 | | |
525 | 563 | | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
526 | 581 | | |
527 | 582 | | |
528 | 583 | | |
| |||
0 commit comments