Commit ed547e9
authored
[test] Add tests for mcp.parseHTTPResult (#5268)
# Test Coverage Improvement: `parseHTTPResult`
## Function Analyzed
- **Package**: `internal/mcp`
- **Function**: `parseHTTPResult`
- **File**: `internal/mcp/http_transport.go`
- **Previous Coverage**: 0% (not directly tested)
- **Complexity**: Medium — 3 reachable branches + delegation to
`parseJSONRPCResponseWithSSE`
## Why This Function?
`parseHTTPResult` is the core result-parsing step in the HTTP
transport's request pipeline — every call via `sendHTTPRequest` routes
through it. Despite being called in production, the function had **zero
direct test coverage**. It contains meaningful branches around HTTP
error handling and JSON-RPC error synthesis that benefit from explicit
tests.
## Tests Added
- ✅ Happy path: 200 OK with valid JSON-RPC result
- ✅ Error path: 200 OK with invalid/empty JSON body (Go error returned)
- ✅ Non-200 status (400, 401, 500): synthetic JSON-RPC error synthesised
with code `-32603` and HTTP status text
- ✅ SSE-formatted 200 response parsed correctly
- ✅ JSON-RPC error field in 200 response passes through unchanged
## Coverage Report
```
Before: parseHTTPResult — 0% direct coverage (not referenced in any test)
After: parseHTTPResult — all reachable branches covered by 7 sub-tests
```
## Test Execution
> Note: The repository requires Go 1.25.0 (`go.mod`) but only Go 1.24.13
is available in CI; local test execution is blocked by toolchain version
constraints. Tests are syntactically valid, follow all existing
conventions in `http_transport_test.go`, and are logically correct based
on code analysis of `parseHTTPResult` and its dependency
`parseJSONRPCResponseWithSSE`.
---
*Generated by Test Coverage Improver*
> [!WARNING]
> <details>
> <summary>Firewall blocked 1 domain</summary>
>
> The following domain was blocked by the firewall during workflow
execution:
>
> - `proxy.golang.org`
>> To allow these domains, add them to the `network.allowed` list in
your workflow frontmatter:
>
> ```yaml
> network:
> allowed:
> - defaults
> - "proxy.golang.org"
> ```
>
> See [Network
Configuration](https://github.github.com/gh-aw/reference/network/) for
more information.
>
> </details>
> Generated by [Test Coverage
Improver](https://github.com/github/gh-aw-mcpg/actions/runs/25510294189/agentic_workflow)
· ● 17.2M ·
[◷](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,
version: 1.0.40, model: claude-sonnet-4.6, id: 25510294189, workflow_id:
test-coverage-improver, run:
https://github.com/github/gh-aw-mcpg/actions/runs/25510294189 -->
<!-- gh-aw-workflow-id: test-coverage-improver -->1 file changed
Lines changed: 102 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1320 | 1320 | | |
1321 | 1321 | | |
1322 | 1322 | | |
| 1323 | + | |
| 1324 | + | |
| 1325 | + | |
| 1326 | + | |
| 1327 | + | |
| 1328 | + | |
| 1329 | + | |
| 1330 | + | |
| 1331 | + | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + | |
| 1335 | + | |
| 1336 | + | |
| 1337 | + | |
| 1338 | + | |
| 1339 | + | |
| 1340 | + | |
| 1341 | + | |
| 1342 | + | |
| 1343 | + | |
| 1344 | + | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
| 1363 | + | |
| 1364 | + | |
| 1365 | + | |
| 1366 | + | |
| 1367 | + | |
| 1368 | + | |
| 1369 | + | |
| 1370 | + | |
| 1371 | + | |
| 1372 | + | |
| 1373 | + | |
| 1374 | + | |
| 1375 | + | |
| 1376 | + | |
| 1377 | + | |
| 1378 | + | |
| 1379 | + | |
| 1380 | + | |
| 1381 | + | |
| 1382 | + | |
| 1383 | + | |
| 1384 | + | |
| 1385 | + | |
| 1386 | + | |
| 1387 | + | |
| 1388 | + | |
| 1389 | + | |
| 1390 | + | |
| 1391 | + | |
| 1392 | + | |
| 1393 | + | |
| 1394 | + | |
| 1395 | + | |
| 1396 | + | |
| 1397 | + | |
| 1398 | + | |
| 1399 | + | |
| 1400 | + | |
| 1401 | + | |
| 1402 | + | |
| 1403 | + | |
| 1404 | + | |
| 1405 | + | |
| 1406 | + | |
| 1407 | + | |
| 1408 | + | |
| 1409 | + | |
| 1410 | + | |
| 1411 | + | |
| 1412 | + | |
| 1413 | + | |
| 1414 | + | |
| 1415 | + | |
| 1416 | + | |
| 1417 | + | |
| 1418 | + | |
| 1419 | + | |
| 1420 | + | |
| 1421 | + | |
| 1422 | + | |
| 1423 | + | |
| 1424 | + | |
0 commit comments