Skip to content

refactor: centralize subtree path validation on Element::is_any_tree (PCPS regression coverage) - #743

Merged
QuantumExplorer merged 3 commits into
dashpay:developfrom
thepastaclaw:fix-check-subtree-pcps
Aug 22, 2026
Merged

QuantumExplorer merged 3 commits into
dashpay:developfrom
thepastaclaw:fix-check-subtree-pcps

Conversation

@thepastaclaw

@thepastaclaw thepastaclaw commented May 23, 2026 •

Copy link
Copy Markdown
Contributor

Centralize subtree path validation on Element::is_any_tree()

Summary

Originally opened as the fix for #710 (check_subtree_exists omitted ProvableCountProvableSumTree, so is_empty_tree, delete with validate_tree_at_path_exists, delete_up_tree, and check_subtree_exists_invalid_path all failed with PathNotFound for paths whose parent is a PCPS tree). That omission was closed on develop by #657 (c9cd4672), which added the PCPS and indexed variants to the hand-maintained list; #787 then had to patch the same list again for PrivateDocumentStore.

This PR now:

  • Replaces the 17-variant match in check_subtree_exists with Element::is_any_tree() — the single source of truth for "this element is a subtree" (it already looks through NonCounted / NotSummed / NotCountedOrSummed). Future tree types can no longer drift out of path validation.
  • Adds the regression coverage [audit][medium] check_subtree_exists omits ProvableCountProvableSumTree #710 asked for: is_empty_tree on a PCPS subtree and a validated delete through a PCPS path.

No behavior change against current develop (is_any_tree() is the same 17-variant set), so nothing to version-gate.

Closes #710.

Validation

cargo fmt --all --check
cargo clippy -p grovedb --all-features -- -D warnings
cargo test -p grovedb --all-features -- is_empty_tree check_subtree_exists delete_with_validate_tree_at_path_exists provable_count_provable_sum

Summary by CodeRabbit

  • Bug Fixes

    • Improved subtree validation to correctly recognize supported tree types, including wrapped and newly supported variants.
    • Enhanced path-based operations so validation and deletion work reliably within nested tree structures.
  • Tests

    • Added coverage for empty and non-empty subtree detection.
    • Added validation for successfully deleting items from nested tree paths and confirming they are no longer found.

@coderabbitai

coderabbitai Bot commented May 23, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: c353ce2c-37b1-44da-8dcc-d1bb5142197d

📥 Commits

Reviewing files that changed from the base of the PR and between 37267ad and 4dc371f.

📒 Files selected for processing (1)
  • grovedb/src/operations/get/mod.rs

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The PR updates check_subtree_exists to recognize any tree element through is_any_tree(). It also exports path-query types and adds tests for empty-tree detection and validated deletion under nested ProvableCountProvableSumTree elements.

Changes

SubTree Existence Validation

Layer / File(s) Summary
Get-module exports and subtree validation
grovedb/src/operations/get/mod.rs
Declares path-query modules, re-exports AxisAggregateValue and PathQueryRun, and replaces explicit tree matching with is_any_tree().
ProvableCountProvableSumTree traversal tests
grovedb/src/tests/is_empty_tree_tests.rs, grovedb/src/tests/operations_coverage_tests.rs
Adds tests for empty and non-empty states, validated deletion, and post-deletion lookup failure.

Estimated code review effort: 2 (Simple) | ~8 minutes

Merge Risk: ⚪ Minimal · up to 4dc37

This change centralizes existing subtree-path validation and adds regression coverage without changing intended behavior. No actionable merge-blocking risk remains beyond normal checks and review.

Suggested reviewers: quantumexplorer

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the subtree validation refactor and PCPS regression coverage.
Linked Issues check ✅ Passed The change centralizes tree recognition and adds both PCPS regression tests requested by issue #710.
Out of Scope Changes check ✅ Passed The implementation and tests directly support the linked issue objectives, with no unrelated changes identified.
Docstring Coverage ✅ Passed Docstring coverage is 85.71% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 3 files.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@thepastaclaw

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 23, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@codecov

codecov Bot commented May 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.41%. Comparing base (80dce0b) to head (4dc371f).

Additional details and impacted files
@@           Coverage Diff            @@
##           develop     #743   +/-   ##
========================================
  Coverage    92.41%   92.41%           
========================================
  Files          289      289           
  Lines        89316    89316           
========================================
  Hits         82537    82537           
  Misses        6779     6779           
Components Coverage Δ
grovedb-core 90.64% <100.00%> (ø)
merk 93.27% <ø> (ø)
storage 87.08% <ø> (ø)
commitment-tree 96.38% <ø> (ø)
mmr 96.49% <ø> (ø)
bulk-append-tree 92.43% <ø> (ø)
element 97.98% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@thepastaclaw

thepastaclaw commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ Review complete (commit 0dbebe9)

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

