Consolidate integrity-level normalization/validation across config and guard#6996
Merged
Conversation
8 tasks
Copilot
AI
changed the title
[WIP] Refactor integrity field validation to remove duplicates
Consolidate integrity-level normalization/validation across config and guard
Jun 4, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR reduces drift risk by centralizing integrity-level normalization + validation in internal/config, and updating both config normalization and guard WASM payload validation to use the shared implementation.
Changes:
- Added
config.NormalizeIntegrityLevel(raw, optional)to provide a single canonical “trim → lowercase → optional-empty → allowed-values” pipeline. - Refactored config guard-policy normalization (
validateAndNormalizeIntegrityField) to delegate to the shared helper while preserving field-path context via wrapping. - Refactored guard WASM payload validation (
validateIntegrityField) to use the shared helper and removed the duplicated local allowed-values set; updated coupled error-message sources and added focused tests.
Show a summary per file
| File | Description |
|---|---|
| internal/guard/wasm_validate.go | Removes duplicate integrity membership logic and delegates validation to config.NormalizeIntegrityLevel. |
| internal/config/guard_policy.go | Introduces NormalizeIntegrityLevel as the canonical integrity-level normalization/validation helper. |
| internal/config/guard_policy_validation.go | Routes integrity-field validation through the shared helper and wraps errors with field-path context. |
| internal/config/guard_policy_test.go | Adds direct unit tests for the shared integrity normalization/validation behavior. |
| internal/config/guard_policy_parse.go | Updates an error message source to reference the canonical integrity list after removing the old variable. |
| internal/config/guard_policy_parse_test.go | Aligns expected error-message formatting with the updated canonical integrity list reference. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 6/6 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.
Integrity-level validation had duplicated normalization and membership checks in
internal/configandinternal/guard, creating drift risk in behavior and error handling. This change centralizes that logic inconfigand updates both call sites to use a single implementation.Shared integrity validator in
configNormalizeIntegrityLevel(raw string, optional bool) (string, error)ininternal/config/guard_policy.go.trim -> lowercase -> optional-empty handling -> allowed-values check.Refactor existing config validation path
validateAndNormalizeIntegrityFieldininternal/config/guard_policy_validation.gonow delegates toNormalizeIntegrityLeveland preserves field-specific error context.Refactor guard WASM payload validation path
validateIntegrityFieldininternal/guard/wasm_validate.gonow delegates toconfig.NormalizeIntegrityLevelinstead of maintaining its own normalization + set-membership logic.Consistency updates for coupled error-message sources
internal/config/guard_policy_parse.gointernal/config/guard_policy_parse_test.goFocused coverage for shared behavior
NormalizeIntegrityLevelininternal/config/guard_policy_test.go(case/whitespace normalization, optional empty, invalid values).