[test] Add tests for guard.NewWasmGuardWithOptions coverage paths by github-actions[bot] · Pull Request #8455 · github/gh-aw-mcpg · GitHub
Skip to content

[test] Add tests for guard.NewWasmGuardWithOptions coverage paths#8455

Merged
lpcox merged 4 commits into
mainfrom
test/guard-wasm-new-options-coverage-b11b12c38432eae0
Jul 1, 2026
Merged

[test] Add tests for guard.NewWasmGuardWithOptions coverage paths#8455
lpcox merged 4 commits into
mainfrom
test/guard-wasm-new-options-coverage-b11b12c38432eae0

Conversation

@github-actions

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

Copy link
Copy Markdown
Contributor

Test Coverage Improvement: NewWasmGuardWithOptions

Function Analyzed

  • Package: internal/guard
  • Function: NewWasmGuardWithOptions
  • Previous Coverage: 69.8%
  • New Coverage: 90.7%
  • Complexity: High (WASM runtime initialization, multiple error paths, custom I/O wiring)

Why This Function?

NewWasmGuardWithOptions had the lowest coverage (69.8%) of any non-trivial function in the codebase. It contains 6 distinct branches that were completely untested:

  • Custom stdout/stderr wiring
  • Empty name fallback to "guard"
  • Standard-Go vs TinyGo error hint (when _start is exported but no guard functions)
  • Missing label_agent export error
  • Successful guard creation (success log path)

LabelAgent had 76.0% coverage with its parseLabelAgentResponse error path unreachable by existing tests.

Tests Added

  • opts.Stdout wired to WASM module stdout (lines 255–257)
  • opts.Stderr wired to WASM module stderr (lines 258–260)
  • ✅ Both opts.Stdout and opts.Stderr set simultaneously
  • ✅ Empty name "" falls back to "guard" as module name (lines 265–267)
  • ✅ WASM with _start but no guard functions → standard Go compiler hint error (lines 295–301)
  • ✅ WASM with label_resource + label_response but missing label_agent (lines 306–309)
  • ✅ Successful creation of a full guard with all three required exports (lines 311–312)
  • ✅ Success path with custom compilation cache
  • LabelAgent with non-empty but invalid JSON response (lines 563–567)

New WASM Fixtures

Four hand-crafted WAT-to-binary WASM fixtures follow the existing inline-bytes style:

Fixture Size Purpose
startOnlyGuardWasm 36 bytes Exports only _start
labelResourceAndResponseWasm 88 bytes Exports label_resource + label_response only
fullGuardWasm 108 bytes Exports all three guard functions + memory
labelAgentReturnsTwoWasm 62 bytes Exports label_agent; returns 2 (zeroed bytes → invalid JSON)

Coverage Report

Before:
  NewWasmGuardWithOptions   69.8%
  LabelAgent                76.0%
  guard package overall     ~92%

After:
  NewWasmGuardWithOptions   90.7%   (+20.9pp)
  LabelAgent                92.0%   (+16.0pp)
  guard package overall     95.3%

Test Execution

All 9 new tests pass, and the full guard package test suite passes:

=== RUN   TestNewWasmGuardWithOptions_CustomStdout
--- PASS: TestNewWasmGuardWithOptions_CustomStdout (0.00s)
=== RUN   TestNewWasmGuardWithOptions_CustomStderr
--- PASS: TestNewWasmGuardWithOptions_CustomStderr (0.00s)
=== RUN   TestNewWasmGuardWithOptions_BothCustomStreams
--- PASS: TestNewWasmGuardWithOptions_BothCustomStreams (0.00s)
=== RUN   TestNewWasmGuardWithOptions_EmptyName
--- PASS: TestNewWasmGuardWithOptions_EmptyName (0.00s)
=== RUN   TestNewWasmGuardWithOptions_StartFunctionOnly
--- PASS: TestNewWasmGuardWithOptions_StartFunctionOnly (0.00s)
=== RUN   TestNewWasmGuardWithOptions_MissingLabelAgent
--- PASS: TestNewWasmGuardWithOptions_MissingLabelAgent (0.00s)
=== RUN   TestNewWasmGuardWithOptions_SuccessPath
--- PASS: TestNewWasmGuardWithOptions_SuccessPath (0.00s)
=== RUN   TestNewWasmGuardWithOptions_SuccessPath_WithCustomCache
--- PASS: TestNewWasmGuardWithOptions_SuccessPath_WithCustomCache (0.00s)
=== RUN   TestLabelAgent_InvalidJSONResponse
--- PASS: TestLabelAgent_InvalidJSONResponse (0.00s)
PASS
ok  github.com/github/gh-aw-mcpg/internal/guard  0.079s

