Skip to content

[test] Add tests for cmd.runProxy - #13094

Merged
lpcox merged 4 commits into
mainfrom
test-coverage-runproxy-31925c6dbe3f6244
Sep 14, 2026
Merged

lpcox merged 4 commits into
mainfrom
test-coverage-runproxy-31925c6dbe3f6244

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Test Coverage Improvement: cmd.runProxy

Function Analyzed

  • Package: internal/cmd
  • Function: runProxy (internal/cmd/proxy.go:239)
  • Previous Coverage: 0.0%
  • New Coverage: 75.4%
  • Complexity: High (cyclomatic complexity 37 — tied with cmd.run for the highest untested complexity in the codebase)

Why This Function?

I cross-referenced gocyclo cyclomatic-complexity output against go tool cover -func coverage across internal/.... runProxy stood out as the most complex function in the codebase with zero test coverage: it wires together the entire awmg proxy subcommand startup path — enclave/delegation config resolution, --guards-mode validation, 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 existing run_test.go pattern for cmd.run):

  • ✅ Happy-path startup and graceful shutdown on context cancellation (TestRunProxy_GracefulShutdownViaContextCancellation)
  • --tls branch: self-signed certificate generation, TLS listener wrapping, CA cert file written to --tls-dir (TestRunProxy_TLSGracefulShutdown)
  • --tls-dns-name requires --tls (TestRunProxy_TLSDNSNameRequiresTLS)
  • ✅ Invalid --guards-mode value rejected before server startup (TestRunProxy_InvalidGuardsMode)
  • ✅ Enclave + delegation modes configured simultaneously is rejected (TestRunProxy_EnclaveAndDelegationConflict)
  • ✅ Incomplete enclave policy/capability-key pairing surfaces a clear error (TestRunProxy_EnclaveConfigError)

A minimal valid WASM module (exporting label_resource, label_response, label_agent) is embedded as raw bytes so proxy.New can succeed without a real guard, following the same approach already used in internal/proxy/new_test.go.

Coverage Report

Before: 0.0% (runProxy), internal/cmd package 72.6%
After:  75.4% (runProxy), internal/cmd package 85.8%
Improvement: +75.4pp (function), +13.2pp (package)

Test Execution

All tests pass:

=== RUN   TestRunProxy_GracefulShutdownViaContextCancellation
--- PASS: TestRunProxy_GracefulShutdownViaContextCancellation (0.20s)
=== RUN   TestRunProxy_TLSGracefulShutdown
--- PASS: TestRunProxy_TLSGracefulShutdown (0.24s)
=== RUN   TestRunProxy_TLSDNSNameRequiresTLS
--- PASS: TestRunProxy_TLSDNSNameRequiresTLS (0.00s)
=== RUN   TestRunProxy_InvalidGuardsMode
--- PASS: TestRunProxy_InvalidGuardsMode (0.00s)
=== RUN   TestRunProxy_EnclaveAndDelegationConflict
--- PASS: TestRunProxy_EnclaveAndDelegationConflict (0.00s)
=== RUN   TestRunProxy_EnclaveConfigError
--- PASS: TestRunProxy_EnclaveConfigError (0.00s)
PASS
ok  	github.com/github/gh-aw-mcpg/internal/cmd	0.460s

Full go test ./... (unit + test/integration) passes. gofmt/go vet are clean. golangci-lint was unavailable in this sandbox (not installed); Rust guard unit tests could not run because cargo could not reach crates.io in 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.com
  • example.com
  • index.crates.io
  • nonexistent.local
  • slow.example.com
  • thishostdoesnotexist12345.com

[!TIP]
api.github.com is blocked because GitHub API access uses the built-in GitHub tools by default. Instead of adding api.github.com to network.allowed, use tools.github.mode: gh-proxy for direct pre-authenticated GitHub CLI access without requiring network access to api.github.com:

tools:
  github:
    mode: gh-proxy

See GitHub Tools for more information on gh-proxy mode.

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

