Commit bb21d4b
authored
[test] Add tests for mcp.Connection.callTool (#10937)
# Test Coverage Improvement: `callTool`
## Function Analyzed
- **Package**: `internal/mcp`
- **Function**: `Connection.callTool` (in `connection_methods.go`)
- **Previous Coverage**: 20.0%
- **New Coverage**: 100.0%
- **Complexity**: Medium (nil-defaulting branch, SDK dispatch, error
propagation)
## Why This Function?
`callTool` is the gateway's core `tools/call` dispatch path — it
normalizes nil `arguments` to an empty map (a hard MCP protocol
requirement) before invoking the backend SDK session's `CallTool`. It
had only 20% statement coverage: existing tests exercised argument
marshaling/unmarshaling at the HTTP JSON layer and nil-session error
paths, but never exercised the real SDK call path (the `if p.Arguments
== nil` branch and the successful `getSDKSession().CallTool(...)` call
were both untested).
## Tests Added
- ✅ `TestCallTool_NilArgumentsDefaultsToEmptyMap` — verifies omitted
`arguments` becomes an empty map at the backend
- ✅ `TestCallTool_ArgumentsForwarded` — verifies provided arguments are
forwarded unmodified
- ✅ `TestCallTool_BackendHandlerError` — verifies a Go error from the
backend tool handler surfaces as an error
- ✅ `TestCallTool_UnknownToolName` — verifies an unknown tool name
produces an error
All four tests spin up a **real** `sdk.NewStreamableHTTPHandler`-backed
`httptest.Server` (rather than mocking JSON-RPC at the HTTP layer), so
they exercise the actual `callSDKMethod → callParamMethod →
sdk.ClientSession.CallTool` dispatch path end-to-end.
## Coverage Report
```
Before: internal/mcp package 97.6%, callTool 20.0%
After: internal/mcp package 98.4%, callTool 100.0%
Improvement: +0.8% package, +80% for the target function
```
## Test Execution
```
=== RUN TestCallTool_NilArgumentsDefaultsToEmptyMap
--- PASS: TestCallTool_NilArgumentsDefaultsToEmptyMap (0.00s)
=== RUN TestCallTool_ArgumentsForwarded
--- PASS: TestCallTool_ArgumentsForwarded (0.00s)
=== RUN TestCallTool_BackendHandlerError
--- PASS: TestCallTool_BackendHandlerError (0.00s)
=== RUN TestCallTool_UnknownToolName
--- PASS: TestCallTool_UnknownToolName (0.00s)
PASS
ok github.com/github/gh-aw-mcpg/internal/mcp 0.028s
```
`gofmt` and `go vet` are clean on the new file.
---
*Generated by Test Coverage Improver*
*Next run will target the next most complex under-tested function*
> Generated by [Test Coverage
Improver](https://github.com/github/gh-aw-mcpg/actions/runs/31324128354)
· auto · 131.6 AIC · ⊞ 10.1K ·
[◷](https://github.com/search?q=repo%3Agithub%2Fgh-aw-mcpg+%22gh-aw-workflow-id%3A+test-coverage-improver%22&type=pullrequests)
<!-- gh-aw-agentic-workflow: Test Coverage Improver, engine: copilot,
model: auto, id: 31324128354, workflow_id: test-coverage-improver, run:
https://github.com/github/gh-aw-mcpg/actions/runs/31324128354 -->
<!-- gh-aw-workflow-id: test-coverage-improver -->
<!-- gh-aw-workflow-call-id: github/gh-aw-mcpg/test-coverage-improver
-->1 file changed
Lines changed: 153 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
0 commit comments