[test-improver] Improve tests for internal/guard (WASM lifecycle coverage) - #12505
Conversation
Add three tests covering previously-uncovered branches: - WasmGuard.Close with a nil context.Context (nil-context fallback) - callWasmGuardFunction input-marshal error path (json.Marshal failure) - hostCallBackend result-marshal error path (json.Marshal failure) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟢 Approval recommended
The focused test-only changes have no unresolved issues.
Pull request overview
Adds focused tests for previously uncovered WASM lifecycle and dispatch error paths without changing production code.
Changes:
- Tests nil-context cleanup and input marshal failures.
- Tests backend result marshal failure handling.
File summaries
| File | Description |
|---|---|
internal/guard/wasm_test.go |
Covers nil-context cleanup and invalid JSON input handling. |
internal/guard/wasm_dispatch_test.go |
Covers backend result serialization failure. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
🔒 mcpg Read-Only Stress — gvisorSurface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Overall: INCONCLUSIVE No write leaked in any part.
|
🔒 mcpg Read-Only Stress — defaultSurface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Overall: INCONCLUSIVE Notes:
|
🔒 mcpg Read-Only Stress — docker-sbxSurface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Overall: INCONCLUSIVE Notes:
|
File analyzed
internal/guard/wasm_lifecycle.go(via existing test filesinternal/guard/wasm_test.goandinternal/guard/wasm_dispatch_test.go)Improvements made
Added three new focused test cases covering previously-uncovered error/edge branches:
TestWasmGuardClose—nil context is replaced with context.Backgroundsubtest: exercises theif ctx == nil { ctx = context.Background() }fallback inWasmGuard.Close, which was never invoked by any prior test.TestCallWasmGuardFunction_MarshalError: passesmap[string]any{"value": math.Inf(1)}asinputDatatocallWasmGuardFunction, whichjson.Marshalalways rejects (+Infis not valid JSON), exercising thefailed to marshal %s inputerror-wrapping branch.TestHostCallBackend_ResultMarshalFailure: configures the mock backend to return a result containingmath.Inf(1), sohostCallBackend'sjson.Marshal(result)fails, exercising the "Failed to marshal backend result" error-sentinel branch (previously only reachable via unrealistic backend implementations).All new tests use the existing
mockBackendCaller/setupWasmGuardtest helpers already used throughout the file, following the established style (boundassert/require, table-free but consistent with sibling tests in the same file).Coverage before/after
internal/guard: 96.6% → 97.1%WasmGuard.Close: 88.9% → 100%callWasmGuardFunction: 88.9% → 100%hostCallBackend: 87.3% → 92.7%Test output
go vet ./internal/guard/...andgofmt -lboth report no issues on the modified files.Full-repo
make agent-finishedwas run: all Go package tests (includinginternal/guard) pass. The Rust guard unit test step failed only due to a sandboxed-environment network restriction preventingcargofrom reaching crates.io (CONNECT tunnel failed, response 403) — unrelated to this change (no Rust files were touched).No production code was modified — this PR only adds test coverage.
Warning
Firewall blocked 2 domains
The following domains were blocked by the firewall during workflow execution:
api.github.comindex.crates.io[!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.