Skip to content

[test-improver] Improve tests for proxy (enclave_test.go) - #16635

Merged
lpcox merged 1 commit into
mainfrom
test-improver/proxy-enclave-test-fatal-handlers-5a02c67e2748a0bf
Nov 18, 2026
Merged

lpcox merged 1 commit into
mainfrom
test-improver/proxy-enclave-test-fatal-handlers-5a02c67e2748a0bf

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

File analyzed

internal/proxy/enclave_test.go (implementation: internal/proxy/enclave.go)

Problem

Two enclave tests called t.Fatalf from inside httptest upstream handler goroutines:

  • TestEnclaveUniformlyDeniesNonPublicRepositories
  • TestEnclaveFailsClosedOnRedirectAndNonJSONSuccess

t.Fatalf calls FailNow, 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, replace t.Fatalf with t.Errorf (records the failure from any goroutine) and respond 500, so the unexpected request still fails the test and the handler returns cleanly. No test cases were removed or weakened.

Coverage

internal/proxy statement coverage: 96.7% before, 96.7% after (no change, as expected for a test-hygiene fix). enclave.go handleEnclaveRequest: 90.3% before and after.

Verification

  • go test ./internal/proxy/ passes
  • go test -count=3 ./internal/proxy/ passes
  • go test -race -run TestEnclave ./internal/proxy/ passes
  • go vet ./internal/proxy/ and gofmt -l clean
  • make agent-finished: all Go stages pass (format, build, unit tests across all packages, integration tests). The Rust guard stage fails only because cargo cannot download crates through the sandbox TLS interception, which is unrelated to this change.

Test output (proxy package, enclave tests)

--- PASS: TestEnclaveUniformlyDeniesNonPublicRepositories
--- PASS: TestEnclaveFailsClosedOnRedirectAndNonJSONSuccess
ok  	github.com/github/gh-aw-mcpg/internal/proxy

Warning

Firewall blocked 4 domains

The following domains were blocked by the firewall during workflow execution:

  • example.com
  • nonexistent.local
  • slow.example.com
  • thishostdoesnotexist12345.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "example.com"
    - "nonexistent.local"
    - "slow.example.com"
    - "thishostdoesnotexist12345.com"

See Network Configuration for more information.

Generated by Test Improver · copilot · routed: haiku55 xhigh · ~5 AIC · ⊞ 3K · ◷

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]>
@lpcox
lpcox marked this pull request as ready for review November 18, 2026 15:31
Copilot AI adaptive review requested due to automatic review settings November 18, 2026 15:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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.Fatalf with t.Errorf in 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)

@github-actions

Copy link
Copy Markdown
Contributor Author

🔒 mcpg Read-Only Stress — default

Surface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Isolation runtime: default AWF (normal container isolation)

Part Surface Op Result Expected Status
A MCP reads (list_issues, list_pull_requests, get_file_contents, list_commits) data returned ALLOWED ✅
B MCP writes (issue_write, star_repository, add_issue_comment, create_branch, create_or_update_file, create_pull_request) all absent from 23-tool catalog (unknown tool) BLOCKED ⚠️
C CLI reads (same 4 ops via github CLI) data returned ALLOWED ✅
D CLI REST writes (reaction/star/issue/comment) not attempted - gh unauthenticated BLOCKED ⚠️
E CLI GraphQL mutations (addReaction/addStar/createIssue) not attempted - gh unauthenticated BLOCKED ⚠️

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.

🔒 mcpg read-only stress (default AWF runtime) by Read-Only Stress: default runtime

@lpcox
lpcox merged commit 220d521 into main Nov 18, 2026
28 checks passed
@lpcox
lpcox deleted the test-improver/proxy-enclave-test-fatal-handlers-5a02c67e2748a0bf branch November 18, 2026 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants