[#4253 2/8] feat(pe): PD validators (Validate + ValidateSelectionKeys)#4281
Draft
stevenvegt wants to merge 1 commit into
Draft
[#4253 2/8] feat(pe): PD validators (Validate + ValidateSelectionKeys)#4281stevenvegt wants to merge 1 commit into
stevenvegt wants to merge 1 commit into
Conversation
Assisted-by: AI
Contributor
|
Coverage Impact ⬇️ Merging this pull request will decrease total coverage on 🛟 Help
|
This was referenced May 27, 2026
Draft
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.

Parent PRD
#4253
Item 2 of 8. Independent of item #1 (branches off the feature branch; can proceed in parallel).
Summary
Add two pure validators to
vcr/pe:Validate(Policy 7, load-time PD consistency) andValidateSelectionKeys(Policy 1,credential_selectionkey validation). Both are pure functions with typed errors and aggregate-all reporting. No caller is wired in this PR — the loader (policy/,discovery/) consumesValidatein item #7, and the API handlers consumeValidateSelectionKeysin item #6.Implementation Spec
func Validate(pd PresentationDefinition) error— Policy 7Semantic checks that JSON Schema cannot express. The PD has already passed schema validation (
v2.Validate, which checks structure: required fields, types,additionalProperties, etc.) before this runs;Validateis a second, cross-field semantic pass on the parsedPresentationDefinition.Constraints.Fields, no two fields may share the sameid(PEX requirement; not expressible in the JSON schema).idvalue-set consistency. For every fieldidappearing on two or more field-objects across descriptors, the value it binds to must satisfy every field's filter at once, so the intersection of the fields' allowed-value sets must be non-empty. Each filter is modelled as a value set:const c→{c};enum [...]→ that finite set;type-only / no filter → the universe of that type;pattern→ a regex predicate.Filter.Typefor the id must be equal (mixed types can never agree; pins the type).constorenum: compute the intersection of all consts (as singletons) and all enum sets, then keep only values matching every declaredpattern. Empty result → conflict. This catches differing consts, const-not-in-enum, disjoint enums, const-fails-pattern, and no-enum-value-matches-pattern.type+ one or morepatterns (no const/enum), the intersection is undecidable (regexp2is not a regular language), so it is not checked at load. This degrades gracefully: at request time no credential can satisfy both patterns, the match fails, and theMatchReportfrom added baseline funcs from old repo #1 surfaces the no-eligible-candidate / binding conflict with the path and value.paths are always allowed (same id resolved from different JSONPaths on different credential types).func ValidateSelectionKeys(selection map[string]string, pds ...PresentationDefinition) error— Policy 1Typed errors
Typed errors let item #6 build the OAuth
invalid_requestdescription (and #7 log structured detail) without string-parsing; theError()strings stay human-readable for logs and operators.Testing
Black-box
validate_test.go, no mocks or fixtures.Validate:PDValidationError.ValidateSelectionKeys: unknown key against a single PD; unknown key against a two-PD union; a key targeting only one side of a two-PD union passes; all-known passes; empty-string value validated by name; multiple unknown keys all listed and sorted.Acceptance Criteria
Validateenforces id-uniqueness-within-constraints and same-idvalue-set non-empty intersection (type/const/enum + concrete-value-vs-pattern); defers only pattern-vs-pattern; ignores path differences.ValidateSelectionKeysvalidates key names against the union of the supplied PDs; ignores values.vcr/pe); existingvcr/petests still green.go build ./...andgo test ./vcr/pe/...pass.