[test] Add tests for server.createGuardFromConfig and requireGuardPolicyIfGuardEnabled - #12110
Conversation
…ardEnabled Cover the previously untested WASM success path in createGuardFromConfig (valid module load, guard creation, logger.LogInfo call) and the guard-policies-configured-but-unparseable branch in requireGuardPolicyIfGuardEnabled (keeps non-noop guard for later DIFC resolution instead of falling back to noop). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
Both WASM success tests leave their wazero runtimes open.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Adds coverage for guard policy fallback and successful WASM guard initialization.
Changes:
- Tests retention of guards with unrecognized policy maps.
- Tests direct and registered WASM guard creation.
File summaries
| File | Description |
|---|---|
internal/server/require_guard_policy_test.go |
Covers unparseable guard policies. |
internal/server/register_guard_test.go |
Covers successful WASM initialization paths. |
Review details
Suppressed comments (1)
internal/server/register_guard_test.go:616
- This second successful WASM instantiation also needs cleanup. Otherwise the registered guard's wazero module/runtime remains open for the rest of the test process; close it through the concrete guard (or close the registry in cleanup).
require.NoError(t, err)
registeredGuard := us.guardRegistry.Get("github")
require.NotNil(t, registeredGuard)
assert.Equal(t, "wasm-guard", registeredGuard.Name())
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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.
This comment has been minimized.
This comment has been minimized.
|
@copilot fix failing lint ci check https://github.com/github/gh-aw-mcpg/actions/runs/33269487271/job/99145276187?pr=12110 |
Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Fixed the formatting in |
🔒 mcpg Read-Only Stress — gVisorSurface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Overall: INCONCLUSIVE
No writes leaked. Result file: References: §33321440577
|
🔒 mcpg Read-Only Stress — default AWF (normal container isolation)Surface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Overall: INCONCLUSIVE
No writes leaked. Run: §33321440777
|
🔒 mcpg Read-Only Stress — docker-sbxSurface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Overall: INCONCLUSIVE
No write leaked through any surface. The Run: §33321440703
|
Test Coverage Improvement:
createGuardFromConfigandrequireGuardPolicyIfGuardEnabledFunctions Analyzed
internal/serverUnifiedServer.createGuardFromConfig,UnifiedServer.requireGuardPolicyIfGuardEnabledWhy These Functions?
go tool cover -funcshowedinternal/server/guard_init.gohad two functions with meaningful uncovered branches directly relevant to the gateway's security-critical guard/DIFC initialization path:createGuardFromConfig's"wasm"case had a completely uncovered success path (0% coverage on the lines whereguard.NewWasmGuardsucceeds,logger.LogInfois called, and the guard + nil error are returned). Existing tests only covered the empty-path and invalid-WASM-file error branches.requireGuardPolicyIfGuardEnabledhad an uncovered branch where a server has non-emptyGuardPoliciesthat doesn't parse into a structured*config.GuardPolicyyet (e.g. an unrecognized key) — this must keep the non-noop guard for later DIFC resolution rather than falling back to noop, and this specific case wasn't exercised.Both functions gate whether backend requests get labeled/guarded at all, so covering their success/edge branches closes a real correctness-verification gap.
Tests Added
TestCreateGuardFromConfig_WasmType_Success— loads a minimal valid WASM module (exportinglabel_resource,label_response,label_agent,memory) from a temp file and verifiescreateGuardFromConfigreturns a working guard with a nil error.TestCreateGuardFromConfig_WasmType_Success_ViaRegisterGuard— exercises the same success path end-to-end throughregisterGuard, confirming the WASM guard is registered (not replaced by noop).TestRequireGuardPolicyIfGuardEnabled_WithUnparseableGuardPolicies— configures a server with a non-empty but unrecognizedGuardPoliciesmap and verifies the non-noop guard is kept (not downgraded to noop), matching the documented "DIFC will be auto-enabled later" behavior.Coverage Report
Test Execution
Full
internal/...suite (go test ./internal/...) passes with no regressions;go build ./...andgofmt -lare clean on the modified files.Generated by Test Coverage Improver
Next run will target the next most complex under-tested function