Skip to content

test(platform): improve platform-value coverage for patch, value_map, converters, and replacement#3428

Merged
QuantumExplorer merged 5 commits into
v3.1-devfrom
test/platform-value-coverage
Apr 3, 2026
Merged

test(platform): improve platform-value coverage for patch, value_map, converters, and replacement#3428
QuantumExplorer merged 5 commits into
v3.1-devfrom
test/platform-value-coverage

Conversation

@QuantumExplorer
Copy link
Copy Markdown
Member

@QuantumExplorer QuantumExplorer commented Apr 3, 2026

Summary

Adds 219 tests across 5 previously untested files in rs-platform-value, covering real logic.

File Tests What's covered
patch/mod.rs 50 RFC 6902 JSON Patch (add/remove/replace/move/copy/test), rollback, merge
value_map.rs 38 Sorting, key lookup/insert, conditional removal, btree conversion
converter/serde_json.rs 69 JSON conversion, U128/I128 bounds, byte-array heuristic, round-trips
converter/ciborium.rs 30 CBOR round-trips, tag rejection, byte heuristic, map key sorting
btreemap_field_replacement.rs 32 Integer/bytes type replacement, nested path traversal, error paths

Test plan

  • cargo test -p platform-value --lib passes
  • cargo fmt --all clean

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Added extensive unit tests covering serialization/conversion (CBOR, JSON), field replacement, patch operations, and value-map behaviors, including nested/array traversal, error cases, round-trips, and edge heuristics to improve reliability.
  • Chores
    • Removed an unused JSON dependency from a script crate.

…and replacement

Add 219 tests across 5 files covering real logic:
- patch/mod.rs: RFC 6902 JSON Patch operations, rollback, merge
- value_map.rs: sorting, key lookup, conditional removal, map conversion
- converter/serde_json.rs: JSON conversion, U128 bounds, byte heuristic
- converter/ciborium.rs: CBOR round-trips, tag rejection, key sorting
- btreemap_field_replacement.rs: type replacement, path traversal

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added this to the v3.1.0 milestone Apr 3, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 3, 2026

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c78ebf92-0ac0-4738-86eb-c0c5c10d32c7

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This pull request adds extensive unit tests (2,559 lines) across rs-platform-value converters, patching, and map helpers, and removes a serde_json dependency entry from packages/rs-scripts/Cargo.toml. Changes are confined to #[cfg(test)] modules and one Cargo.toml edit.

Changes

Cohort / File(s) Summary
BTreeMap Field Replacement Tests
packages/rs-platform-value/src/btreemap_extensions/btreemap_field_replacement.rs
Added 516 lines of tests for IntegerReplacementType and ReplacementType conversions, byte-length validation, identifier/base58/base64/binary encodings, path-based replacements (replace_at_path, replace_at_paths, replace_consume_value, replace_value_in_place), nested map/array traversal semantics, and traversal error cases.
CBOR Conversion Tests
packages/rs-platform-value/src/converter/ciborium.rs
Added 412 lines of tests for CBOR ↔ Value round-trips (primitives, integers including I128), unsupported tag error handling, array-to-bytes heuristics, deterministic map ordering, narrowing behavior for large integers, fixed-size byte variants, and various helper conversions.
JSON Conversion Tests
packages/rs-platform-value/src/converter/serde_json.rs
Added ~660 lines of tests covering Valueserde_json::Value conversions, validating integer size limits (U128/I128), byte/identifier encodings (base64/bs58), array byte-heuristic behavior, validating JSON paths and BTree converters, round-trips, and NaN handling in validating JSON.
Patch Operation Tests
packages/rs-platform-value/src/patch/mod.rs
Added 566 lines of tests for JSON-Patch-like operations (add, remove, replace, move, copy, test), multi-operation application and rollback behaviors, merge semantics (recursive merge, null-as-removal, replacements), pointer parsing utilities, and error/reporting cases.
Value Map Helper Tests
packages/rs-platform-value/src/value_map.rs
Added 405 lines of tests for ValueMapHelper and related helpers: sorting/order variants, recursive sorting, mutation/insertion helpers, conditional removals, lookup/removal APIs, and conversions to/from BTree/IndexMap including error cases.
Dependency Removal
packages/rs-scripts/Cargo.toml
Removed the serde_json dependency entry from the crate's Cargo.toml (1-line deletion).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 I hopped through tests both long and neat,
Assertions crunchy, coverage sweet,
CBOR, JSON, patches in a row,
Maps and bytes in tidy show,
A carrot for each passing feat!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and specifically summarizes the main change: adding comprehensive test coverage to five modules (patch, value_map, converters, and replacement) in the platform-value crate, improving test coverage significantly.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/platform-value-coverage

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 and usage tips.

