Skip to content

[test] Add tests for guard.wasmAlloc, wasmDealloc, tryCallWasmFunction allocator path, and decodeWasmCallResult#6864

Merged
lpcox merged 1 commit into
mainfrom
add-wasm-parse-coverage-tests-84899062df31686f
Jun 1, 2026
Merged

[test] Add tests for guard.wasmAlloc, wasmDealloc, tryCallWasmFunction allocator path, and decodeWasmCallResult#6864
lpcox merged 1 commit into
mainfrom
add-wasm-parse-coverage-tests-84899062df31686f

Conversation

@github-actions

@github-actions github-actions Bot commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Test Coverage Improvement: wasm_parse.go (internal/guard)

Function Analyzed

  • Package: internal/guard
  • Functions: tryCallWasmFunction, wasmAlloc, wasmDealloc, decodeWasmCallResult, parsePathLabeledResponse
  • Previous Coverage: 70.6%
  • New Coverage: 74.2%
  • Complexity: High (WASM runtime integration, allocator path, error handling)

Why These Functions?

tryCallWasmFunction was at 57.1% coverage — the allocator path (lines 198-220) was completely untested because no existing test WASM binary exported both alloc and dealloc functions. wasmAlloc and wasmDealloc were at 0% for the same reason.

Tests Added

  • tryCallWasmFunction allocator path via WASM with alloc/dealloc exports
  • wasmAlloc error: null pointer returned by alloc (returns 0)
  • wasmAlloc error: alloc returns void (no result)
  • wasmDealloc: nil function is no-op
  • wasmDealloc: zero pointer is no-op
  • wasmDealloc: zero size is no-op
  • wasmDealloc: valid call (no-op in test WASM)
  • decodeWasmCallResult: resultLen == 0 branch (empty byte slice)
  • decodeWasmCallResult: resultLen < 0 but not -2 (negative error code)
  • parsePathLabeledResponse: NewPathLabeledData error (invalid items_path)
  • wasmMemorySize: nil memory → (0, false)

Four hand-assembled WASM binaries are included as []byte literals:

  • allocGuardWasm: alloc returns 256, label_agent returns 0 (empty)
  • allocReturnsZeroWasm: alloc returns 0 (null pointer error path)
  • allocReturnsVoidWasm: alloc is void (no-result error path)
  • labelReturnsNeg1Wasm: label_agent returns -1 (negative error code path)

Coverage Report

Before: 70.6% (internal/guard)
After:  74.2% (internal/guard)
Improvement: +3.6%

Function-level improvements:
  parsePathLabeledResponse:   84.6% → 100.0%
  tryCallWasmFunction:        57.1% →  83.3%
  decodeWasmCallResult:       66.7% →  72.2%
  wasmMemorySize:             85.7% → 100.0%
  wasmAlloc:                   0.0% →  90.0%
  wasmDealloc:                 0.0% →  75.0%

Test Execution

All 11 new tests pass:

--- PASS: TestParsePathLabeledResponse_NewPathLabeledDataError (0.00s)
--- PASS: TestTryCallWasmFunction_AllocatorPath (0.00s)
--- PASS: TestDecodeWasmCallResult_ResultLenZero (0.00s)
--- PASS: TestDecodeWasmCallResult_NegativeErrorCode (0.00s)
--- PASS: TestWasmAlloc_NullPointerReturned (0.00s)
--- PASS: TestWasmAlloc_NoResultReturned (0.00s)
--- PASS: TestWasmDealloc_NilFunctionIsNoOp (0.00s)
--- PASS: TestWasmDealloc_ZeroPtrIsNoOp (0.00s)
--- PASS: TestWasmDealloc_ZeroSizeIsNoOp (0.00s)
--- PASS: TestWasmDealloc_ValidCall (0.00s)
--- PASS: TestWasmMemorySize_NilMemory (0.00s)
PASS
ok  github.com/github/gh-aw-mcpg/internal/guard   0.013s

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.io
  • go.yaml.in
  • golang.org
  • google.golang.org
  • gopkg.in
  • goproxy.cn
  • goproxy.io
  • proxy.golang.org
  • releaseassets.githubusercontent.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "go.opentelemetry.io"
    - "go.yaml.in"
    - "golang.org"
    - "google.golang.org"
    - "gopkg.in"
    - "goproxy.cn"
    - "goproxy.io"
    - "proxy.golang.org"
    - "releaseassets.githubusercontent.com"

See Network Configuration for more information.

Generated by Test Coverage Improver · sonnet46 19.6M ·

…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>
@lpcox lpcox marked this pull request as ready for review June 1, 2026 19:08
Copilot AI review requested due to automatic review settings June 1, 2026 19:08

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 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 related wasmAlloc/wasmDealloc branches.
  • Adds tests for decodeWasmCallResult edge cases (0-length result and negative error codes) and wasmMemorySize(nil) behavior.
  • Adds a test covering parsePathLabeledResponse error propagation when difc.NewPathLabeledData fails due to an invalid items_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

@lpcox lpcox merged commit f2b719f into main Jun 1, 2026
23 checks passed
@lpcox lpcox deleted the add-wasm-parse-coverage-tests-84899062df31686f branch June 1, 2026 19:11
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.

2 participants