[test] Add tests for guard.wasmAlloc, wasmDealloc, tryCallWasmFunction allocator path, and decodeWasmCallResult#6864
Merged
Conversation
…ator path, and decodeWasmCallResult Covers previously uncovered branches in internal/guard/wasm_parse.go: - tryCallWasmFunction: allocator path using WASM with alloc/dealloc exports (57.1% → 83.3%) - wasmAlloc: null pointer and no-result error paths (0% → 90.0%) - wasmDealloc: nil fn, zero ptr/size, and valid call paths (0% → 75.0%) - decodeWasmCallResult: resultLen==0 and resultLen<0 (not -2) branches (66.7% → 72.2%) - parsePathLabeledResponse: NewPathLabeledData error path (84.6% → 100.0%) - wasmMemorySize: nil memory branch (now 100%) Overall guard package coverage: 70.6% → 74.2% New WASM test binaries (hand-assembled) added: - allocGuardWasm: alloc returns 256, label_agent returns 0 (empty) - allocReturnsZeroWasm: alloc returns 0 (null pointer error) - allocReturnsVoidWasm: alloc returns void (no result error) - labelReturnsNeg1Wasm: label_agent returns -1 (negative error code) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds targeted unit tests in internal/guard to improve coverage of wasm_parse.go, especially the previously-untested allocator (alloc/dealloc) path and several error/edge branches in WASM call decoding and response parsing.
Changes:
- Introduces hand-assembled WASM fixtures to exercise
tryCallWasmFunction’s allocator path and relatedwasmAlloc/wasmDeallocbranches. - Adds tests for
decodeWasmCallResultedge cases (0-length result and negative error codes) andwasmMemorySize(nil)behavior. - Adds a test covering
parsePathLabeledResponseerror propagation whendifc.NewPathLabeledDatafails due to an invaliditems_path.
Show a summary per file
| File | Description |
|---|---|
| internal/guard/wasm_parse_coverage_test.go | Adds new WASM-backed coverage tests for allocator path and decode/parse edge cases in wasm_parse.go. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 1/1 changed files
- Comments generated: 0
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:
wasm_parse.go(internal/guard)Function Analyzed
internal/guardtryCallWasmFunction,wasmAlloc,wasmDealloc,decodeWasmCallResult,parsePathLabeledResponseWhy These Functions?
tryCallWasmFunctionwas at 57.1% coverage — the allocator path (lines 198-220) was completely untested because no existing test WASM binary exported bothallocanddeallocfunctions.wasmAllocandwasmDeallocwere at 0% for the same reason.Tests Added
tryCallWasmFunctionallocator path via WASM withalloc/deallocexportswasmAllocerror: null pointer returned by alloc (returns 0)wasmAllocerror: alloc returns void (no result)wasmDealloc: nil function is no-opwasmDealloc: zero pointer is no-opwasmDealloc: zero size is no-opwasmDealloc: valid call (no-op in test WASM)decodeWasmCallResult:resultLen == 0branch (empty byte slice)decodeWasmCallResult:resultLen < 0but not -2 (negative error code)parsePathLabeledResponse:NewPathLabeledDataerror (invaliditems_path)wasmMemorySize: nil memory →(0, false)Four hand-assembled WASM binaries are included as
[]byteliterals:allocGuardWasm:allocreturns 256,label_agentreturns 0 (empty)allocReturnsZeroWasm:allocreturns 0 (null pointer error path)allocReturnsVoidWasm:allocis void (no-result error path)labelReturnsNeg1Wasm:label_agentreturns -1 (negative error code path)Coverage Report
Test Execution
All 11 new tests pass:
Generated by Test Coverage Improver
Next run will target the next most complex under-tested function
Warning
Firewall blocked 9 domains
The following domains were blocked by the firewall during workflow execution:
go.opentelemetry.iogo.yaml.ingolang.orggoogle.golang.orggopkg.ingoproxy.cngoproxy.ioproxy.golang.orgreleaseassets.githubusercontent.comSee Network Configuration for more information.