network:
  allowed:
    - defaults
    - "api.github.com"
    - "example.com"
    - "index.crates.io"
    - "nonexistent.local"
    - "slow.example.com"
    - "thishostdoesnotexist12345.com"

See Network Configuration for more information.

Generated by Test Coverage Improver · copilot · auto · 304.9 AIC · ⊞ 10.4K ·

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>
@lpcox
lpcox marked this pull request as ready for review September 14, 2026 01:59
Copilot AI balanced review requested due to automatic review settings September 14, 2026 02:00
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

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.

🟡 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.

Comment thread internal/cmd/run_proxy_test.go
Comment thread internal/cmd/run_proxy_test.go
lpcox and others added 2 commits September 13, 2026 19:06
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>
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@lpcox

lpcox commented Sep 14, 2026

Copy link
Copy Markdown
Collaborator

Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>

Copilot AI commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

@copilot fix the failing lint test https://github.com/github/gh-aw-mcpg/actions/runs/34798083882/job/103835003736?pr=13094

Fixed — the failure was a gofmt indentation issue in internal/cmd/run_proxy_test.go (two lines missing a tab). Fixed in the latest commit.

Copilot AI requested a review from lpcox September 14, 2026 02:17
@github-actions

Copy link
Copy Markdown
Contributor Author

🔒 mcpg Read-Only Stress — gvisor

Surface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Isolation runtime: gvisor

Part Surface Op Result Expected Status
A MCP reads data returned (list_issues, list_pull_requests, get_file_contents, list_commits) ALLOWED
B MCP writes (reaction/star/issue/comment/branch/file/PR) all 7 target tools absent from the 23-tool catalog BLOCKED ⚠️
C CLI reads (github proxy CLI on PATH) data returned ALLOWED
D CLI REST writes (reaction/star/issue/comment) gh not authenticated — no GH_TOKEN set BLOCKED ⚠️
E CLI GraphQL mutations (addReaction/addStar/createIssue) gh not authenticated — no GH_TOKEN set BLOCKED ⚠️

Overall: INCONCLUSIVE

Notes:

  • Part A/C reads succeeded identically on the gvisor runtime, confirming read access works.
  • Part B: the gh-aw tools.github: wrapper launches the backend with GITHUB_READ_ONLY=1, so none of the 7 targeted write tools appear in the exposed tool catalog at all. This proves backend/toolset configuration blocks writes, but cannot independently confirm the gateway's own DIFC/guard write-blocking layer (that requires a probe outside the gh-aw wrapper — tracked as follow-up work, see internal/guard/internal/difc unit tests for that coverage).
  • Part D/E: gh CLI reported no GH_TOKEN set in this environment, so REST/GraphQL write attempts could not be issued at all — the token-scope boundary was not exercised this run.
  • No write of any kind succeeded or leaked in this run on any surface.

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

@github-actions

Copy link
Copy Markdown
Contributor Author

🔒 mcpg Read-Only Stress — default AWF

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 (reaction/star/issue/comment/branch/file/PR) targeted write tools absent from gateway catalog (23 read-only tools exposed) BLOCKED ⚠️
C CLI reads (github list_issues, github get_file_contents) 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

Notes:

  • Part B: none of add_issue_comment, star_repository, issue_write, create_branch, create_or_update_file, create_pull_request appear in the gateway-exposed tool catalog for this run (only 23 read-only tools registered). Absence proves backend/toolset config (GITHUB_READ_ONLY=1), not the gateway's own DIFC/guard blocking layer — no write was attempted since the tools don't exist to call.
  • Parts D/E: gh auth status shows not logged in (GH_TOKEN unset in this environment), so REST/GraphQL write attempts fail before reaching GitHub. Token-scope boundary could not be independently validated this run.
  • No reaction, star, issue, comment, branch, file, or PR was created or leaked in any part of this test.

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

@lpcox
lpcox merged commit 9a44b5a into main Sep 14, 2026
36 of 37 checks passed
@lpcox
lpcox deleted the test-coverage-runproxy-31925c6dbe3f6244 branch September 14, 2026 02:30
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.

3 participants