Skip to content

test: improve Rust test coverage to ~90%#32

Merged
iomz merged 3 commits intodevfrom
test/improve-rust-test-coverage
Nov 20, 2025
Merged

test: improve Rust test coverage to ~90%#32
iomz merged 3 commits intodevfrom
test/improve-rust-test-coverage

Conversation

@iomz
Copy link
Owner

@iomz iomz commented Nov 20, 2025

Add 21 additional tests to improve coverage from 17 to 38 tests:

  • Add tests for delete_image (success and error cases)
  • Add tests for load_hito_config (nonexistent, with file, custom filename, invalid JSON)
  • Add tests for save_hito_config (default and custom filename)
  • Add edge case tests for sort_images (unknown option, None values)
  • Add edge case tests for list_images (empty dir, files without extensions)
  • Add edge case tests for load_image (directory error)
  • Add filter edge case tests (empty patterns, invalid values)
  • Improve path handling test coverage

Coverage results:

  • Regions: 89.65% (2000 total, 207 missed)
  • Functions: 79.63% (108 total, 22 missed)
  • Lines: 89.53% (1356 total, 142 missed)

Remaining uncovered code is primarily Tauri integration functions requiring AppHandle, which is appropriate to test via integration tests.

Summary by CodeRabbit

  • Tests
    • Expanded test suite with comprehensive coverage for file management and configuration functionality, including edge cases and error handling scenarios.

✏️ Tip: You can customize this high-level summary in your review settings.

Add 21 additional tests to improve coverage from 17 to 38 tests:
- Add tests for delete_image (success and error cases)
- Add tests for load_hito_config (nonexistent, with file, custom filename, invalid JSON)
- Add tests for save_hito_config (default and custom filename)
- Add edge case tests for sort_images (unknown option, None values)
- Add edge case tests for list_images (empty dir, files without extensions)
- Add edge case tests for load_image (directory error)
- Add filter edge case tests (empty patterns, invalid values)
- Improve path handling test coverage

Coverage results:
- Regions: 89.65% (2000 total, 207 missed)
- Functions: 79.63% (108 total, 22 missed)
- Lines: 89.53% (1356 total, 142 missed)

Remaining uncovered code is primarily Tauri integration functions
requiring AppHandle, which is appropriate to test via integration tests.
@iomz iomz self-assigned this Nov 20, 2025
@iomz iomz added the enhancement New feature or request label Nov 20, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 20, 2025

Note

Reviews paused

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Walkthrough

The get_parent_directory function signature was updated to accept PathBuf instead of String, with corresponding adjustments to its documentation and test suite. Tests were updated to pass PathBuf arguments, and new tests were added for delete_image, load_hito_config, save_hito_config, and various sort and list behaviors including error handling scenarios.

Changes

Cohort / File(s) Change Summary
Function Signature Update & Test Expansion
src-tauri/src/lib.rs
Updated get_parent_directory to accept PathBuf instead of String; UTF-8 conversion handling deferred to after parent derivation; existing tests refactored to use PathBuf arguments; new tests added for delete_image, load_hito_config, save_hito_config, and sort/list behaviors; doc example updated to reflect PathBuf usage

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • Function signature change is straightforward with consistent control flow
  • Test updates follow a repetitive pattern across multiple test cases
  • Review should focus on UTF-8 conversion handling logic and edge cases in new tests (Windows-specific and root-path scenarios)

Possibly related PRs

Poem

🐰 A PathBuf hops where Strings once tread,
UTF-8 wisdom in parent paths spread,
Tests multiply like carrots in spring,
Each edge case caught—oh what joy we bring! 🥕

Pre-merge checks and finishing touches

✅ 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 reflects the main objective of the pull request: adding tests to improve coverage from ~17 to ~38 tests, achieving ~90% code coverage as stated in the objectives.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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.

@codecov
Copy link

codecov bot commented Nov 20, 2025

Codecov Report

❌ Patch coverage is 99.11504% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.40%. Comparing base (18c0ae7) to head (d5cd373).
⚠️ Report is 3 commits behind head on dev.

