Skip to content

test(drive): cover shared-prefix aggregate index insertion#3961

Draft
thephez wants to merge 2 commits into
v3.1-devfrom
test/index-set-conflict
Draft

test(drive): cover shared-prefix aggregate index insertion#3961
thephez wants to merge 2 commits into
v3.1-devfrom
test/index-set-conflict

Conversation

@thephez

@thephez thephez commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

Issue being fixed or feature implemented

Adds regression coverage for #3960.

A data contract can currently be accepted with shared-prefix document indexes where a shorter aggregate index and a deeper range index produce a Drive layout that cannot be materialized during document insertion. The reported shape is a [resourceId] count+sum index combined with a [resourceId, rating] range-countable index.

This PR adds Drive e2e coverage for that accepted-but-uninsertable contract shape and related wrapper-matrix variants.

What was done?

  • Added a new Drive contract insertion e2e test module for shared-prefix aggregate index layouts.
  • Registered the module under insert_contract/v0/tests.
  • Added the reported review contract shape as a regression case.
  • Expanded coverage into a matrix for:
    • count-only prefix parents
    • sum-only prefix parents
    • count+sum prefix parents
    • plain, range-count, range-sum, and range count+sum child continuations
  • Marked compatible controls as cases that must insert successfully.
  • Allowed unsupported layouts to pass only if they are rejected at contract creation or made insertable by Drive in a future fix.

How Has This Been Tested?

Targeted command:

cargo test -p drive shared_prefix_aggregate_index_combinations_reject_or_insert -- --nocapture

Current result: fails as expected, listing the accepted shared-prefix layouts that cannot be inserted today. The compatible control cases insert successfully.

Observed failing accepted layouts include:

  • count_parent_range_sum_child
  • count_parent_range_count_sum_child
  • sum_parent_plain_child
  • sum_parent_range_count_child
  • count_sum_parent_plain_child
  • count_sum_parent_range_count_child

These failures are the intended regression signal until the platform either rejects unsupported layouts during contract validation or supports them during Drive insertion.

Breaking Changes

None. This PR adds test coverage only.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

Summary by CodeRabbit

  • Tests
    • Added end-to-end coverage for shared-prefix index configurations.
    • Expanded validation checks across multiple layout combinations to ensure valid setups work as expected and incompatible ones are rejected.
    • Improved confidence in document insertion behavior for these index patterns.

thephez added 2 commits June 24, 2026 16:54
Adds a Drive e2e regression test for the accepted contract shape from #3960: a count+sum prefix index combined with a deeper range-countable index sharing that prefix. The test currently fails with the unsupported NotCountedOrSummed wrapping error, documenting the gap until validation or layout support is fixed.
Extends the shared-prefix aggregate index regression coverage to exercise count-only, sum-only, and count+sum parent value trees against plain, range-count, range-sum, and combined range count+sum child continuations. The matrix distinguishes compatible cases that must insert from unsupported layouts that should either be rejected during contract validation or supported by Drive insertion.
@coderabbitai

coderabbitai Bot commented Jun 24, 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

Run ID: 1f390eff-a412-464b-92be-0fb3d521f2e5

📥 Commits

Reviewing files that changed from the base of the PR and between 87f6b73 and bd2bd25.

📒 Files selected for processing (2)
  • packages/rs-drive/src/drive/contract/insert/insert_contract/v0/tests/mod.rs
  • packages/rs-drive/src/drive/contract/insert/insert_contract/v0/tests/shared_prefix_aggregation_e2e_tests.rs

📝 Walkthrough

Walkthrough

Adds a new end-to-end test module for insert contract v0 shared-prefix aggregate index layouts, wires it into the test suite, builds contracts from parent/child flag combinations, and exercises contract application plus document insertion across a case matrix.

Changes

Shared-prefix aggregate index coverage

