feat(secrets): add Dedupe to remove subsumed patterns - #629
Open
joe0BAB wants to merge 1 commit into
Open
Conversation
joe0BAB
marked this pull request as ready for review
August 20, 2026 13:52
docker-agent
left a comment
Contributor
There was a problem hiding this comment.
Assessment: 🟢 APPROVE
No bugs found in the changed code. The Dedupe function, canonicalize, and includes DP are all correct.
Summary: This PR introduces a well-implemented pattern deduplication algorithm. Key areas checked:
canonicalize: Correctly collapses adjacent wildcards —starsandgapaccumulate independently and are emitted together inflush(). Stars before**are not lost; they stay instarsand are emitted first. Patterns like**/*,*/**, and**all correctly collapse to the same[*, **]canonical form.includesDP: The two-row rolling array (prev/cur) is fully overwritten on every outer iteration (bothcur[nq]at the top and allcur[j]in the inner loop), so no stale values bleed through. Theq[j]=tokenGapcase formulap[i].kind==tokenStar && cur[j+1] && prev[j]correctly requires both: gap=0 expansion (cur[j+1]) and gap≥1 expansion (prev[j]), and correctly rejects literals since they can't cover all gap expansions.Dedupeloop: The mutual-inclusion tie-breaking (keep earlier entry whenj < i, keepiwhen mutual) is sound. Transitivity ensures that even if a dominatorjis itself later dominated,iis still correctly dropped.subsumesfilters:firstLit/lastLitare correctly""for wildcard-anchored entries (zero value ofstring), so the literal-anchor filters only fire whenothertruly starts/ends with a literal.- Tests: The exhaustive oracle in
TestDedupeExhaustive(checking all 84 patterns against all identifiers up to 9 components) provides strong correctness evidence.
joe0BAB
force-pushed
the
feat/proto
branch
2 times, most recently
from
August 20, 2026 14:07
28e1dd2 to
86dbf27
Compare
Dedupe collapses a pattern list to its maximal elements: patterns whose matches are fully covered by another entry are dropped, equivalent spellings (e.g. **, **/* and */**) keep their first occurrence, and input order is preserved. Containment is decided as true language containment over identifiers, computed on canonical token sequences with an O(L^2) DP per pair; length, shape and literal-anchor filters skip most pairs. This is deliberately stricter than Pattern.Includes, which also treats a literal as covering '*' and '*' as covering '**'. Verified against a brute-force oracle: every pattern pair with up to three components, checked against all identifiers with up to nine components over a three-symbol alphabet. Signed-off-by: Johannes Großmann <grossmann.johannes@t-online.de>
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.
Dedupe collapses a pattern list to its maximal elements: patterns whose matches are fully covered by another entry are dropped, equivalent spellings (e.g. *, / and */) keep their first occurrence, and input order is preserved.
Containment is decided as true language containment over identifiers, computed on canonical token sequences with an O(L^2) DP per pair; length, shape and literal-anchor filters skip most pairs. This is deliberately stricter than Pattern.Includes, which also treats a literal as covering '' and '' as covering '**'.
Verified against a brute-force oracle: every pattern pair with up to three components, checked against all identifiers with up to nine components over a three-symbol alphabet.