[test] Add tests for guard.WasmGuard.LabelResponse#8383
Draft
github-actions[bot] wants to merge 1 commit into
Draft
[test] Add tests for guard.WasmGuard.LabelResponse#8383github-actions[bot] wants to merge 1 commit into
github-actions[bot] wants to merge 1 commit into
Conversation
Cover previously untested branches in WasmGuard.LabelResponse (wasm.go:610):
- Context state extraction with tool_args (lines 618-624)
- Non-map context state ignored gracefully (line 619 false branch)
- Non-nil capabilities added to WASM input (lines 625-627)
- labeled_paths JSON response path via parsePathLabeledResponse (lines 647-649)
- items JSON response path via parseCollectionLabeledData (lines 652-654)
- Final no-labeling return nil,nil (line 657)
Three new WASM fixtures written using i32.store instructions write hardcoded
JSON payloads to the output buffer at runtime:
- labelResponseWritesEmptyObjectWasm → writes '{}'
- labelResponseWritesItemsWasm → writes '{"items":[{"data":"x"}]}'
- labelResponseWritesLabeledPathsWasm → writes labeled_paths/items_path response
Coverage for WasmGuard.LabelResponse: 59.1% → 100.0%
Guard package overall: 92.5% → 93.6%
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.LabelResponseFunction Analyzed
internal/guardWasmGuard.LabelResponse(wasm.go:610)Why This Function?
WasmGuard.LabelResponsehad the lowest coverage (59.1%) of any non-trivial function in the testable guard package. It contains three groups of uncovered branches: (1) context request-state extraction, (2) capabilities injection, and (3) three distinct JSON-response-parsing paths that each route to a different code path or final return.Tests Added
tool_args— exercises lines 619-621 (state map extraction)*difc.Capabilities— exercises thecaps != nilbranch (line 626)labeled_pathsJSON response — exercisesparsePathLabeledResponsepath (lines 647-649)itemsJSON response — exercisesparseCollectionLabeledDatapath (lines 652-654), verifies returned*CollectionLabeledDatareturn nil, nil(line 657)WASM Fixtures
Three new WASM binary fixtures write specific JSON payloads to the output buffer at runtime using
i32.storeinstructions (4-byte little-endian stores, consistent with existing test WASM patterns):labelResponseWritesEmptyObjectWasm{}labelResponseWritesItemsWasm{"items":[{"data":"x"}]}labelResponseWritesLabeledPathsWasm{"labeled_paths":[],"items_path":"/items"}Coverage Report
Test Execution
All 7 new tests pass:
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:
athens.azurefd.netgo.opentelemetry.iogo.yaml.ingolang.orggoogle.golang.orggopkg.ingoproxy.cngoproxy.iomirrors.aliyun.comproxy.golang.orgreleaseassets.githubusercontent.comSee Network Configuration for more information.