Layer / File(s) Summary
Module registration and case setup
packages/rs-drive/src/drive/contract/insert/insert_contract/v0/tests/mod.rs, packages/rs-drive/src/drive/contract/insert/insert_contract/v0/tests/shared_prefix_aggregation_e2e_tests.rs
Adds the new test module entry and defines the shared-prefix flags, case configuration, and outcome types.
Index and contract construction
packages/rs-drive/src/drive/contract/insert/insert_contract/v0/tests/shared_prefix_aggregation_e2e_tests.rs
Builds index values from flag combinations and assembles the review contract schema and indices.
Contract application and matrix
packages/rs-drive/src/drive/contract/insert/insert_contract/v0/tests/shared_prefix_aggregation_e2e_tests.rs
Applies the contract, inserts review documents for each case, and compares the observed result with the expected outcome matrix.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Suggested reviewers

  • shumkov

Poem

I hopped through indexes, neat and bright,
With shared-prefix leaves in morning light.
I nibbled at cases, one by one,
Until the insert dance was done.
🐰📚 Hop hop—tests now run!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding Drive test coverage for shared-prefix aggregate index insertion.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/index-set-conflict

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.

@thephez thephez marked this pull request as ready for review June 24, 2026 21:13
@thephez thephez requested a review from QuantumExplorer as a code owner June 24, 2026 21:13
@thepastaclaw

thepastaclaw commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

✅ Review complete (commit bd2bd25)

@thephez thephez marked this pull request as draft June 24, 2026 22:12

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Code Review

Test-only PR adds a regression matrix for shared-prefix aggregate index layouts in Drive. The test is intentionally committed in a known-failing state (6 of 12 cases fail today per the PR description, confirmed by Codex running the test), with no #[ignore] or #[should_panic] gating — merging as-is will break cargo test -p drive on the base branch. A secondary issue conflates two distinct failure modes into the same outcome variant, weakening the regression signal.

🔴 1 blocking | 🟡 1 suggestion(s)

🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.

In `packages/rs-drive/src/drive/contract/insert/insert_contract/v0/tests/shared_prefix_aggregation_e2e_tests.rs`:
- [BLOCKING] packages/rs-drive/src/drive/contract/insert/insert_contract/v0/tests/shared_prefix_aggregation_e2e_tests.rs:263-359: Test is committed in a known-failing state and will break CI
  This is a plain `#[test]` with no `#[ignore]` or `#[should_panic]`, yet the PR description states the current result is failure and lists six cases that fail today (`count_parent_range_sum_child`, `count_parent_range_count_sum_child`, `sum_parent_plain_child`, `sum_parent_range_count_child`, `count_sum_parent_plain_child`, `count_sum_parent_range_count_child`). Codex independently ran `cargo test -p drive shared_prefix_aggregate_index_combinations_reject_or_insert` and confirmed it fails.

  The match arm at line 349 unconditionally treats `SharedPrefixOutcome::InsertFailed` as a failure regardless of `must_insert`, so all six cases will produce `assert!(failures.is_empty(), ...)` failures the moment this lands on `v3.1-dev`. Every unrelated PR running the Drive test job will go red until the upstream fix lands.

  The author calls this the "intended regression signal until the platform either rejects unsupported layouts during contract validation or supports them during Drive insertion" — but a green-required CI test is the wrong vehicle for that signal. Options: (a) gate with `#[ignore = "tracks #3960 ..."]`; (b) restructure so today's observed behavior is the *passing* state and the future fix flips the assertion; (c) land alongside the production fix so the matrix passes on merge.

  A secondary structural note: even when this is unblocked, a single `#[test]` looping over 12 cases produces one combined failure message rather than per-case test failures. Splitting into one `#[test]` per case (mirroring `range_countable_index_e2e_tests.rs`) would localize future regressions.
