From c437471b025ff876cbb9035e06fbb57adc4f9af2 Mon Sep 17 00:00:00 2001 From: Nic-dorman Date: Thu, 20 Aug 2026 16:17:05 +0100 Subject: [PATCH] fix(tests): make unwritable-path tests actually unwritable on Windows (V2-1043) Two adaptive.rs tests built their "impossible" path under the Unix root ("/nonexistent_.../..."), assuming create_dir_all must fail there. On Windows that resolves to a creatable directory under C:\, so: - save_snapshot_to_unwritable_dir_does_not_panic failed on every Windows box (the snapshot was written and the !exists assert tripped), and - save_with_timeout_returns_promptly_on_fast_failure silently stopped testing the fast-fail path (mkdir succeeded, so it timed a successful write instead), and both littered directories at the drive root. Route the path through a tempfile::NamedTempFile instead: a parent component is an existing regular file, so create_dir_all fails on every platform and nothing is left behind. ant-core lib suite is now fully green on Windows (452/452). Co-Authored-By: Claude Fable 5 --- ant-core/src/data/client/adaptive.rs | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/ant-core/src/data/client/adaptive.rs b/ant-core/src/data/client/adaptive.rs index cc4e515..20356d5 100644 --- a/ant-core/src/data/client/adaptive.rs +++ b/ant-core/src/data/client/adaptive.rs @@ -2805,10 +2805,13 @@ mod tests { /// quiet no-op: best-effort, no panic, no error propagation. #[test] fn save_snapshot_to_unwritable_dir_does_not_panic() { - // A path under a non-existent absolute root that the process - // also cannot create. On macOS/Linux a write under "/" requires - // root; create_dir_all will fail on this path. - let path = PathBuf::from("/nonexistent_root_dir_xyz_for_test/sub/dir/client_adaptive.json"); + // A path routed through an existing regular file: create_dir_all + // fails on every platform because a parent component is a file. + // (A path under "/" is NOT impossible everywhere — on Windows it + // resolves to a creatable C:\ directory and littered the drive + // root — V2-1043.) + let blocker = tempfile::NamedTempFile::new().unwrap(); + let path = blocker.path().join("sub").join("client_adaptive.json"); let snap = ChannelStart { quote: 1, store: 1, @@ -4196,14 +4199,16 @@ mod tests { /// Round-5 follow-up: `save_snapshot_with_timeout` returns /// promptly even when the underlying write would otherwise hang. - /// Use a path under a non-existent root that mkdir cannot create - /// to simulate a slow/failing filesystem (mkdir returns Err - /// quickly so this isn't a real hang test, but it confirms the - /// timeout wrapper does not block longer than the deadline on a - /// fast-failing operation either). + /// Use a path mkdir cannot create — routed through an existing + /// regular file, which fails on every platform (a Unix-root path + /// is creatable on Windows — V2-1043) — to simulate a slow/failing + /// filesystem (mkdir returns Err quickly so this isn't a real hang + /// test, but it confirms the timeout wrapper does not block longer + /// than the deadline on a fast-failing operation either). #[test] fn save_with_timeout_returns_promptly_on_fast_failure() { - let path = std::path::PathBuf::from("/nonexistent_root_xyz_test/snap.json"); + let blocker = tempfile::NamedTempFile::new().unwrap(); + let path = blocker.path().join("snap.json"); let snap = ChannelStart { quote: 1, store: 1,