Skip to content

[test-improver] Improve tests for Guard (LabelAgent/LabelResource success paths) - #10950

Merged
lpcox merged 2 commits into
mainfrom
test-improver/wasm-labels-success-path-26b61b7c79e67dc4
Aug 10, 2026
Merged

[test-improver] Improve tests for Guard (LabelAgent/LabelResource success paths)#10950
lpcox merged 2 commits into
mainfrom
test-improver/wasm-labels-success-path-26b61b7c79e67dc4

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

File analyzed

internal/guard/wasm_labels.go (LabelAgent and LabelResource methods on WasmGuard), tested via a new file internal/guard/wasm_labels_success_test.go.

Why this file

Existing tests in internal/guard/wasm_dispatch_test.go thoroughly cover error paths for LabelAgent/LabelResource (failed guard, empty response, missing exports, invalid JSON, etc.) but had no happy-path test exercising a full successful WASM response. This left the success branches — final response parsing, debug logging, and return statements — completely uncovered.

Improvements made

Added internal/guard/wasm_labels_success_test.go containing:

  • Two hand-authored minimal WASM fixtures (labelAgentSuccessWasm, labelResourceSuccessWasm) that write valid JSON responses ({"difc_mode": "strict"} and {"resource": {...}, "operation": "read"} respectively) into linear memory and return the byte count, using the existing setupRawWasmModule test helper (no new dependencies).
  • TestLabelAgent_SuccessPath — exercises LabelAgent's full success path with a valid allow-only policy, asserting the parsed DIFCMode field via require/assert (testify).
  • TestLabelResource_SuccessPath — exercises LabelResource with non-nil caps (covering the caps != nil capability-injection branch) and asserts the parsed resource description and read operation.
  • TestLabelResource_SuccessPath_NilCapabilities — complementary case with caps == nil, covering the alternate branch.

All new tests use testify require/assert exclusively, consistent with project conventions.

Coverage before/after (internal/guard package, go tool cover -func)

Function Before After
LabelAgent 92.0% 100.0%
LabelResource 83.3% 100.0%
Package total 95.1% 95.6%

Test output

$ go test -v ./internal/guard/ -run "TestLabelAgent_SuccessPath|TestLabelResource_SuccessPath"
=== RUN   TestLabelAgent_SuccessPath
--- PASS: TestLabelAgent_SuccessPath (0.00s)
=== RUN   TestLabelResource_SuccessPath
--- PASS: TestLabelResource_SuccessPath (0.00s)
=== RUN   TestLabelResource_SuccessPath_NilCapabilities
--- PASS: TestLabelResource_SuccessPath_NilCapabilities (0.00s)
PASS
ok  	github.com/github/gh-aw-mcpg/internal/guard	0.013s

Full package suite:

$ go test -v ./internal/guard/    # PASS, all tests
$ go test -count=3 ./internal/guard/   # PASS, 3x
$ go vet ./internal/guard/   # clean
$ gofmt -l internal/guard/wasm_labels_success_test.go   # no output (already formatted)

No existing tests were modified or removed.

Generated by Test Improver · auto · 239.3 AIC · ⊞ 8.1K ·

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@lpcox
lpcox marked this pull request as ready for review August 10, 2026 05:26
Copilot AI balanced review requested due to automatic review settings August 10, 2026 05:26

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.

Pull request overview

Adds successful WASM response coverage for guard labeling methods.

Changes:

  • Adds minimal WASM success fixtures.
  • Tests successful LabelAgent and LabelResource parsing.
  • Exercises nil and non-nil capability inputs.
Show a summary per file
File Description
internal/guard/wasm_labels_success_test.go Adds WASM fixtures and success-path tests.

Review details

