{{ message }}
[test] Add tests for guard.NewWasmGuardWithOptions coverage paths#8455
Merged
lpcox merged 4 commits intoJul 1, 2026
Conversation
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>
Contributor
There was a problem hiding this comment.
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
NewWasmGuardWithOptionsvalidation branches and oneLabelAgentparsing failure branch. - Adds tests covering stdout/stderr option plumbing (branch coverage), empty module-name fallback, “standard Go vs TinyGo” hint error, missing
label_agentexport, and successful guard creation (with/without a custom compilation cache). - Adds a
LabelAgenttest that forces invalid JSON to exerciseparseLabelAgentResponse’s error path via the publicLabelAgentmethod.
Show a summary per file
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
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>
This was referenced Jul 1, 2026
This was referenced Jul 2, 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:
NewWasmGuardWithOptionsFunction Analyzed
internal/guardNewWasmGuardWithOptionsWhy This Function?
NewWasmGuardWithOptionshad the lowest coverage (69.8%) of any non-trivial function in the codebase. It contains 6 distinct branches that were completely untested:"guard"_startis exported but no guard functions)label_agentexport errorLabelAgenthad 76.0% coverage with itsparseLabelAgentResponseerror path unreachable by existing tests.Tests Added
opts.Stdoutwired to WASM module stdout (lines 255–257)opts.Stderrwired to WASM module stderr (lines 258–260)opts.Stdoutandopts.Stderrset simultaneously""falls back to"guard"as module name (lines 265–267)_startbut no guard functions → standard Go compiler hint error (lines 295–301)label_resource+label_responsebut missinglabel_agent(lines 306–309)LabelAgentwith 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:
startOnlyGuardWasm_startlabelResourceAndResponseWasmlabel_resource+label_responseonlyfullGuardWasmlabelAgentReturnsTwoWasmlabel_agent; returns 2 (zeroed bytes → invalid JSON)Coverage Report
Test Execution
All 9 new tests pass, and the full guard package test suite passes:
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.iogo.yaml.ingolang.orggoogle.golang.orggopkg.ingoproxy.cngoproxy.iopkg.go.devproxy.golang.orgreleaseassets.githubusercontent.comsum.golang.orgSee Network Configuration for more information.