Repository navigation
[test] Add tests for guard.WasmGuard dispatch methods - #8148
Merged
Merged
Conversation
Cover previously-untested dispatch functions in internal/guard/wasm.go: - unmarshalWasmResponse (0% → 100%) - NewWasmGuard (0% → 100%) - hostLog (0% → 100%) - LabelAgent (0% → 76%) - LabelResource (0% → 83%) - LabelResponse (0% → 59%) - hostCallBackend (27% → 87%) Overall guard package coverage: 79.2% → 92.1% (+12.9%) New WASM fixtures added (inline byte slices, no compiler needed): - labelResourceReturnsZeroWasm: exports label_resource, returns 0 - labelResponseReturnsZeroWasm: exports label_response, returns 0 - labelResponseReturnsTwoWasm: exports label_response, returns 2 (claims 2 bytes written to zeroed buffer — exercises invalid-JSON path) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a dedicated test suite for internal/guard’s WasmGuard dispatch and host-call paths, increasing confidence in the WASM↔Go boundary behavior and improving package-level coverage.
Changes:
- Introduces
wasm_dispatch_test.gowith table/branch coverage forunmarshalWasmResponse,NewWasmGuard,hostLog,LabelAgent,LabelResource,LabelResponse, andhostCallBackend. - Adds small inline WASM byte fixtures to hit specific dispatch edge cases (empty results / invalid JSON) without requiring a WASM toolchain.
- Exercises error/sentinel protocols for
hostCallBackend(e.g.,-1error,-2buffer-too-small) via direct host-function invocation.
Show a summary per file
| File | Description |
|---|---|
| internal/guard/wasm_dispatch_test.go | Adds focused unit tests and WASM fixtures to cover WasmGuard dispatch methods and host-call behavior. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 1/1 changed files
- Comments generated: 3
- Review effort level: Low
Comment on lines
+484
to
+489
| g.hostCallBackend(context.Background(), g.module, stack) | ||
| // Result too large: the gateway signals buffer-too-small by returning -2, | ||
| // which is encoded as uint64(0xFFFFFFFE) via setResult(int32(-2)). | ||
| const bufTooSmall = uint64(0xFFFFFFFE) | ||
| assert.Equal(t, bufTooSmall, stack[0], "result too large should return -2 buffer-too-small sentinel") | ||
| } |
Comment on lines
+508
to
+513
| stack[5] = 2 // resultSize < 4 — cannot write required-size hint | ||
|
|
||
| g.hostCallBackend(context.Background(), g.module, stack) | ||
| const bufTooSmall = uint64(0xFFFFFFFE) | ||
| assert.Equal(t, bufTooSmall, stack[0], "result too large with small buffer should still return -2") | ||
| } |
Collaborator
|
@copilot address review feedback and fix linting error https://github.com/github/gh-aw-mcpg/actions/runs/28254607796/job/83762156749?pr=8148 |
Contributor
Addressed in commit
Validation run: targeted |
This was referenced Jun 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Test Coverage Improvement: WasmGuard dispatch methods
Function Analyzed
internal/guardinternal/guard/wasm.goWhy This Function?
The
internal/guardpackage had the lowest coverage (79.2%) among testable packages, with several core dispatch functions at 0% coverage. These functions are the primary interface between the Go gateway and WASM security guard modules:unmarshalWasmResponseNewWasmGuardhostLogLabelResourceLabelAgenthostCallBackendLabelResponseTests Added
TestUnmarshalWasmResponse— 6 cases:TestNewWasmGuard— 3 cases:TestHostLog— 6 cases:logLevelDebug(0)logLevelInfo(1)logLevelWarn(2)logLevelError(3)TestLabelAgent— 5 cases:allow-only→ buildStrictLabelAgentPayload errorTestLabelResource— 3 cases:TestLabelResponse— 4 cases:(nil, nil)(no labeling)TestHostCallBackend— 8 cases:New WASM Fixtures
Three inline WASM byte-slice fixtures added (hand-computed from WAT, no compiler required):
labelResourceReturnsZeroWasm— exportslabel_resource, returns 0 (empty result)labelResponseReturnsZeroWasm— exportslabel_response, returns 0 (empty result)labelResponseReturnsTwoWasm— exportslabel_response, returns 2 (claims 2 bytes in zeroed buffer = invalid JSON)Coverage Report
Test Execution
All 30 new tests pass:
Generated by Test Coverage Improver
Warning
Firewall blocked 6 domains
The following domains were blocked by the firewall during workflow execution:
go.opentelemetry.iogo.yaml.ingolang.orggoogle.golang.orggopkg.inproxy.golang.orgSee Network Configuration for more information.