@thepastaclaw
Copy link
Copy Markdown
Collaborator

thepastaclaw commented Apr 3, 2026

Review Gate

Commit: 2222ed74

  • Debounce: 24m ago (need 30m)

  • CI checks: checks still running (2 pending)

  • CodeRabbit review: comment found

  • Off-peak hours: off-peak (12:06 PM PT Friday)

  • Run review now (check to override)

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 3, 2026

Codecov Report

❌ Patch coverage is 99.07749% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.63%. Comparing base (7011b62) to head (2222ed7).
⚠️ Report is 5 commits behind head on v3.1-dev.

Files with missing lines Patch % Lines
...ckages/rs-platform-value/src/converter/ciborium.rs 96.87% 8 Missing ⚠️
.../btreemap_extensions/btreemap_field_replacement.rs 98.17% 6 Missing ⚠️
packages/rs-platform-value/src/value_map.rs 99.59% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           v3.1-dev    #3428      +/-   ##
============================================
+ Coverage     80.22%   80.63%   +0.41%     
============================================
  Files          2855     2855              
  Lines        281685   285727    +4042     
============================================
+ Hits         225983   230405    +4422     
+ Misses        55702    55322     -380     
Components Coverage Δ
dpp 73.21% <ø> (+0.20%) ⬆️
drive 82.49% <ø> (+0.14%) ⬆️
drive-abci 86.67% <ø> (ø)
sdk 36.55% <ø> (ø)
dapi-client 79.06% <ø> (ø)
platform-version ∅ <ø> (∅)
platform-value 90.79% <99.07%> (+6.55%) ⬆️
platform-wallet 76.09% <ø> (ø)
drive-proof-verifier 55.26% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@QuantumExplorer QuantumExplorer changed the title test(platform-value): add coverage for patch, value_map, converters, and replacement test(platform): improve platform-value coverage for patch, value_map, converters, and replacement Apr 3, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🧹 Nitpick comments (3)
packages/rs-platform-value/src/btreemap_extensions/btreemap_field_replacement.rs (1)

684-692: Rename this test to match its expected behavior.

The name says “error” but the assertion expects Ok(()). Renaming avoids confusion during failures and triage.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@packages/rs-platform-value/src/btreemap_extensions/btreemap_field_replacement.rs`
around lines 684 - 692, The test function replace_at_path_empty_path_error has a
misleading name because it asserts Ok(()); rename the function to reflect
successful behavior (e.g., replace_at_path_empty_path_ok or
replace_at_path_empty_path_returns_ok) so the name matches the assertion; locate
the test function replace_at_path_empty_path_error and update its identifier
accordingly, keeping the body and assertion unchanged.
packages/rs-platform-value/src/converter/ciborium.rs (1)

530-535: Make this a real round-trip assertion.

Right now any non-empty byte slice passes. Decoding the buffer and comparing it with the original value would actually verify serialization correctness.

Suggested change
 #[test]
 fn to_cbor_buffer_roundtrip() {
     let val = Value::Text("cbor buffer test".into());
     let buf = val.to_cbor_buffer().unwrap();
-    assert!(!buf.is_empty());
+    let decoded: CborValue = ciborium::de::from_reader(buf.as_slice()).unwrap();
+    let back: Value = decoded.try_into().unwrap();
+    assert_eq!(back, val);
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/rs-platform-value/src/converter/ciborium.rs` around lines 530 - 535,
The test to_cbor_buffer_roundtrip currently only asserts the buffer is
non-empty; change it to perform a real round-trip by decoding the buffer back
into a Value and asserting equality with the original Value; specifically call
the corresponding deserializer (e.g., Value::from_cbor_buffer or
Value::from_cbor_bytes) on the buf produced by Value::to_cbor_buffer(), unwrap
the result, and use assert_eq!(decoded, val) so the test verifies correct
serialization/deserialization for the Value type.
packages/rs-platform-value/src/value_map.rs (1)

