Add property tests for filterToOutermost / filterToInnermost#146
Merged
Conversation
These helpers dedupe nested candidate sets and are called from every rule that picks elements to act on — a bug here leaks into half the codebase. Enumerated tests cover specific shapes; property tests exercise the underlying algebra against random trees + random candidate subsets. Properties asserted: - subset: result ⊆ input - ancestor-free (outermost) / descendant-free (innermost) — no two result elements have a contains() relationship - maximality: every dropped candidate must have a kept candidate as ancestor (outermost) or descendant (innermost), so the filter doesn't over-prune - order preservation: result respects input order - idempotence: filterToX(filterToX(xs)) === filterToX(xs) - cross-property: outermost ∩ innermost is exactly the set of candidates with no other candidate as relative Trees are generated via an explicit flat encoding (n nodes; parent[i] uniform over [0, i-1]) rather than fc.letrec — the recursive arbitrary blows the stack at fast-check's default depth bias even with depthIdentifier, and weighted-oneof bases were still flaky. The flat encoding produces any tree uniformly within the size cap and always terminates. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Summary
Property-based tests for the two dedupe helpers in `src/lib/dom-utils.ts` (`filterToOutermost` and `filterToInnermost`). These functions sit underneath every rule that picks a set of elements to act on — a bug here leaks into `prompt-injection-redact`, `irrelevant-sections-redact`, `countdown-timer-redact`, `scarcity-redact`, `cart-addon-annotate`, and more. Enumerated tests cover specific shapes; property tests exercise the underlying algebra against random trees and random candidate subsets.
Properties asserted
Generator notes
Trees are generated via an explicit flat encoding (`n` nodes; `parent[i]` uniform over `[0, i-1]`) rather than `fc.letrec`. The recursive arbitrary blew the stack at fast-check's default depth bias even with `depthIdentifier`, and weighted-oneof bases were still flaky. The flat encoding produces any tree shape uniformly within the size cap and always terminates.
Test plan
🤖 Generated with Claude Code