[test] Add tests for config.AllowOnlyPolicy.UnmarshalJSON#7639
Merged
lpcox merged 1 commit intoJun 16, 2026
Merged
Conversation
…ion-label error paths
Cover the two remaining uncovered error branches in AllowOnlyPolicy.UnmarshalJSON:
- promotion-label field rejects non-string JSON values (e.g. numbers)
- demotion-label field rejects non-string JSON values (e.g. arrays)
These are added as additional table-driven cases in the existing
TestAllowOnlyPolicyUnmarshalJSON_FieldErrorPaths test, consistent with
the pattern used for the other nine field error paths.
Coverage for AllowOnlyPolicy.UnmarshalJSON improves from 91.9% to 97.3%.
The remaining 2.7% is the repos error branch, which is unreachable dead code
because json.Unmarshal into interface{} never fails on valid JSON input.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves unit test coverage for the security-critical internal/config.(*AllowOnlyPolicy).UnmarshalJSON parser by adding missing error-path coverage for two recently added fields.
Changes:
- Add a table-driven error-path test case ensuring
promotion-labelrejects non-string JSON values. - Add a table-driven error-path test case ensuring
demotion-labelrejects non-string JSON values.
Show a summary per file
| File | Description |
|---|---|
| internal/config/guard_policy_unmarshal_coverage_test.go | Extends TestAllowOnlyPolicyUnmarshalJSON_FieldErrorPaths with new cases covering invalid JSON types for promotion-label and demotion-label. |
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
This was referenced Jun 17, 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:
AllowOnlyPolicy.UnmarshalJSONFunction Analyzed
internal/config(*AllowOnlyPolicy).UnmarshalJSONWhy This Function?
AllowOnlyPolicy.UnmarshalJSONis the most complex under-tested function in the testable packages. It manually parses JSON for a security-critical policy type using a 12-case switch, validating each field's type individually. Despite most error paths being covered, two branches forpromotion-labelanddemotion-labelwere completely uncovered — fields added later that weren't added to the existing error-path test table.Tests Added
Two new table-driven cases in
TestAllowOnlyPolicyUnmarshalJSON_FieldErrorPaths:promotion-labelfield rejects non-string JSON values (e.g. numeric123)demotion-labelfield rejects non-string JSON values (e.g. array[1,2,3])These follow the exact same pattern as the nine existing error-path cases for
min-integrity,blocked-users,tool-call-limits,approval-labels,trusted-users,endorsement-reactions,disapproval-reactions,disapproval-integrity, andendorser-min-integrity.Coverage Report
The remaining 2.7% is the
reposerror branch at line 191 — unreachable dead code becausejson.Unmarshalintointerface{}never fails on valid JSON input (and all values come frommap[string]json.RawMessageso they are always valid).Test Execution
Generated by Test Coverage Improver
Next run will target the next most complex under-tested function
Warning
Firewall blocked 7 domains
The following domains were blocked by the firewall during workflow execution:
go.opentelemetry.iogo.yaml.ingolang.orggoogle.golang.orggopkg.inproxy.golang.orgsum.golang.orgSee Network Configuration for more information.