Files with missing lines Patch % Lines
src-tauri/src/lib.rs 99.11% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev      #32      +/-   ##
==========================================
+ Coverage   91.76%   94.40%   +2.64%     
==========================================
  Files          19       19              
  Lines        2708     3041     +333     
  Branches      534      534              
==========================================
+ Hits         2485     2871     +386     
+ Misses        223      170      -53     
Flag Coverage Δ
rust 94.40% <99.11%> (+2.64%) ⬆️
unittests 94.40% <99.11%> (+2.64%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

Copy link
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: 0

🧹 Nitpick comments (2)
src-tauri/src/lib.rs (2)

1518-1554: delete_image tests cover main paths; watch for environment‑specific behavior

The three new tests for delete_image (happy path, nonexistent path, and directory input) nicely pin down the function’s contract and its error messages. The success test also correctly asserts that the original path no longer exists after deletion, which matches the intended semantics of “send to trash”.

Just be aware these tests are delegating to the underlying deletion mechanism and filesystem; if you ever see sporadic failures on unusual CI environments or platforms, you may want to gate the happy‑path test with a platform/config flag rather than weakening the assertions.


1673-1957: Extensive sort/filter/list/load‑image edge‑case tests look consistent with implementation

The big block of new tests around sort_images, list_images, and load_image does a good job of pinning down edge behavior:

  • Unknown sort option leaves the list as‑is.
  • Files without extensions, empty directories, and directories passed to load_image are handled as expected.
  • Filters correctly no‑op when given empty patterns or size values and behave sensibly for malformed “between” ranges.
  • Sorting with None size / created_at values matches the implementation (treated as 0 / sorted last respectively).
  • Combined filter tests (category + size) validate the interaction between filters and the category map.

Overall, these tests closely mirror the current logic and will be very helpful if you later tweak the filter/sort semantics. I don’t see any correctness issues here.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 18c0ae7 and d5cf3a6.

📒 Files selected for processing (1)
  • src-tauri/src/lib.rs (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src-tauri/src/lib.rs (1)
src/types.ts (2)
  • CategoryAssignment (43-46)
  • ImagePath (5-9)
🔇 Additional comments (2)
src-tauri/src/lib.rs (2)

52-65: PathBuf-based get_parent_directory + UTF‑8 tests look solid; double‑check bare filename semantics

The switch to PathBuf in get_parent_directory and the updated doc/example plus new UTF‑8 coverage tests (test_get_parent_directory_invalid_utf8_path / valid_utf8_path) are all consistent and more idiomatic for a Tauri command.

One thing to verify: in test_get_parent_directory, the "file.txt" case currently asserts is_ok(), but with the current implementation you’re relying directly on PathBuf::parent(). On some platforms, Path::new("file.txt").parent() yields None, which would cause this call to return "File has no parent directory". Please confirm that the expectation for a bare filename is intentionally Ok (e.g., you conceptually treat it as being in the current directory) and, if so, consider normalizing that case in the function or adjusting the test to match the actual PathBuf::parent behavior.

Also applies to: 765-787, 1960-1984


1557-1671: Good coverage for .hito config load/save, including filename overrides and invalid JSON

The new load_hito_config/save_hito_config tests exercise all the important branches:

  • No config file present returns an empty image_categories vec.
  • Default .hito.json vs custom filenames.
  • Round‑trip save then deserialize.
  • Invalid JSON returning an error that contains "Failed to parse".

This matches the implementation’s behavior and should make future refactors of the config path logic or serialization relatively safe. No issues from my side here.

@iomz
Copy link
Owner Author

iomz commented Nov 20, 2025

@coderabbitai pause

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 20, 2025

✅ Actions performed

Reviews paused.

iomz added 2 commits November 20, 2025 20:44
- Fix doctests by marking Tauri commands as no_run or removing executable examples
- Rename lib from tauri_app_lib to hito_lib in Cargo.toml and all references
- Improve codecov workflow with Cargo cache and better doctest error handling
The --doc flag for cargo llvm-cov requires nightly toolchain.
Update the command to use cargo +nightly llvm-cov --doc.
@iomz iomz merged commit b248075 into dev Nov 20, 2025
4 checks passed
@iomz iomz deleted the test/improve-rust-test-coverage branch November 20, 2025 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant