Skip to content

crates/rcache: verify sha256 against bincache index, add tests - #158

Merged
twitchyliquid64 merged 1 commit into
mainfrom
tom/fix
Apr 24, 2026
Merged

twitchyliquid64 merged 1 commit into
mainfrom
tom/fix

Conversation

@twitchyliquid64

@twitchyliquid64 twitchyliquid64 commented Apr 24, 2026 •

Copy link
Copy Markdown
Contributor

Whelp. Looks like a refactor a while ago stopped using FileCache to fetch the artifact tarballs, and FileCache was responsible for checking the sha's.

This change restores sha checking, as well as adds adversarial tests to all the paths where we fetch artifacts that need hash checking.

Lets get this one in sooner rather than later.

Summary by CodeRabbit

  • Improvements

    • Remote cache now validates downloaded data integrity using hash verification
    • Corrupted downloads are automatically removed from the filesystem
    • Validation failures report both expected and computed hash values for diagnostics
  • Tests

    • Added unit tests for hash mismatch detection scenarios

@coderabbitai

coderabbitai Bot commented Apr 24, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The changes add SHA-256 hash verification throughout the caching infrastructure to detect data integrity issues during remote cache materialization and file operations, along with corresponding error variants, a new utility method for Tee, and comprehensive unit tests validating hash mismatch scenarios.

Changes

Cohort / File(s) Summary
Hash Verification Implementation
crates/rcache/src/remote.rs, crates/common/src/file_cache.rs
Adds SHA-256 hash computation and verification during remote cache download and file write operations. Updates Error<BE> enum with new variants including HashMismatch { want, got }, IO, Cache, NotFound, and ArchiveError. Includes unit tests with mocked responses to validate hash mismatch detection and file cleanup.
Build Configuration
crates/rcache/Cargo.toml
Adds sha2 workspace dependency to support hash computation across the crate.
Utility Enhancement
crates/common/src/lib.rs
Introduces public into_inner(self) consuming method on Tee<W1, W2> to deconstruct the wrapper and yield the underlying writer pair (W1, W2).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Through digital streams, a hash we now trace,
Each byte flows and dances in verification's embrace,
When checksums align with a cryptographic cheer,
Our cached treasures are safe, crystal clear! 🥬✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 21.74% 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 accurately reflects the main changes: verifying SHA-256 hashes against the bincache index and adding tests for this functionality.
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 tom/fix

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

@coderabbitai coderabbitai Bot left a comment

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.

🧹 Nitpick comments (1)
crates/rcache/src/remote.rs (1)

344-349: Make mock backend fail on missing fixtures instead of returning empty data.

Defaulting to Vec::new() can mask incorrect URL/key wiring in tests and still produce a hash mismatch for the wrong reason.

Proposed test-hardening diff
         async fn execute(&self, req: MockUrl) -> Result<MockResponse, std::io::Error> {
-            let data = self.responses.get(&req.0).cloned().unwrap_or_default();
+            let data = self.responses.get(&req.0).cloned().ok_or_else(|| {
+                std::io::Error::new(
+                    std::io::ErrorKind::NotFound,
+                    format!("missing mock response for {}", req.0),
+                )
+            })?;
             Ok(MockResponse {
                 data,
                 consumed: false,
             })
         }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/rcache/src/remote.rs` around lines 344 - 349, The mock backend's
execute method currently returns an empty MockResponse when a fixture is
missing, which can hide test wiring bugs; update async fn execute(&self, req:
MockUrl) -> Result<MockResponse, std::io::Error> to check
self.responses.get(&req.0) and if absent return
Err(std::io::Error::new(std::io::ErrorKind::NotFound, format!("no fixture for
{}", req.0))) instead of defaulting to Vec::new(), otherwise construct and
return the MockResponse with the found data and consumed: false; refer to the
execute method, MockUrl, MockResponse and the responses map when making the
change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@crates/rcache/src/remote.rs`:
- Around line 344-349: The mock backend's execute method currently returns an
empty MockResponse when a fixture is missing, which can hide test wiring bugs;
update async fn execute(&self, req: MockUrl) -> Result<MockResponse,
std::io::Error> to check self.responses.get(&req.0) and if absent return
Err(std::io::Error::new(std::io::ErrorKind::NotFound, format!("no fixture for
{}", req.0))) instead of defaulting to Vec::new(), otherwise construct and
return the MockResponse with the found data and consumed: false; refer to the
execute method, MockUrl, MockResponse and the responses map when making the
change.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: ddf7bfad-066b-4924-8468-9044642ad65f

📥 Commits

Reviewing files that changed from the base of the PR and between d5f7a13 and fee0edf.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (4)
  • crates/common/src/file_cache.rs
  • crates/common/src/lib.rs
  • crates/rcache/Cargo.toml
  • crates/rcache/src/remote.rs

@bryan-minimal bryan-minimal left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

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