- [SUGGESTION] packages/rs-drive/src/drive/contract/insert/insert_contract/v0/tests/shared_prefix_aggregation_e2e_tests.rs:211-220: `apply_contract` failure is conflated with schema-level `ContractRejected`
  `insert_review_document_for_case` maps two structurally different failure modes onto the same `SharedPrefixOutcome::ContractRejected` variant: factory-level rejection from `build_review_contract` (the genuine "reject at contract creation" fix path) and runtime failure from `drive.apply_contract` (a storage-layer failure, not validation rejection).

  The assertion at line 344 then treats `ContractRejected` as "OK, the contract was rejected at creation time" for `must_insert: false` cases. If a future change starts surfacing the bug at `apply_contract` time (e.g. Drive errors when materializing the index trees rather than during document insertion), this test will silently flip from red to green even though nothing has been fixed at the validation layer this PR is regression coverage for.

  Add an `ApplyFailed(String)` variant and treat it like `InsertFailed` in the assertion so the diagnostic output identifies precisely which Drive phase broke.

Comment on lines +263 to +359
#[test]
fn shared_prefix_aggregate_index_combinations_reject_or_insert() {
let cases = [
SharedPrefixCase {
name: "count_parent_plain_child",
prefix_flags: IndexFlags::COUNT,
child_flags: IndexFlags::PLAIN,
must_insert: true,
},
SharedPrefixCase {
name: "count_parent_range_count_child",
prefix_flags: IndexFlags::COUNT,
child_flags: IndexFlags::RANGE_COUNT,
must_insert: true,
},
SharedPrefixCase {
name: "count_parent_range_sum_child",
prefix_flags: IndexFlags::COUNT,
child_flags: IndexFlags::RANGE_SUM,
must_insert: false,
},
SharedPrefixCase {
name: "count_parent_range_count_sum_child",
prefix_flags: IndexFlags::COUNT,
child_flags: IndexFlags::RANGE_COUNT_SUM,
must_insert: false,
},
SharedPrefixCase {
name: "sum_parent_plain_child",
prefix_flags: IndexFlags::SUM,
child_flags: IndexFlags::PLAIN,
must_insert: false,
},
SharedPrefixCase {
name: "sum_parent_range_count_child",
prefix_flags: IndexFlags::SUM,
child_flags: IndexFlags::RANGE_COUNT,
must_insert: false,
},
SharedPrefixCase {
name: "sum_parent_range_sum_child",
prefix_flags: IndexFlags::SUM,
child_flags: IndexFlags::RANGE_SUM,
must_insert: true,
},
SharedPrefixCase {
name: "sum_parent_range_count_sum_child",
prefix_flags: IndexFlags::SUM,
child_flags: IndexFlags::RANGE_COUNT_SUM,
must_insert: true,
},
SharedPrefixCase {
name: "count_sum_parent_plain_child",
prefix_flags: IndexFlags::COUNT_SUM,
child_flags: IndexFlags::PLAIN,
must_insert: false,
},
SharedPrefixCase {
name: "count_sum_parent_range_count_child",
prefix_flags: IndexFlags::COUNT_SUM,
child_flags: IndexFlags::RANGE_COUNT,
must_insert: false,
},
SharedPrefixCase {
name: "count_sum_parent_range_sum_child",
prefix_flags: IndexFlags::COUNT_SUM,
child_flags: IndexFlags::RANGE_SUM,
must_insert: true,
},
SharedPrefixCase {
name: "count_sum_parent_range_count_sum_child",
prefix_flags: IndexFlags::COUNT_SUM,
child_flags: IndexFlags::RANGE_COUNT_SUM,
must_insert: true,
},
];

let failures = cases
.iter()
.filter_map(|case| match insert_review_document_for_case(case) {
SharedPrefixOutcome::Inserted => None,
SharedPrefixOutcome::ContractRejected(_) if !case.must_insert => None,
SharedPrefixOutcome::ContractRejected(error) => Some(format!(
"{}: compatible shared-prefix aggregate indexes were rejected: {}",
case.name, error
)),
SharedPrefixOutcome::InsertFailed(error) => Some(format!("{}: {}", case.name, error)),
})
.collect::<Vec<_>>();

assert!(
failures.is_empty(),
"shared-prefix aggregate index contracts must either reject unsupported layouts at \
contract creation or allow document insertion; incompatible accepted layouts failed for:\n{}",
failures.join("\n")
);
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🔴 Blocking: Test is committed in a known-failing state and will break CI

This is a plain #[test] with no #[ignore] or #[should_panic], yet the PR description states the current result is failure and lists six cases that fail today (count_parent_range_sum_child, count_parent_range_count_sum_child, sum_parent_plain_child, sum_parent_range_count_child, count_sum_parent_plain_child, count_sum_parent_range_count_child). Codex independently ran cargo test -p drive shared_prefix_aggregate_index_combinations_reject_or_insert and confirmed it fails.

The match arm at line 349 unconditionally treats SharedPrefixOutcome::InsertFailed as a failure regardless of must_insert, so all six cases will produce assert!(failures.is_empty(), ...) failures the moment this lands on v3.1-dev. Every unrelated PR running the Drive test job will go red until the upstream fix lands.

The author calls this the "intended regression signal until the platform either rejects unsupported layouts during contract validation or supports them during Drive insertion" — but a green-required CI test is the wrong vehicle for that signal. Options: (a) gate with #[ignore = "tracks #3960 ..."]; (b) restructure so today's observed behavior is the passing state and the future fix flips the assertion; (c) land alongside the production fix so the matrix passes on merge.

A secondary structural note: even when this is unblocked, a single #[test] looping over 12 cases produces one combined failure message rather than per-case test failures. Splitting into one #[test] per case (mirroring range_countable_index_e2e_tests.rs) would localize future regressions.

Suggested change
#[test]
fn shared_prefix_aggregate_index_combinations_reject_or_insert() {
let cases = [
SharedPrefixCase {
name: "count_parent_plain_child",
prefix_flags: IndexFlags::COUNT,
child_flags: IndexFlags::PLAIN,
must_insert: true,
},
SharedPrefixCase {
name: "count_parent_range_count_child",
prefix_flags: IndexFlags::COUNT,
child_flags: IndexFlags::RANGE_COUNT,
must_insert: true,
},
SharedPrefixCase {
name: "count_parent_range_sum_child",
prefix_flags: IndexFlags::COUNT,
child_flags: IndexFlags::RANGE_SUM,
must_insert: false,
},
SharedPrefixCase {
name: "count_parent_range_count_sum_child",
prefix_flags: IndexFlags::COUNT,
child_flags: IndexFlags::RANGE_COUNT_SUM,
must_insert: false,
},
SharedPrefixCase {
name: "sum_parent_plain_child",
prefix_flags: IndexFlags::SUM,
child_flags: IndexFlags::PLAIN,
must_insert: false,
},
SharedPrefixCase {
name: "sum_parent_range_count_child",
prefix_flags: IndexFlags::SUM,
child_flags: IndexFlags::RANGE_COUNT,
must_insert: false,
},
SharedPrefixCase {
name: "sum_parent_range_sum_child",
prefix_flags: IndexFlags::SUM,
child_flags: IndexFlags::RANGE_SUM,
must_insert: true,
},
SharedPrefixCase {
name: "sum_parent_range_count_sum_child",
prefix_flags: IndexFlags::SUM,
child_flags: IndexFlags::RANGE_COUNT_SUM,
must_insert: true,
},
SharedPrefixCase {
name: "count_sum_parent_plain_child",
prefix_flags: IndexFlags::COUNT_SUM,
child_flags: IndexFlags::PLAIN,
must_insert: false,
},
SharedPrefixCase {
name: "count_sum_parent_range_count_child",
prefix_flags: IndexFlags::COUNT_SUM,
child_flags: IndexFlags::RANGE_COUNT,
must_insert: false,
},
SharedPrefixCase {
name: "count_sum_parent_range_sum_child",
prefix_flags: IndexFlags::COUNT_SUM,
child_flags: IndexFlags::RANGE_SUM,
must_insert: true,
},
SharedPrefixCase {
name: "count_sum_parent_range_count_sum_child",
prefix_flags: IndexFlags::COUNT_SUM,
child_flags: IndexFlags::RANGE_COUNT_SUM,
must_insert: true,
},
];
let failures = cases
.iter()
.filter_map(|case| match insert_review_document_for_case(case) {
SharedPrefixOutcome::Inserted => None,
SharedPrefixOutcome::ContractRejected(_) if !case.must_insert => None,
SharedPrefixOutcome::ContractRejected(error) => Some(format!(
"{}: compatible shared-prefix aggregate indexes were rejected: {}",
case.name, error
)),
SharedPrefixOutcome::InsertFailed(error) => Some(format!("{}: {}", case.name, error)),
})
.collect::<Vec<_>>();
assert!(
failures.is_empty(),
"shared-prefix aggregate index contracts must either reject unsupported layouts at \
contract creation or allow document insertion; incompatible accepted layouts failed for:\n{}",
failures.join("\n")
);
}
#[test]
#[ignore = "tracks #3960: shared-prefix aggregate index layouts are accepted at contract creation but currently fail during document insertion; un-ignore when contract validation rejects them or Drive supports them"]
fn shared_prefix_aggregate_index_combinations_reject_or_insert() {

source: ['claude', 'codex']

Comment on lines +211 to +220
fn insert_review_document_for_case(case: &SharedPrefixCase) -> SharedPrefixOutcome {
let drive = setup_drive_with_initial_state_structure(None);
let pv = PlatformVersion::latest();
let contract = match build_review_contract(case.prefix_flags, case.child_flags) {
Ok(contract) => contract,
Err(error) => return SharedPrefixOutcome::ContractRejected(error),
};
if let Err(error) = apply_contract(&drive, &contract) {
return SharedPrefixOutcome::ContractRejected(error);
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🟡 Suggestion: apply_contract failure is conflated with schema-level ContractRejected

insert_review_document_for_case maps two structurally different failure modes onto the same SharedPrefixOutcome::ContractRejected variant: factory-level rejection from build_review_contract (the genuine "reject at contract creation" fix path) and runtime failure from drive.apply_contract (a storage-layer failure, not validation rejection).

The assertion at line 344 then treats ContractRejected as "OK, the contract was rejected at creation time" for must_insert: false cases. If a future change starts surfacing the bug at apply_contract time (e.g. Drive errors when materializing the index trees rather than during document insertion), this test will silently flip from red to green even though nothing has been fixed at the validation layer this PR is regression coverage for.

Add an ApplyFailed(String) variant and treat it like InsertFailed in the assertion so the diagnostic output identifies precisely which Drive phase broke.

Suggested change
fn insert_review_document_for_case(case: &SharedPrefixCase) -> SharedPrefixOutcome {
let drive = setup_drive_with_initial_state_structure(None);
let pv = PlatformVersion::latest();
let contract = match build_review_contract(case.prefix_flags, case.child_flags) {
Ok(contract) => contract,
Err(error) => return SharedPrefixOutcome::ContractRejected(error),
};
if let Err(error) = apply_contract(&drive, &contract) {
return SharedPrefixOutcome::ContractRejected(error);
}
fn insert_review_document_for_case(case: &SharedPrefixCase) -> SharedPrefixOutcome {
let drive = setup_drive_with_initial_state_structure(None);
let pv = PlatformVersion::latest();
let contract = match build_review_contract(case.prefix_flags, case.child_flags) {
Ok(contract) => contract,
Err(error) => return SharedPrefixOutcome::ContractRejected(error),
};
if let Err(error) = apply_contract(&drive, &contract) {
return SharedPrefixOutcome::ApplyFailed(error);
}

source: ['claude']

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.

2 participants