Skip to content

Commit a3ebc75

Browse files
committed
test(blob_fetcher): cover fetch_blobs_by_hash skip-existing branch
Pre-stage a blob and verify fetch_blobs_by_hash short-circuits the network call, reporting skipped:1. Assisted-by: Claude Code:claude-opus-4-7
1 parent 8e3d042 commit a3ebc75

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

crates/socket-patch-core/tests/blob_fetcher_edges_e2e.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,29 @@ async fn fetch_blobs_by_hash_empty_set_short_circuits() {
5858
assert!(result.results.is_empty());
5959
}
6060

61+
/// `fetch_blobs_by_hash` with a hash whose blob is already on disk
62+
/// short-circuits the network call and reports `skipped: 1`. Covers
63+
/// the `skip if already on disk` branch (~L200-220).
64+
#[tokio::test]
65+
async fn fetch_blobs_by_hash_skips_existing_blobs() {
66+
use std::collections::HashSet;
67+
let tmp = tempfile::tempdir().unwrap();
68+
let blobs = tmp.path().join("blobs");
69+
std::fs::create_dir(&blobs).unwrap();
70+
let hash = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef";
71+
std::fs::write(blobs.join(hash), b"already here").unwrap();
72+
let mut hashes = HashSet::new();
73+
hashes.insert(hash.to_string());
74+
75+
let client = dummy_client();
76+
let result = fetch_blobs_by_hash(&hashes, &blobs, &client, None).await;
77+
assert_eq!(result.total, 1, "one hash requested");
78+
assert_eq!(result.downloaded, 0, "already-on-disk needs no download");
79+
assert_eq!(result.skipped, 1, "exactly one skipped");
80+
assert_eq!(result.failed, 0);
81+
assert!(result.results.iter().any(|r| r.success && r.hash == hash));
82+
}
83+
6184
/// `get_missing_blobs` against a manifest that lists no patches
6285
/// returns the empty set. Covers the early-return inside the
6386
/// function — the existing apply tests always stage at least one

0 commit comments

Comments
 (0)