Skip to content

test(visualize): add 39 tests covering full public API surface#433

Closed
thepastaclaw wants to merge 1 commit into
dashpay:developfrom
thepastaclaw:test/coverage-tracker-364
Closed

test(visualize): add 39 tests covering full public API surface#433
thepastaclaw wants to merge 1 commit into
dashpay:developfrom
thepastaclaw:test/coverage-tracker-364

Conversation

@thepastaclaw
Copy link
Copy Markdown
Contributor

@thepastaclaw thepastaclaw commented Mar 1, 2026

Summary

Adds 39 tests to the grovedb-visualize crate, which previously had zero tests (61.70% coverage came entirely from downstream usage).

Part of the GroveDB code coverage improvement initiative (tracker #364).

Tests Added (39 total)

Area Count Coverage
to_hex 7 empty, single byte, short/medium (no truncation), long (truncation), boundary at 7 bytes (not truncated) and 8 bytes (truncated)
Drawer 7 write with no indent, indent level 1/2, down/up round-trip, flush, no-newline at level, multiple newlines
Visualize for [u8] 6 valid short UTF-8, long UTF-8 truncation, invalid UTF-8, empty, exactly STR_LEN boundary, STR_LEN+1
Visualize for Vec<u8> 1 delegation to slice
Visualize for &T 1 delegation through reference
Visualize for Option<T> 2 Some and None paths
DebugBytes 3 valid UTF-8, invalid UTF-8, empty
DebugByteVectors 3 multiple elements, empty, single element
Derived traits 4 Ord/Eq/Hash for DebugBytes and DebugByteVectors
Helper functions 3 visualize_to_vec, visualize_stderr, visualize_stdout
Integration 2 nested Drawer levels with Visualize, bytes with Drawer indent

Validation

  • cargo test -p grovedb-visualize → 39 passed, 0 failed
  • cargo clippy -p grovedb-visualize --tests → clean
  • cargo fmt -p grovedb-visualize -- --check → clean

Summary by CodeRabbit

  • Tests
    • Added comprehensive test suite covering hex conversion functions, drawer behavior with indentation and navigation, visualization for byte arrays and vectors, and debug wrapper implementations.
    • Extended coverage includes edge cases: truncation behavior, UTF-8 validation, invalid sequences, and nested drawer integration scenarios.

…rate

Add 39 tests covering all public API surface:
- to_hex: empty, short, medium, long (truncation), boundary cases
- Drawer: write at various indent levels, down/up, flush, multiline handling
- Visualize for [u8]: valid/invalid UTF-8, truncation at STR_LEN boundary
- Visualize for Vec<u8>, &T, Option<T> (Some and None)
- DebugBytes and DebugByteVectors: Debug formatting, Ord, Eq, Hash
- visualize_to_vec, visualize_stderr, visualize_stdout
- Integration tests combining Drawer indentation with Visualize trait

The crate previously had 0 tests (61.70% coverage from downstream usage).
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 1, 2026

📝 Walkthrough

Walkthrough

A comprehensive test suite was added to visualize/src/lib.rs, covering the to_hex function, Drawer functionality, visualization implementations for various types, DebugBytes and DebugByteVectors debug wrappers, and integration tests for end-to-end output validation.

Changes

Cohort / File(s) Summary
Test Suite Additions
visualize/src/lib.rs
Added 402 lines of comprehensive tests covering to_hex function behavior, Drawer navigation and flushing, Visualize trait implementations for slices, vectors, references and options, DebugBytes/DebugByteVectors formatting and derived traits, and integration tests for stdout/stderr visualization with truncation and nesting scenarios.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 Hop, hop, tests galore!
Coverage that we all adore,
From hex to drawer flows so bright,
Assertions put the code to flight!

🚥 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 describes the main change: adding 39 tests to cover the public API surface of the visualize crate, which is the primary objective of this PR.
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
  • Post copyable unit tests in a comment

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
Contributor Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 1, 2026

✅ 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.

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: 1

🧹 Nitpick comments (2)
visualize/src/lib.rs (2)

305-316: This test codifies newline stripping at indentation level 0.

drawer_write behaving like a write proxy should generally preserve \n at level 0; asserting "line1line2" bakes in a surprising behavior and makes later correction harder.

Suggested assertion if preserving newlines is the intended contract
-    // At level 0, newlines are replaced with empty separator
-    assert_eq!(output, "line1line2");
+    // At level 0, newlines should be preserved
+    assert_eq!(output, "line1\nline2");
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@visualize/src/lib.rs` around lines 305 - 316, The test
drawer_down_up_returns_to_zero asserts that newlines are stripped at indentation
level 0, but as a write proxy Drawer::write should preserve '\n' when
indentation level is zero; update the test for Drawer (the
drawer_down_up_returns_to_zero function) to expect retained newlines (e.g.
"line1\nline2") after calling drawer.write(...) instead of "line1line2" so the
behavior matches a no-op at level 0 and doesn't lock in the surprising
newline-stripping behavior.

241-249: to_hex truncation assertion is too permissive.

starts_with + ends_with("0c") can pass with malformed middle/tail. This case is deterministic; assert the exact output.

Stronger assertion
 let result = to_hex(&bytes);
-assert!(result.starts_with("01020304.."));
-assert!(result.ends_with("0c"));
+assert_eq!(result, "01020304..090a0b0c");
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@visualize/src/lib.rs` around lines 241 - 249, The test
to_hex_long_bytes_truncated uses starts_with/ends_with which is too permissive;
update the test to assert the exact deterministic output from to_hex for the
given 12-byte input (replace the loose assertions in to_hex_long_bytes_truncated
with a single equality assertion comparing result to the expected string
"01020304..090a0b0c" so the middle/trailing content is checked exactly).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@visualize/src/lib.rs`:
- Around line 405-413: The test visualize_bytes_str_len_plus_one currently uses
a 33-byte input which locks in an off-by-one inclusive-slice behavior; update
the test to use exactly STR_LEN bytes (32) so it asserts the intended
non-truncation behavior, i.e., change the test input to a 32-byte string and
keep the assertion that output contains the full string produced by
visualize_to_vec; alternatively, if the intended contract is that STR_LEN+1
should be truncated, update the assertion to check that output contains only the
STR_LEN-length prefix plus the truncation marker used by the visualization code
instead of the full 33-char string.

---

Nitpick comments:
In `@visualize/src/lib.rs`:
- Around line 305-316: The test drawer_down_up_returns_to_zero asserts that
newlines are stripped at indentation level 0, but as a write proxy Drawer::write
should preserve '\n' when indentation level is zero; update the test for Drawer
(the drawer_down_up_returns_to_zero function) to expect retained newlines (e.g.
"line1\nline2") after calling drawer.write(...) instead of "line1line2" so the
behavior matches a no-op at level 0 and doesn't lock in the surprising
newline-stripping behavior.
- Around line 241-249: The test to_hex_long_bytes_truncated uses
starts_with/ends_with which is too permissive; update the test to assert the
exact deterministic output from to_hex for the given 12-byte input (replace the
loose assertions in to_hex_long_bytes_truncated with a single equality assertion
comparing result to the expected string "01020304..090a0b0c" so the
middle/trailing content is checked exactly).

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4247bb5 and 141f96b.

📒 Files selected for processing (1)
  • visualize/src/lib.rs

Comment thread visualize/src/lib.rs
Comment on lines +405 to +413
fn visualize_bytes_str_len_plus_one() {
let data = b"abcdefghijklmnopqrstuvwxyz1234567"; // 33 bytes
assert_eq!(data.len(), 33);
let mut buf = Vec::new();
visualize_to_vec(&mut buf, data.as_slice());
let output = String::from_utf8(buf).unwrap();
// [..=STR_LEN] is inclusive, so 33 chars from a 33-char string = full
assert!(output.contains("str: abcdefghijklmnopqrstuvwxyz1234567"));
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

STR_LEN + 1 test is locking in an off-by-one boundary behavior.

This test currently expects no truncation for 33 chars even though STR_LEN is 32. It cements the inclusive-slice quirk instead of the intended boundary contract.

Suggested test expectation update
 fn visualize_bytes_str_len_plus_one() {
     let data = b"abcdefghijklmnopqrstuvwxyz1234567"; // 33 bytes
     assert_eq!(data.len(), 33);
     let mut buf = Vec::new();
     visualize_to_vec(&mut buf, data.as_slice());
     let output = String::from_utf8(buf).unwrap();
-    // [..=STR_LEN] is inclusive, so 33 chars from a 33-char string = full
-    assert!(output.contains("str: abcdefghijklmnopqrstuvwxyz1234567"));
+    // > STR_LEN should be truncated to STR_LEN chars
+    assert!(output.contains("str: abcdefghijklmnopqrstuvwxyz123456"));
+    assert!(!output.contains("str: abcdefghijklmnopqrstuvwxyz1234567"));
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
fn visualize_bytes_str_len_plus_one() {
let data = b"abcdefghijklmnopqrstuvwxyz1234567"; // 33 bytes
assert_eq!(data.len(), 33);
let mut buf = Vec::new();
visualize_to_vec(&mut buf, data.as_slice());
let output = String::from_utf8(buf).unwrap();
// [..=STR_LEN] is inclusive, so 33 chars from a 33-char string = full
assert!(output.contains("str: abcdefghijklmnopqrstuvwxyz1234567"));
}
fn visualize_bytes_str_len_plus_one() {
let data = b"abcdefghijklmnopqrstuvwxyz1234567"; // 33 bytes
assert_eq!(data.len(), 33);
let mut buf = Vec::new();
visualize_to_vec(&mut buf, data.as_slice());
let output = String::from_utf8(buf).unwrap();
// > STR_LEN should be truncated to STR_LEN chars
assert!(output.contains("str: abcdefghijklmnopqrstuvwxyz123456"));
assert!(!output.contains("str: abcdefghijklmnopqrstuvwxyz1234567"));
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@visualize/src/lib.rs` around lines 405 - 413, The test
visualize_bytes_str_len_plus_one currently uses a 33-byte input which locks in
an off-by-one inclusive-slice behavior; update the test to use exactly STR_LEN
bytes (32) so it asserts the intended non-truncation behavior, i.e., change the
test input to a 32-byte string and keep the assertion that output contains the
full string produced by visualize_to_vec; alternatively, if the intended
contract is that STR_LEN+1 should be truncated, update the assertion to check
that output contains only the STR_LEN-length prefix plus the truncation marker
used by the visualization code instead of the full 33-char string.

@thepastaclaw
Copy link
Copy Markdown
Contributor Author

Closing duplicate — superseded by #435

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