523-605: LGTM! Miscellaneous tests round out the coverage.

Tests validate:

  • Value-based key operations
  • String insertion
  • BTreeMap conversion
  • Recursive sorting (verifies both outer and inner map ordering)
Minor: Simplify panic message (optional)

Line 603 could use unreachable!() or a shorter message:

         } else {
-            panic!("expected inner map");
+            unreachable!("expected inner map");
         }

This is purely stylistic.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/rs-platform-value/src/value_map.rs` around lines 523 - 605, Replace
the explicit panic! call in the test
sort_by_keys_and_inner_maps_sorts_recursively with a shorter assertion helper
like unreachable!() (or panic! with a shorter message) to simplify the panic
message; locate the branch that currently does panic!("expected inner map")
inside that test and change it to unreachable!() so the failure is clearer and
more idiomatic.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@packages/rs-platform-value/src/btreemap_extensions/btreemap_field_replacement.rs`:
- Around line 441-445: The test replace_for_bytes_20_identifier_error asserts
the wrong error variant for 20-byte input; update the expectation so
ReplacementType::Identifier.replace_for_bytes_20(bytes) asserts
Err(Error::ByteLengthNot20BytesError(_)) (or the project's canonical
20-byte-length error variant) instead of
Err(Error::ByteLengthNot36BytesError(_)); locate this in the test function
replace_for_bytes_20_identifier_error and change the matches! pattern
accordingly to reflect the correct length/error contract.

In `@packages/rs-platform-value/src/converter/ciborium.rs`:
- Around line 367-380: The CBOR conversion currently narrows Value::U128 and
Value::I128 into 64-bit without checking overflow; add tests and/or change the
converter to detect out-of-range 128-bit values and return an error like the
JSON converter. Specifically, add unit tests that convert Value::U128(u128::MAX)
and Value::I128(i128::MAX) (and the negative extreme for I128) using try_into()
and assert that conversion fails (Err) or panics as your API dictates;
alternatively, modify the CBOR conversion logic (the TryFrom/try_into
implementation that maps Value::U128/Value::I128 to CborValue::Integer) to check
value > u64::MAX or value < i64::MIN/i64::MAX and return a suitable error
instead of doing an unchecked cast, then update existing tests
(u128_narrowed_to_u64_in_cbor and i128_narrowed_to_i64_in_cbor) to still cover
in-range cases.

In `@packages/rs-platform-value/src/converter/serde_json.rs`:
- Around line 1117-1122: The test currently expects Value::Float(f64::NAN) to
become 0, but the validating conversion should reject non-finite floats instead;
update the Float handling in try_into_validating_json() so it checks
f.is_finite() and returns an Err (propagate a suitable validation error) rather
than coercing to 0, and likewise fix the other conversion paths in this file
where non-finite floats are coerced (the three Float conversion branches) to
either return errors or be explicitly lossy only in the lossy conversion; remove
the test validating_json_float_nan_becomes_zero or update it to assert an error
from try_into_validating_json().

