[test-improver] Improve tests for guard package (normalizeLabelListField)#8210
Merged
lpcox merged 3 commits intoJun 28, 2026
Merged
Conversation
Add TestNormalizeLabelListField to wasm_payload_test.go covering all
previously-uncovered branches of the normalizeLabelListField helper:
- non-string, non-[]interface{} input (type error path)
- empty/delimiter-only string (len(parts)==0 error path)
- whitespace-only parts skipped via continue (empty trimmed part)
- all parts whitespace resulting in empty output (len(out)==0 error path)
Also adds positive test cases for comma-delimited strings, newline-
delimited strings, mixed delimiters, whitespace trimming, empty arrays,
and the array validation error paths.
Coverage: normalizeLabelListField 82.6% → 100%
Package: internal/guard 92.0% → 92.5%
Co-authored-by: Copilot <[email protected]>
This was referenced Jun 28, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Adds direct, table-driven unit coverage for the internal/guard helper normalizeLabelListField, making label parsing/validation behavior explicit and fully exercised (including previously uncovered error branches).
Changes:
- Added
TestNormalizeLabelListFieldwith comprehensive table-driven coverage across array/string/invalid-type inputs. - Increased branch coverage for delimiter/whitespace edge cases and invalid inputs.
Show a summary per file
| File | Description |
|---|---|
| internal/guard/wasm_payload_test.go | Adds dedicated unit tests for normalizeLabelListField, covering success paths and previously uncovered error/edge branches. |
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: 2
- Review effort level: Low
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
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.
File Analyzed
internal/guard/wasm_payload_test.gointernal/guardImprovements Made
1. Added
TestNormalizeLabelListFieldThe
normalizeLabelListFieldhelper inwasm_payload.gohad no dedicated unit tests and sat at 82.6% coverage (4 branches uncovered). Tests for this function were entirely indirect — exercised only throughbuildStrictLabelAgentPayloadinwasm_test.go.Added a comprehensive, table-driven
TestNormalizeLabelListFielddirectly targeting the function:2. Increased Coverage — Previously Uncovered Branches
return nil, fmt.Errorf("...expected array of strings or comma/newline-delimited string...")raw = 42(integer)return nil, fmt.Errorf("...must include at least one non-empty label")(first)raw = ","if trimmed == "" { continue }raw = "valid, ,other"return nil, fmt.Errorf("...must include at least one non-empty label")(second)raw = " "3. Test Cases Added (17 subtests)
Array path:
Non-array, non-string path (previously 0% covered):
String path:
String path error cases (previously 0% covered):
continueandlen(out)==0branches)Mixed case:
continue, result non-empty)4. Better Test Structure
t.Parallel()at top level and in each subtest for faster executionname,raw,want,wantErrfieldsrequirefor fatal checks,assertfor informational checksTest Execution
All 26 package tests pass (including the 17 new subtests).
Why These Changes?
normalizeLabelListFieldis a security-relevant helper that validates and normalizes therefusal-labelsfield in guard policies used to control tool call behavior. Having comprehensive direct unit tests for this function:The existing indirect coverage through
buildStrictLabelAgentPayloadonly exercised the happy paths, leaving 4 error branches entirely untested.Generated by Test Improver Workflow
Focuses on better patterns, increased coverage, and more stable tests
Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
index.crates.ioSee Network Configuration for more information.