Repository navigation
[test-improver] Improve tests for proxy (enclave_test.go) - #16635
Conversation
t.Fatalf calls FailNow, which must only run on the test goroutine. The enclave tests invoked it from httptest handler goroutines. Report the unexpected request with t.Errorf and fail the upstream response instead. Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain; the enclave test handlers now report unexpected requests safely from goroutines and return cleanly with HTTP 500 responses.
No open issues 🎉
What changed in this PR
This PR hardens enclave proxy tests by safely handling unexpected upstream requests from httptest handler goroutines without using goroutine-unsafe t.Fatalf.
Changes:
- Replaced
t.Fatalfwitht.Errorfin two upstream handlers. - Added HTTP 500 responses so unexpected handlers return cleanly.
- Preserved existing test cases, assertions, and coverage.
| File | Description |
|---|---|
| internal/proxy/enclave_test.go | Updates two enclave test handlers to safely report unexpected upstream requests from goroutines and return HTTP 500. |
Review effort: Lite (adaptive)
🔒 mcpg Read-Only Stress — defaultSurface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Overall: INCONCLUSIVE No write leaked in any probe. Part B is marked inconclusive because the backend GitHub MCP server runs with GITHUB_READ_ONLY=1 (gh-aw framework default), so all write tools are entirely absent from the 23-tool catalog - this proves backend/toolset config, not mcpg's own gateway-layer DIFC enforcement. Parts D/E are marked inconclusive because gh auth status reported no authenticated GitHub host in this job, so REST/GraphQL write probes could not be attempted (not a pass, not a leak - simply untested here). No pass-label applied since overall result is not a clean PASS.
|
File analyzed
internal/proxy/enclave_test.go(implementation:internal/proxy/enclave.go)Problem
Two enclave tests called
t.Fatalffrom insidehttptestupstream handler goroutines:TestEnclaveUniformlyDeniesNonPublicRepositoriesTestEnclaveFailsClosedOnRedirectAndNonJSONSuccesst.FatalfcallsFailNow, which is only safe on the test goroutine. Calling it from a handler goroutine can misreport failures or leave the test hanging.Improvement
In the
default:branch of each upstream handler, replacet.Fatalfwitht.Errorf(records the failure from any goroutine) and respond500, so the unexpected request still fails the test and the handler returns cleanly. No test cases were removed or weakened.Coverage
internal/proxystatement coverage: 96.7% before, 96.7% after (no change, as expected for a test-hygiene fix).enclave.gohandleEnclaveRequest: 90.3% before and after.Verification
go test ./internal/proxy/passesgo test -count=3 ./internal/proxy/passesgo test -race -run TestEnclave ./internal/proxy/passesgo vet ./internal/proxy/andgofmt -lcleanmake agent-finished: all Go stages pass (format, build, unit tests across all packages, integration tests). The Rust guard stage fails only becausecargocannot download crates through the sandbox TLS interception, which is unrelated to this change.Test output (proxy package, enclave tests)
Warning
Firewall blocked 4 domains
The following domains were blocked by the firewall during workflow execution:
example.comnonexistent.localslow.example.comthishostdoesnotexist12345.comTo allow these domains, add them to the
network.allowedlist in your workflow frontmatter:See Network Configuration for more information.