Commit f554d6b
authored
[test-improver] Improve tests for mcp package (#2567)
## File Analyzed
- **Test File**: `internal/mcp/connection_stderr_test.go`
- **Package**: `internal/mcp`
- **Lines of Code**: 38 → 79 (documentation-only test replaced with real
tests)
## Improvements Made
### 1. Replaced Documentation-Only Test with Real Tests
The original file contained a single test
`TestConnection_MultipleServersStderrLogging` that only called
`t.Log(...)` — no assertions, no real verification of any behavior. It
was purely a design note disguised as a test.
The file is now replaced with four substantive tests targeting
previously untested code paths.
### 2. Increased Coverage
- ✅ **`TestConnection_SendRequest`**: Exercises the `SendRequest`
wrapper method which was **never tested** anywhere in the test suite.
Verifies it delegates correctly to `SendRequestWithServerID` via a plain
JSON-RPC HTTP test server.
- ✅ **`TestConnection_SendRequest_UnsupportedMethod`**: Verifies
`SendRequest` surfaces errors from the transport layer (unsupported
method path).
- ✅ **`TestConnection_Close_NilSession`**: Verifies `Close()` returns
nil without panicking when there is no active SDK session.
- ✅ **`TestConnection_Close_CancelsContext`**: Verifies `Close()`
cancels the underlying context, making it unusable for further use.
**Previously covered**: `SendRequest` — 0 test cases
**Now covered**: `SendRequest` — 2 test cases; `Close` — 2 explicit test
cases
### 3. Cleaner & More Stable Tests
- ✅ Uses existing `newPlainJSONTestServer` and `newTestConnection`
helpers (no duplication)
- ✅ Uses testify `require`/`assert` throughout (consistent with the rest
of the package)
- ✅ Proper resource cleanup with `defer conn.Close()` and `defer
srv.Close()`
- ✅ Descriptive test names using `TestFunctionName_Scenario` format
## Why These Changes?
`connection_stderr_test.go` was the only non-benchmark test file in the
entire codebase that imported nothing but `"testing"` and contained no
assertions. Meanwhile, `Connection.SendRequest` — a public method on a
core type — had zero test coverage despite being straightforward to
test. These changes convert a no-op documentation comment into four
working tests that catch real regressions.
---
*Generated by Test Improver Workflow*
*Focuses on better patterns, increased coverage, and more stable tests*
> Generated by [Test
Improver](https://github.com/github/gh-aw-mcpg/actions/runs/23581468264)
·
[◷](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, model:
auto, id: 23581468264, workflow_id: test-improver, run:
https://github.com/github/gh-aw-mcpg/actions/runs/23581468264 -->
<!-- gh-aw-workflow-id: test-improver -->1 file changed
Lines changed: 72 additions & 31 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
4 | 7 | | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
5 | 11 | | |
6 | 12 | | |
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 | | - | |
| 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 | + | |
38 | 79 | | |
0 commit comments