Small, focused fix that swaps the hand-rolled tree-variant match in check_subtree_exists for the centralized Element::is_any_tree() helper, closing the gap where ProvableCountProvableSumTree paths were rejected. Two regression tests cover the realistic entry points. One nitpick: the explicit into_underlying() before is_any_tree() is redundant since is_any_tree() already unwraps via underlying().

💬 1 nitpick(s)

Comment thread grovedb/src/operations/get/mod.rs Outdated
Comment on lines 404 to 408
match element.map(|e| e.into_underlying()) {
Ok(Element::Tree(..))
| Ok(Element::SumTree(..))
| Ok(Element::BigSumTree(..))
| Ok(Element::CountTree(..))
| Ok(Element::CountSumTree(..))
| Ok(Element::ProvableCountTree(..))
| Ok(Element::ProvableCountSumTree(..))
| Ok(Element::ProvableSumTree(..))
| Ok(Element::CommitmentTree(..))
| Ok(Element::MmrTree(..))
| Ok(Element::BulkAppendTree(..))
| Ok(Element::DenseAppendOnlyFixedSizeTree(..)) => Ok(()).wrap_with_cost(cost),
Ok(e) if e.is_any_tree() => Ok(()).wrap_with_cost(cost),
Ok(_) | Err(Error::PathKeyNotFound(_)) => Err(error_fn()).wrap_with_cost(cost),
Err(e) => Err(e).wrap_with_cost(cost),
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 Nitpick: Redundant into_underlying() before is_any_tree()

Element::is_any_tree() already invokes self.underlying() internally to look through NonCounted / NotSummed / NotCountedOrSummed wrappers (see grovedb-element/src/element/helpers.rs:323 and :56-63). Calling into_underlying() first re-does that unwrap, and for wrapped variants it performs an owned *inner boxed-element move on every successful subtree check. Since the subsequent arms no longer pattern-match against a specific unwrapped variant, you can pass the element straight to is_any_tree() and let the helper handle wrapper transparency. The comment about looking through NonCounted remains accurate either way.

Suggested change
match element.map(|e| e.into_underlying()) {
Ok(Element::Tree(..))
| Ok(Element::SumTree(..))
| Ok(Element::BigSumTree(..))
| Ok(Element::CountTree(..))
| Ok(Element::CountSumTree(..))
| Ok(Element::ProvableCountTree(..))
| Ok(Element::ProvableCountSumTree(..))
| Ok(Element::ProvableSumTree(..))
| Ok(Element::CommitmentTree(..))
| Ok(Element::MmrTree(..))
| Ok(Element::BulkAppendTree(..))
| Ok(Element::DenseAppendOnlyFixedSizeTree(..)) => Ok(()).wrap_with_cost(cost),
Ok(e) if e.is_any_tree() => Ok(()).wrap_with_cost(cost),
Ok(_) | Err(Error::PathKeyNotFound(_)) => Err(error_fn()).wrap_with_cost(cost),
Err(e) => Err(e).wrap_with_cost(cost),
}
match element {
Ok(ref e) if e.is_any_tree() => Ok(()).wrap_with_cost(cost),
Ok(_) | Err(Error::PathKeyNotFound(_)) => Err(error_fn()).wrap_with_cost(cost),
Err(e) => Err(e).wrap_with_cost(cost),
}

source: ['claude']

@thepastaclaw
thepastaclaw marked this pull request as ready for review June 16, 2026 07:06
@thepastaclaw

Copy link
Copy Markdown
Contributor Author

@QuantumExplorer Could you take a look at the current head 0dbebe9b when you have a chance? This is a focused fix for PCPS-tree path validation: it uses is_any_tree() and adds traversal/deletion regression coverage. All current checks, Codecov, and CodeRabbit are green, and the branch is mergeable.

@thepastaclaw
thepastaclaw force-pushed the fix-check-subtree-pcps branch from 0dbebe9 to 0223de0 Compare August 2, 2026 14:35
@thepastaclaw
thepastaclaw force-pushed the fix-check-subtree-pcps branch from 0223de0 to 37267ad Compare August 20, 2026 20:31
QuantumExplorer and others added 2 commits August 22, 2026 16:27
…subtree_exists

`Element::is_any_tree()` already looks through the NonCounted /
NotSummed / NotCountedOrSummed wrappers via `underlying()`, so the
preceding `into_underlying()` re-did that unwrap and moved the boxed
inner element on every successful check. Match on the element itself
(review nitpick), and say in the comment why the helper — not a
hand-kept variant list — is the source of truth here.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@QuantumExplorer QuantumExplorer changed the title fix: accept PCPS trees in path validation refactor: centralize subtree path validation on Element::is_any_tree (PCPS regression coverage) Aug 22, 2026
@QuantumExplorer

Copy link
Copy Markdown
Member

This is Claude. Fixed up for merge:

Local: fmt clean, clippy -p grovedb -D warnings clean, targeted grovedb tests 135/135.

@QuantumExplorer
QuantumExplorer merged commit 0e904fe into dashpay:develop Aug 22, 2026
11 checks passed
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.

[audit][medium] check_subtree_exists omits ProvableCountProvableSumTree

2 participants