Generated by Test Coverage Improver
Next run will target the next most complex under-tested function

Warning

Firewall blocked 11 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
  • pkg.go.dev
  • proxy.golang.org
  • releaseassets.githubusercontent.com
  • sum.golang.org

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"
    - "pkg.go.dev"
    - "proxy.golang.org"
    - "releaseassets.githubusercontent.com"
    - "sum.golang.org"

See Network Configuration for more information.

Generated by Test Coverage Improver · 614.3 AIC · ⊞ 7.1K ·

Cover previously untested branches in NewWasmGuardWithOptions and LabelAgent:

- opts.Stdout wired to WASM module stdout (lines 255-257)
- opts.Stderr wired to WASM module stderr (lines 258-260)
- Both opts.Stdout and opts.Stderr set simultaneously
- Empty name falls back to "guard" as module name (lines 265-267)
- WASM with _start but no guard functions → standard Go error hint (lines 295-301)
- WASM with label_resource + label_response but missing label_agent (lines 306-309)
- Successful creation of a full guard with all three required exports (lines 311-312)
- Success path with custom compilation cache
- LabelAgent with non-empty but invalid JSON response (lines 563-567)

Three new inline WASM fixtures are introduced (hand-crafted WAT binaries matching
the style of existing fixtures in wasm_parse_coverage_test.go):
- startOnlyGuardWasm (36 bytes): exports only _start
- labelResourceAndResponseWasm (88 bytes): exports label_resource + label_response
- fullGuardWasm (108 bytes): exports all three guard functions + memory
- labelAgentReturnsTwoWasm (62 bytes): exports label_agent + memory; returns 2

Coverage improvements:
- NewWasmGuardWithOptions: 69.8% -> 90.7% (+20.9pp)
- LabelAgent: 76.0% -> 92.0% (+16.0pp)
- guard package overall: -> 95.3%

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@lpcox lpcox marked this pull request as ready for review July 1, 2026 18:14
Copilot AI review requested due to automatic review settings July 1, 2026 18:14

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 exercise previously untested branches in NewWasmGuardWithOptions (stdio wiring, empty-name fallback, export-validation error paths, and success path) and the invalid-JSON failure path in LabelAgent, using small inline WASM fixtures.

Changes:

  • Introduces new WASM byte fixtures to trigger specific NewWasmGuardWithOptions validation branches and one LabelAgent parsing failure branch.
  • Adds tests covering stdout/stderr option plumbing (branch coverage), empty module-name fallback, “standard Go vs TinyGo” hint error, missing label_agent export, and successful guard creation (with/without a custom compilation cache).
  • Adds a LabelAgent test that forces invalid JSON to exercise parseLabelAgentResponse’s error path via the public LabelAgent method.
Show a summary per file
File Description
internal/guard/wasm_new_options_coverage_test.go Adds focused branch-coverage tests and minimal WASM fixtures for NewWasmGuardWithOptions and LabelAgent error handling.

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 thread internal/guard/wasm_new_options_coverage_test.go
Comment thread internal/guard/wasm_new_options_coverage_test.go
Comment thread internal/guard/wasm_new_options_coverage_test.go Outdated
lpcox and others added 3 commits July 1, 2026 11:27
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
GitHub Advanced Security started work on behalf of lpcox July 1, 2026 18:27 View session
GitHub Advanced Security started work on behalf of lpcox July 1, 2026 18:27 View session
GitHub Advanced Security started work on behalf of lpcox July 1, 2026 18:27 View session
GitHub Advanced Security finished work on behalf of lpcox July 1, 2026 18:28
GitHub Advanced Security finished work on behalf of lpcox July 1, 2026 18:28
GitHub Advanced Security finished work on behalf of lpcox July 1, 2026 18:28
@lpcox lpcox merged commit 843d8d3 into main Jul 1, 2026
26 checks passed
@lpcox lpcox deleted the test/guard-wasm-new-options-coverage-b11b12c38432eae0 branch July 1, 2026 20:00
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