Commit 750b010
authored
[test-improver] Improve tests for server/http_server (#5495)
# Test Improvements: `http_server_test.go`
## File Analyzed
- **Test File**: `internal/server/http_server_test.go`
- **Package**: `internal/server`
## Improvements Made
### 1. Better Testing Patterns
- ✅ Converted `TestNewHTTPServer` from a single flat test to a
table-driven test covering four distinct address formats (`host:port`,
`:port`, `127.0.0.1:0`, empty string)
- ✅ Added descriptive subtest names for each scenario
- ✅ Used `t.Setenv` for environment variable control in timeout test
### 2. Increased Coverage — `buildMCPHTTPServer` contract coverage
- ✅ `TestBuildMCPHTTPServer_ReturnsServerWithCorrectAddr` — verifies the
returned server is bound to the requested address
- ✅ `TestBuildMCPHTTPServer_RouteBuilderIsCalled` — verifies the
routeBuilder callback is actually invoked
- ✅ `TestBuildMCPHTTPServer_RouteBuilderReceivesSessionTimeout` —
verifies the session timeout from `MCP_GATEWAY_SESSION_TIMEOUT` env var
is passed through to the routeBuilder
- ✅ `TestBuildMCPHTTPServer_CustomRouteFromBuilder` — verifies routes
registered inside the routeBuilder callback are accessible through the
built server's handler
### 3. Follow-up review feedback addressed
- ✅ Removed redundant endpoint tests that duplicated existing `/health`
and OAuth discovery coverage in other server test files
- ✅ Kept only `buildMCPHTTPServer`-specific contract assertions to
reduce duplicated maintenance surface
### 4. Cleaner & More Stable Tests
- ✅ Each test is fully isolated with its own `UnifiedServer` and
`t.Cleanup` for teardown
- ✅ Uses `httptest.NewRecorder` / `httptest.NewRequest` — no real ports
opened
- ✅ No timing dependencies
## Test Execution
Targeted and full validation pass:
- `go test ./internal/server -run
'TestNewHTTPServer|TestBuildMCPHTTPServer'`
- `make agent-finished`
## Why These Changes?
`http_server_test.go` originally had minimal coverage. This PR improves
direct coverage of `newHTTPServer` and `buildMCPHTTPServer`-specific
contracts (address propagation, routeBuilder invocation, session-timeout
forwarding, and custom route wiring) while removing duplicate endpoint
assertions already covered elsewhere.
---
*Generated by Test Improver Workflow*
*Focuses on better patterns, increased coverage, and more stable tests*
> Generated by <a
href="https://github.com/github/gh-aw-mcpg/actions/runs/25704663772/agentic_workflow">Test
Improver</a> · ● 3.9M · <a
href="https://github.com/search?q=repo%3Agithub%2Fgh-aw-mcpg+%22gh-aw-workflow-id%3A+test-improver%22&type=pullrequests">◷</a>1 file changed
Lines changed: 104 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
| 6 | + | |
5 | 7 | | |
| 8 | + | |
6 | 9 | | |
7 | 10 | | |
8 | 11 | | |
| 12 | + | |
| 13 | + | |
9 | 14 | | |
10 | 15 | | |
11 | 16 | | |
12 | | - | |
| 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 | + | |
13 | 63 | | |
14 | | - | |
15 | 64 | | |
16 | | - | |
17 | | - | |
| 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 | + | |
18 | 118 | | |
0 commit comments