In `@packages/rs-platform-value/src/patch/mod.rs`:
- Around line 765-767: Add a regression test to cover map rollback for `add`
failures instead of skipping it: implement a new #[test] named
`apply_patches_rollback_add_map_on_failure` (analogous to
`apply_patches_rollback_add_array_on_failure`) that creates a map doc (e.g.,
platform_value!({"a": 1})), clones the original, constructs a Patch of two ops —
an `add` to "/a" with a different value followed by a `test` that will fail —
then assert that `patch(&mut doc, &p)` returns an error and that `doc ==
original`, ensuring map state is restored on failure.

---

Nitpick comments:
In
`@packages/rs-platform-value/src/btreemap_extensions/btreemap_field_replacement.rs`:
- Around line 684-692: The test function replace_at_path_empty_path_error has a
misleading name because it asserts Ok(()); rename the function to reflect
successful behavior (e.g., replace_at_path_empty_path_ok or
replace_at_path_empty_path_returns_ok) so the name matches the assertion; locate
the test function replace_at_path_empty_path_error and update its identifier
accordingly, keeping the body and assertion unchanged.

In `@packages/rs-platform-value/src/converter/ciborium.rs`:
- Around line 530-535: The test to_cbor_buffer_roundtrip currently only asserts
the buffer is non-empty; change it to perform a real round-trip by decoding the
buffer back into a Value and asserting equality with the original Value;
specifically call the corresponding deserializer (e.g., Value::from_cbor_buffer
or Value::from_cbor_bytes) on the buf produced by Value::to_cbor_buffer(),
unwrap the result, and use assert_eq!(decoded, val) so the test verifies correct
serialization/deserialization for the Value type.

In `@packages/rs-platform-value/src/value_map.rs`:
- Around line 523-605: Replace the explicit panic! call in the test
sort_by_keys_and_inner_maps_sorts_recursively with a shorter assertion helper
like unreachable!() (or panic! with a shorter message) to simplify the panic
message; locate the branch that currently does panic!("expected inner map")
inside that test and change it to unreachable!() so the failure is clearer and
more idiomatic.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8fcb46e7-1a03-4fff-82b0-dc8403292c2b

📥 Commits

Reviewing files that changed from the base of the PR and between 7011b62 and 310c15c.

📒 Files selected for processing (5)
  • packages/rs-platform-value/src/btreemap_extensions/btreemap_field_replacement.rs
  • packages/rs-platform-value/src/converter/ciborium.rs
  • packages/rs-platform-value/src/converter/serde_json.rs
  • packages/rs-platform-value/src/patch/mod.rs
  • packages/rs-platform-value/src/value_map.rs

Comment thread packages/rs-platform-value/src/converter/ciborium.rs
Comment thread packages/rs-platform-value/src/converter/serde_json.rs
Comment thread packages/rs-platform-value/src/patch/mod.rs Outdated
QuantumExplorer and others added 4 commits April 3, 2026 20:45
Adds a test for map-based add rollback that documents the current
behavior — rollback after adding a new map key doesn't fully restore
the original due to ValueMap's append-only insert.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Fixes cargo-machete CI failure.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Collaborator

@thepastaclaw thepastaclaw left a comment

Choose a reason for hiding this comment

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

Code Review

Excellent test coverage PR adding 219 tests across platform-value modules. Agent findings about 'misleading round_trip names' and 'tests documenting bugs' were verified against the code and found to be intentional: the tests explicitly document known conversion behaviors (lossy 128-bit integers in CBOR, NaN normalization in JSON) with clear comments explaining why. The rollback tests correctly capture the current partial-rollback semantics. No actionable issues found — the tests are well-structured, clearly named within their module context, and provide genuine coverage improvement.

Reviewed commit: 40bfc2f

@QuantumExplorer QuantumExplorer merged commit 74ac0ed into v3.1-dev Apr 3, 2026
15 checks passed
@QuantumExplorer QuantumExplorer deleted the test/platform-value-coverage branch April 3, 2026 19:16
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