Skip to content

[test-improver] Improve tests for proxy.New and proxy.Handler#8464

Draft
github-actions[bot] wants to merge 1 commit into
mainfrom
test-improver/proxy-new-handler-coverage-8b1116335cd98991
Draft

[test-improver] Improve tests for proxy.New and proxy.Handler#8464
github-actions[bot] wants to merge 1 commit into
mainfrom
test-improver/proxy-new-handler-coverage-8b1116335cd98991

Conversation

@github-actions

@github-actions github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds unit tests for two completely uncovered functions in internal/proxy/proxy.go.

File Analyzed

internal/proxy/proxy_server_test.go (new file)
Implementation: internal/proxy/proxy.go

Improvements Made

Added 4 tests covering previously untested code paths:

Test Path Covered
TestNew_EmptyWasmPath cfg.WasmPath == "" guard (lines 90-92)
TestNew_InvalidWasmPath WASM load error + GitHubAPIURL default fallback
TestNew_InvalidDIFCMode difcParseErr != nil warning branch (lines 104-106)
TestHandler_ServesRequests Handler() constructor + verifies /health response

TestHandler_ServesRequests reuses the existing newTestServer helper from handler_test.go (a NoopGuard-based server), so no WASM file is needed. The test routes a real /health request through the wrapped handler to confirm it responds correctly.

Coverage Before / After

Function Before After
proxy.go:New 0.0% 64.0%
proxy.go:Handler 0.0% 100.0%
Package total 92.7% 94.9%

The remaining gap in New (36%) covers the full success path which requires loading a real WASM guard module — not feasible in unit tests.

Test Output

=== RUN   TestNew_EmptyWasmPath
--- PASS: TestNew_EmptyWasmPath (0.00s)
=== RUN   TestNew_InvalidWasmPath
--- PASS: TestNew_InvalidWasmPath (0.00s)
=== RUN   TestNew_InvalidDIFCMode
--- PASS: TestNew_InvalidDIFCMode (0.00s)
=== RUN   TestHandler_ServesRequests
--- PASS: TestHandler_ServesRequests (0.00s)
PASS
ok  	github.com/github/gh-aw-mcpg/internal/proxy	0.010s

All existing proxy tests continue to pass (go test -count=3 ./internal/proxy/ — stable across 3 runs).

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • index.crates.io

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

network:
  allowed:
    - defaults
    - "index.crates.io"

See Network Configuration for more information.

Generated by Test Improver · 450.1 AIC · ⊞ 5.6K ·

- TestNew_EmptyWasmPath: covers the WasmPath == "" guard (line 90-92)
- TestNew_InvalidWasmPath: covers WASM load error path + GitHubAPIURL
  default fallback branch (line 95-97)
- TestNew_InvalidDIFCMode: covers difcParseErr != nil warning branch
  (lines 104-106) in New
- TestHandler_ServesRequests: covers Handler() constructor by routing a
  /health request through the returned http.Handler

Coverage improvement for internal/proxy:
  proxy.go:New     0.0% → 64.0%
  proxy.go:Handler 0.0% → 100.0%
  package total    92.7% → 94.9%

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

0 participants