Tip

Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment on lines +135 to +138
// TestLabelResource_SuccessPath_NilCapabilities verifies that LabelResource still
// succeeds when caps is nil (the capabilities field is simply omitted from the
// WASM input), covering the complementary branch to the caps != nil case above.
func TestLabelResource_SuccessPath_NilCapabilities(t *testing.T) {
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@lpcox

lpcox commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

@copilot address review feedback

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

Copilot AI commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

@copilot address review feedback

Addressed in the latest commit. The label_resource fixture is now input-sensitive (modelled on labelResponseWritesItemsIfInputLargeWasm): it writes {"resource":{"description":"caps"},"operation":"read"} when inLen > 60 and {"resource":{"description":"no-caps"},"operation":"write"} otherwise. The baseline input is 53 bytes and grows to 71 bytes once capabilities is injected, so the nil and non-nil cases now assert distinct description/operation values. Verified by mutation: removing the if caps != nil { input["capabilities"] = caps } block makes TestLabelResource_SuccessPath fail.

Copilot AI requested a review from lpcox August 10, 2026 13:49
@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 (runsc) kernel-level isolation

Part Surface Op Result Expected Status
A MCP reads (issues/PRs/file/commits) data returned ALLOWED
B MCP writes (reaction/star/issue/comment/branch/file/PR) Error [-32602]: unknown tool (gateway-level, ~6–50ms) BLOCKED
C CLI reads (issues/PRs/file/commits via github CLI) data returned ALLOWED
D CLI REST writes (reaction/star/issue/comment/file) unauthenticated — no GH_TOKEN in env BLOCKED
E CLI GraphQL mutations (addReaction/addStar/createIssue) gateway: unknown tool / gh unauthenticated BLOCKED

Gateway exposes only 22 read-only tools. Write tool calls return Error [-32602]: unknown tool in ~6–50ms (gateway-level filtering confirmed by fast response vs ~800–1200ms backend roundtrip for reads).

Overall: PASS

References: §31394467821

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

@github-actions

Copy link
Copy Markdown
Contributor Author

🔒 mcpg Read-Only Stress — docker-sbx

Surface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Isolation runtime: docker-sbx (KVM-isolated microVM)

Part Surface Op Result Expected Status
A MCP reads (issues/PRs/file/commits) data returned ALLOWED
B MCP writes (reaction/star/issue/comment/branch/file/PR) unknown tool [-32602] BLOCKED
C CLI reads (issues/file) data returned ALLOWED
D CLI REST writes (reaction/star/issue/comment/file) HTTP 401 Bad credentials BLOCKED
E CLI GraphQL mutations (addReaction/addStar/createIssue) HTTP 401 Bad credentials BLOCKED

Overall: PASS

Part B: gateway returns MCP error [-32602]: unknown tool "<write_tool>" for all 7 write tools — gateway strips write tools at the MCP protocol layer.
Parts D & E: gh CLI is unauthenticated in this runtime (401), providing a second enforcement layer.

References: §31394468184

🔒 mcpg read-only stress (docker-sbx runtime) by Read-Only Stress: docker-sbx 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/PRs, get_file, list_commits) data returned ALLOWED
B MCP writes (reaction/star/issue/comment/branch/file/PR) Error [-32602]: unknown tool BLOCKED
C CLI reads (list_issues, get_file via github CLI) data returned ALLOWED
D CLI REST writes (reaction/star/issue/comment/file) gh unauthenticated (no GH_TOKEN) BLOCKED
E CLI GraphQL mutations (addReaction/addStar/createIssue) gh unauthenticated (no GH_TOKEN) BLOCKED

Overall: PASS

Part B detail: Gateway exposes exactly 22 read-only tools. All 7 write tool calls returned Error [-32602]: unknown tool — a gateway-level MCP protocol error, not a backend response. No write reached GitHub.

Parts D&E detail: gh CLI has no GH_TOKEN in this runtime, so all REST/GraphQL writes were blocked at the CLI authentication layer before reaching the network.

References: §31394468103

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

@lpcox
lpcox merged commit a7c37d6 into main Aug 10, 2026
37 checks passed
@lpcox
lpcox deleted the test-improver/wasm-labels-success-path-26b61b7c79e67dc4 branch August 10, 2026 13:53
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