Skip to content

Use adapter equality for multi-context :scope#1770

Open
RedZapdos123 wants to merge 1 commit intofb55:masterfrom
RedZapdos123:fix-1767-scope-context-equals
Open

Use adapter equality for multi-context :scope#1770
RedZapdos123 wants to merge 1 commit intofb55:masterfrom
RedZapdos123:fix-1767-scope-context-equals

Conversation

@RedZapdos123
Copy link
Copy Markdown

@RedZapdos123 RedZapdos123 commented Apr 5, 2026

Description:

  • Make :scope use adapter equality consistently for multiple context nodes.
  • Replace reference-based context.includes(element) with context.some(node => equals(node, element)).
  • Add regression test covering multiple context elements with a custom adapter equals implementation.

Verification:

  • npm run test:vi
  • npm run build
  • direct runtime reproduction now returns multi=2 (was multi=0)

Fixes #1767

Summary by CodeRabbit

  • Bug Fixes

    • Improved :scope pseudo-selector to correctly handle context matching with custom adapters using equivalent comparison instead of reference equality.
  • Tests

    • Added test coverage for :scope selector behavior with multiple context elements and custom adapter equality logic.

Signed-off-by: Mridankan Mandal <xerontitan90@gmail.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 5, 2026

📝 Walkthrough

Walkthrough

Updated the :scope pseudo-selector filter to use adapter-aware equality comparison for all context sizes. Previously it used reference-based inclusion checking; now it consistently applies the adapter's equals method via context.some() to determine membership, ensuring uniform behavior regardless of context length.

Changes

Cohort / File(s) Summary
Scope pseudo-selector equality fix
src/pseudo-selectors/filters.ts
Changed membership check from reference-based context.includes(element) to adapter-aware context.some((node) => equals(node, element)) for consistent equality semantics.
Adapter equality test
test/api.ts
Added test case validating :scope with multiple context nodes using custom adapter with overridden equals method to ensure adapter-based equality is applied correctly across context roots.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A scope predicate, once inconsistent in its ways,
Now checks all nodes with equal gaze.
Custom adapters bloom, no reference bias—
Context equality, now bright and righteous! 🌟

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The pull request directly addresses issue #1767 by replacing reference-based context.includes() with context.some() using adapter equality, fixing the inconsistent behavior of :scope with multiple context nodes.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the :scope pseudo-selector equality semantics: code change to filters.ts and corresponding test case in api.ts remain focused on the stated objective.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title accurately describes the main change: switching from reference-based equality to adapter equality for the :scope pseudo-selector when handling multiple context nodes.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@RedZapdos123 RedZapdos123 changed the title fix: use adapter equality for multi-context :scope Use adapter equality for multi-context :scope Apr 5, 2026
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.

:scope with multiple context nodes bypasses adapter equals and uses reference includes

2 participants