Skip to content

[#4253 3/8] refactor(pe): rewire Match onto Select, remove selector abstraction#4284

Draft
stevenvegt wants to merge 1 commit into
4253-1-select-enginefrom
4253-3-rewire-select
Draft

[#4253 3/8] refactor(pe): rewire Match onto Select, remove selector abstraction#4284
stevenvegt wants to merge 1 commit into
4253-1-select-enginefrom
4253-3-rewire-select

Conversation

@stevenvegt
Copy link
Copy Markdown
Member

@stevenvegt stevenvegt commented May 27, 2026

Parent PRD

#4253

Item 3 of 8. Depends on item #1 (#4280) — branched off 4253-1-select-engine, retargeted to the feature branch once #1 merges.

Summary

Rewire the public vcr/pe matching API onto Select and delete the CredentialSelector abstraction. The credential_selection path stops constructing a selector and instead passes the selection as Select initial bindings. Net effect: less surface, and a single matching engine. Behavior is preserved for every PD that does not reuse an id across descriptors (i.e. every PD today).

Implementation Spec

vcr/pe/presentation_definition.go

  • Match(vcs []vc.VerifiableCredential, opts ...Option) ([]vc.VerifiableCredential, []InputDescriptorMappingObject, error) — gains variadic options that pass through to Select. Discovery's pd.Match(creds) keeps compiling unchanged (no opts ⇒ FirstMatch, no bindings).
  • Delete MatchWithSelector.
  • Delete matchConstraints, matchBasic, and matchSubmissionRequirements. Their submission-requirement satisfaction now lives inside Select (item added baseline funcs from old repo #1, which reuses the unchanged groups()/apply()/deduplicate() helpers). Match becomes a thin wrapper: build Select options, call Select(pd, vcs, opts...), then build the []InputDescriptorMappingObject descriptor map (paths + dedup, plus the single-VC JSON-LD vs JWT path fixup) from Result.

vcr/pe/selector.go

Delete entirely: CredentialSelector, FirstMatchSelector, NewFieldSelector, fieldSelection, matchesSelections.

Builder (vcr/pe/presentation_submission.go)

Presenter (vcr/holder/presenter.go)

  • Lines 64-72 collapse to: if credentialSelection is non-empty, builder.SetInitialBindings(credentialSelection). The NewFieldSelector construction and its unknown-key error (line 67-70) are removed.
  • Unknown selection keys are now silently dropped by Select; typo protection moves to ValidateSelectionKeys at the API layer (Add verifiable data registry #6). This realizes the PRD's "NewFieldSelector becomes lenient" by deletion.

Behavior preservation (the bar)

For any PD without same-id reuse — every PD deployed today — FirstMatch plus the absence of cross-descriptor bindings means Select picks the same VC per descriptor that FirstMatchSelector / NewFieldSelector did, with no backtracking. So:

  • The existing TestMatch, the submission-requirement, and PresentationSubmission.Validate test scenarios are the characterization safety net for this rewire and pass with no assertion changes. TestPresentationDefinition_MatchWithSelector_SubmissionRequirements is retargeted to call Match (with options) since MatchWithSelector is deleted, but its assertions stay the same.
  • selector_test.go is deleted: its TestNewFieldSelector scenarios are covered by added baseline funcs from old repo #1's characterization tests (Select with bindings), and the strict-unknown-key assertion is dropped (its replacement is ValidateSelectionKeys in added nuts-go-test #2).
  • Any holder/presenter test asserting an error on unknown selection keys is updated to assert the key is dropped (no error).

Submission-requirement satisfaction (apply/groups/deduplicate) is in scope and reused unchanged inside Select. What stays deferred per the PRD is the binding search cooperating with pick min>=1 subset selection: if Select's coarse skip yields a combination that a pick/min rule rejects, it does not re-search for a different binding-consistent combination to satisfy the floor; it reports the failure. Tie-breakers among multiple valid assignments are also deferred.

Testing

  • Existing vcr/pe and vcr/holder suites green, with only the deletions/updates noted above.
  • A focused test that Match(vcs, WithInitialBindings(sel)) produces the same result the old NewFieldSelector path did for a representative selection (belt-and-suspenders alongside added baseline funcs from old repo #1's characterization tests).

Acceptance Criteria

  • Match takes variadic Options and is a thin wrapper over Select (builds the descriptor map from Result via the shared private helper); MatchWithSelector, matchConstraints, matchBasic, and matchSubmissionRequirements removed.
  • selector.go deleted; no references to CredentialSelector/FirstMatchSelector/NewFieldSelector remain.
  • Builder exposes SetInitialBindings; presenter wires credentialSelection through it with no unknown-key error.
  • All existing vcr/pe and vcr/holder tests pass (updated only as described); selector_test.go removed.
  • go build ./... and go test ./vcr/... pass.

@qltysh
Copy link
Copy Markdown
Contributor

qltysh Bot commented May 27, 2026

Qlty


Coverage Impact

This PR will not change total coverage.

🚦 See full report on Qlty Cloud »

🛟 Help
  • Diff Coverage: Coverage for added or modified lines of code (excludes deleted files). Learn more.

  • Total Coverage: Coverage for the whole repository, calculated as the sum of all File Coverage. Learn more.

  • File Coverage: Covered Lines divided by Covered Lines plus Missed Lines. (Excludes non-executable lines including blank lines and comments.)

    • Indirect Changes: Changes to File Coverage for files that were not modified in this PR. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant