[test] Add tests for cmd.runProxy - #13094
Conversation
runProxy (internal/cmd/proxy.go) had 0% coverage despite being one of the most complex functions in the codebase (cyclomatic complexity 37, tied with cmd.run for highest untested complexity). It wires together the proxy subcommand's entire startup path: enclave/delegation config resolution, guards-mode validation, WASM guard loading, TLS certificate generation, and graceful shutdown. Added internal/cmd/run_proxy_test.go covering: - Happy-path startup and graceful shutdown on context cancellation - The --tls branch (self-signed cert generation, TLS listener wrapping) - --tls-dns-name requiring --tls - Invalid --guards-mode rejection - Enclave+delegation mode conflict detection - Incomplete enclave policy/capability-key configuration error Coverage for runProxy rose from 0% to 75.4%; internal/cmd package overall rose from 72.6% to 85.8%. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
🟡 Changes recommended
The tests must isolate inherited proxy configuration and restore process-wide TLS environment variables.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Adds direct coverage for cmd.runProxy, including startup, shutdown, TLS, validation, and configuration errors.
Changes:
- Adds a minimal embedded WASM guard fixture.
- Tests normal and TLS shutdown paths.
- Tests invalid guard and enclave/delegation configurations.
File summaries
| File | Description |
|---|---|
internal/cmd/run_proxy_test.go |
Adds end-to-end and validation tests for runProxy. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 2
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@copilot fix the failing lint test https://github.com/github/gh-aw-mcpg/actions/runs/34798083882/job/103835003736?pr=13094 |
Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Fixed — the failure was a gofmt indentation issue in |
🔒 mcpg Read-Only Stress — gvisorSurface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Overall: INCONCLUSIVE Notes:
|
🔒 mcpg Read-Only Stress — default AWFSurface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Overall: INCONCLUSIVE Notes:
|
Test Coverage Improvement:
cmd.runProxyFunction Analyzed
internal/cmdrunProxy(internal/cmd/proxy.go:239)cmd.runfor the highest untested complexity in the codebase)Why This Function?
I cross-referenced
gocyclocyclomatic-complexity output againstgo tool cover -funccoverage acrossinternal/....runProxystood out as the most complex function in the codebase with zero test coverage: it wires together the entireawmg proxysubcommand startup path — enclave/delegation config resolution,--guards-modevalidation, logger/tracing/WASM-cache initialization, WASM guard loading, proxy server construction, the private delegation control channel, TLS certificate generation, HTTP server setup, and graceful shutdown — yet had no direct tests exercising it end-to-end.Tests Added
internal/cmd/run_proxy_test.go(mirrors the existingrun_test.gopattern forcmd.run):TestRunProxy_GracefulShutdownViaContextCancellation)--tlsbranch: self-signed certificate generation, TLS listener wrapping, CA cert file written to--tls-dir(TestRunProxy_TLSGracefulShutdown)--tls-dns-namerequires--tls(TestRunProxy_TLSDNSNameRequiresTLS)--guards-modevalue rejected before server startup (TestRunProxy_InvalidGuardsMode)TestRunProxy_EnclaveAndDelegationConflict)TestRunProxy_EnclaveConfigError)A minimal valid WASM module (exporting
label_resource,label_response,label_agent) is embedded as raw bytes soproxy.Newcan succeed without a real guard, following the same approach already used ininternal/proxy/new_test.go.Coverage Report
Test Execution
All tests pass:
Full
go test ./...(unit +test/integration) passes.gofmt/go vetare clean.golangci-lintwas unavailable in this sandbox (not installed); Rust guard unit tests could not run becausecargocould not reachcrates.ioin this sandbox (unrelated to this change — no Rust code was touched).Generated by Test Coverage Improver
Next run will target the next most complex under-tested function
Warning
Firewall blocked 6 domains
The following domains were blocked by the firewall during workflow execution:
api.github.comexample.comindex.crates.iononexistent.localslow.example.comthishostdoesnotexist12345.com[!TIP]
api.github.comis blocked because GitHub API access uses the built-in GitHub tools by default. Instead of addingapi.github.comtonetwork.allowed, usetools.github.mode: gh-proxyfor direct pre-authenticated GitHub CLI access without requiring network access toapi.github.com:See GitHub Tools for more information on
gh-proxymode.To allow these domains, add them to the
network.allowedlist in your workflow frontmatter:See Network Configuration for more information.