Skip to content

Commit b026f43

Browse files
committed
Add unit tests from cargo-mutants in write_operations/copy_strategy
is_apfs and is_same_apfs_volume were only covered indirectly through copy_file_with_strategy. cargo-mutants showed survivors for both: - is_apfs → true / false struct-level returns - is_apfs == "apfs" → != mutant - is_same_apfs_volume → true / false, and the != → == on the st_dev comparison - The match-guard p.exists() → true/false on dest parent Five new tests on macOS pin the behavior directly: - is_apfs_returns_true_for_typical_macos_paths: positive case via tmpdir - is_apfs_returns_false_for_nonexistent_path: statfs early-return path - is_same_apfs_volume_true_for_same_apfs_dir_pair: src exists + dest doesn't, parent fallback kicks in, st_dev matches - is_same_apfs_volume_false_when_source_missing: source-stat fail path - is_same_apfs_volume_false_when_dest_parent_missing: nonexistent parent path — kills the match-guard true mutant Five tests, ~0.04s combined.
1 parent 4f04d03 commit b026f43

1 file changed

Lines changed: 73 additions & 0 deletions

File tree

apps/desktop/src-tauri/src/file_system/write_operations/copy_strategy.rs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,79 @@ mod tests {
249249
cleanup_temp_dir(&temp_dir);
250250
}
251251

252+
// ----------------------------------------------------------------------
253+
// is_apfs / is_same_apfs_volume — mutation-driven survivors.
254+
//
255+
// Both helpers were previously only covered indirectly via
256+
// copy_file_with_strategy. cargo-mutants showed survivors for
257+
// `is_apfs → true / → false` and the != → == device-id mutant in
258+
// is_same_apfs_volume. These tests pin the behavior directly.
259+
// ----------------------------------------------------------------------
260+
261+
#[cfg(target_os = "macos")]
262+
#[test]
263+
fn is_apfs_returns_true_for_typical_macos_paths() {
264+
// System root and the test's tmp dir are both on APFS in any modern
265+
// macOS dev / CI box. If both came back as not-APFS, the `== "apfs"`
266+
// → `!= "apfs"` mutant would survive.
267+
let temp_dir = create_temp_dir("is-apfs-true");
268+
assert!(
269+
is_apfs(&temp_dir),
270+
"tempfs path on macOS dev box should be APFS — if this fails on a non-APFS bot, gate the test on a precheck"
271+
);
272+
cleanup_temp_dir(&temp_dir);
273+
}
274+
275+
#[cfg(target_os = "macos")]
276+
#[test]
277+
fn is_apfs_returns_false_for_nonexistent_path() {
278+
// Kills: replace is_apfs → true. statfs fails → early return false.
279+
assert!(!is_apfs(Path::new("/nonexistent-volume-xyzzy-12345/file")));
280+
}
281+
282+
#[cfg(target_os = "macos")]
283+
#[test]
284+
fn is_same_apfs_volume_true_for_same_apfs_dir_pair() {
285+
// Source exists, dest doesn't (typical copy precondition): the function
286+
// falls back to checking the dest's parent. Both should resolve to the
287+
// same st_dev on APFS, returning true. Kills the != → == mutant on the
288+
// dev-id comparison.
289+
let temp_dir = create_temp_dir("same-apfs-pair");
290+
let src = temp_dir.join("a.txt");
291+
fs::write(&src, "x").unwrap();
292+
let dst = temp_dir.join("b.txt"); // doesn't exist
293+
assert!(
294+
is_same_apfs_volume(&src, &dst),
295+
"two paths in the same tmp dir should be on the same APFS volume"
296+
);
297+
cleanup_temp_dir(&temp_dir);
298+
}
299+
300+
#[cfg(target_os = "macos")]
301+
#[test]
302+
fn is_same_apfs_volume_false_when_source_missing() {
303+
// Kills: replace is_same_apfs_volume → true.
304+
let temp_dir = create_temp_dir("missing-source");
305+
let src = temp_dir.join("does-not-exist.txt");
306+
let dst = temp_dir.join("dest.txt");
307+
assert!(!is_same_apfs_volume(&src, &dst));
308+
cleanup_temp_dir(&temp_dir);
309+
}
310+
311+
#[cfg(target_os = "macos")]
312+
#[test]
313+
fn is_same_apfs_volume_false_when_dest_parent_missing() {
314+
// Pins the `Some(p) if p.exists() → false` fallback. If the match
315+
// guard is mutated to `true`, the function would attempt to stat a
316+
// nonexistent parent.
317+
let temp_dir = create_temp_dir("missing-parent");
318+
let src = temp_dir.join("src.txt");
319+
fs::write(&src, "x").unwrap();
320+
let dst = Path::new("/nonexistent-parent-xyzzy/child.txt");
321+
assert!(!is_same_apfs_volume(&src, dst));
322+
cleanup_temp_dir(&temp_dir);
323+
}
324+
252325
#[test]
253326
fn test_copy_file_with_strategy_empty_file() {
254327
let temp_dir = create_temp_dir("empty");

0 commit comments

Comments
 (0)