Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add property tests for filterToOutermost / filterToInnermost#146

Merged
twschiller merged 1 commit into
mainfrom
coverage/dom-utils-filter-property-tests
Jun 5, 2026
Merged

Add property tests for filterToOutermost / filterToInnermost#146
twschiller merged 1 commit into
mainfrom
coverage/dom-utils-filter-property-tests

Conversation

@twschiller

Copy link
Copy Markdown
Contributor

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

  • Subset — result ⊆ input.
  • Ancestor-free / descendant-free — 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 preserves the input ordering.
  • Idempotence — `filterToX(filterToX(xs)) === filterToX(xs)`.
  • Cross-property — `outermost ∩ innermost` is exactly the set of "isolated" candidates (no other candidate as ancestor or descendant).

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

  • `bun run preflight` passes
  • 12 new properties pass (1090 → 1102 total tests)
  • Coverage for `dom-utils.ts` reaches ~98% statements

🤖 Generated with Claude Code

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]>
@vercel

vercel Bot commented Jun 5, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
agent-browser-shield-demo-site Ready Ready Preview, Comment Jun 5, 2026 2:49am

Request Review

@twschiller twschiller merged commit 4557501 into main Jun 5, 2026
7 checks passed
@twschiller twschiller deleted the coverage/dom-utils-filter-property-tests branch June 5, 2026 02:51
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