Refactor guard policy integrity normalization to remove duplicated validation paths#6915
Merged
Merged
Conversation
6 tasks
Copilot
AI
changed the title
[WIP] Refactor duplicate code for optional integrity field validation
Refactor guard policy integrity normalization to remove duplicated validation paths
Jun 2, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors NormalizeGuardPolicy integrity field handling by extracting duplicated trim/lowercase + allowed-values validation logic into a single helper, keeping validation behavior and error formatting consistent as the guard policy schema evolves.
Changes:
- Added
validateAndNormalizeIntegrityField(fieldPath, raw, optional)to centralize integrity normalization/validation. - Replaced inline validation for
allow-only.min-integrity,allow-only.disapproval-integrity, andallow-only.endorser-min-integritywith the shared helper. - Added unit tests to cover normalization, required/optional empty handling, and invalid-value rejection.
Show a summary per file
| File | Description |
|---|---|
| internal/config/guard_policy_validation.go | Consolidates integrity field normalization/validation into a helper and wires it into NormalizeGuardPolicy. |
| internal/config/guard_policy_test.go | Adds targeted tests for the new shared integrity validation helper. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 0
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.
NormalizeGuardPolicyhad three near-identical integrity validation blocks (min-integrity,disapproval-integrity,endorser-min-integrity) with repeated trim/lowercase + allowed-values checks. This change centralizes that logic to keep field handling and error formatting consistent as integrity fields evolve.Validation refactor
validateAndNormalizeIntegrityField(fieldPath, raw, optional)ininternal/config/guard_policy_validation.go.allow-only.min-integrityallow-only.disapproval-integrityallow-only.endorser-min-integrityBehavior preserved, duplication removed
Focused coverage for shared helper
TestValidateAndNormalizeIntegrityFieldininternal/config/guard_policy_test.goto cover: