From 6099995338c69d0861fa745cba8e0cc4ab6537ac Mon Sep 17 00:00:00 2001 From: Paul Bakaus Date: Fri, 4 Sep 2026 10:32:53 -0700 Subject: [PATCH] Tests: make the temp-dir helpers unique under a coarse clock Windows' system clock is coarse enough that two parallel tests could get the same pid-plus-nanoseconds directory name and then remove each other's files (rust-windows: close_verb_round_trip_and_ownership, NotFound). A per-process counter is appended to the name. Co-Authored-By: Claude Code Claude-Session: https://claude.ai/code/session_01Vau2X53xGTjjTCXWMVBoNY --- crates/context/src/critique_storage.rs | 10 ++++++++-- crates/context/src/staleness_deep.rs | 10 ++++++++-- crates/hook/tests/cache_root_tests.rs | 8 ++++++-- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/crates/context/src/critique_storage.rs b/crates/context/src/critique_storage.rs index 95ef0f4ea..7cc88fade 100644 --- a/crates/context/src/critique_storage.rs +++ b/crates/context/src/critique_storage.rs @@ -687,11 +687,17 @@ mod tests_660 { use std::collections::HashMap; use std::path::PathBuf; + static TMP_SEQ: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); + fn tmp() -> String { let base = std::env::temp_dir().join(format!( - "impeccable-critique-{}-{}", + "impeccable-critique-{}-{}-{}", std::process::id(), - std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_nanos() + std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_nanos(), + // A per-process counter: Windows' clock is coarse enough that two + // parallel tests can share a nanosecond stamp and then delete each + // other's directories. + TMP_SEQ.fetch_add(1, std::sync::atomic::Ordering::Relaxed) )); std::fs::create_dir_all(&base).unwrap(); // Like Node's `realpathSync`: no `\\?\` verbatim prefix on Windows, diff --git a/crates/context/src/staleness_deep.rs b/crates/context/src/staleness_deep.rs index 10dfbc772..fb3ea4622 100644 --- a/crates/context/src/staleness_deep.rs +++ b/crates/context/src/staleness_deep.rs @@ -437,11 +437,17 @@ pub fn load_known_rule_ids() -> Option> { mod tests { use super::check_hook_installation; + static TMP_SEQ: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); + fn tmp() -> String { let base = std::env::temp_dir().join(format!( - "impeccable-doctor-hook-{}-{}", + "impeccable-doctor-hook-{}-{}-{}", std::process::id(), - std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_nanos() + std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_nanos(), + // A per-process counter: Windows' clock is coarse enough that two + // parallel tests can share a nanosecond stamp and then delete each + // other's directories. + TMP_SEQ.fetch_add(1, std::sync::atomic::Ordering::Relaxed) )); std::fs::create_dir_all(&base).unwrap(); // Like Node's `realpathSync`: on Windows, `canonicalize` yields a diff --git a/crates/hook/tests/cache_root_tests.rs b/crates/hook/tests/cache_root_tests.rs index eaa8a6ebc..366e0d5bd 100644 --- a/crates/hook/tests/cache_root_tests.rs +++ b/crates/hook/tests/cache_root_tests.rs @@ -47,9 +47,13 @@ struct Tmp(PathBuf); impl Tmp { fn new() -> Tmp { let base = std::env::temp_dir().join(format!( - "impeccable-cache-root-{}-{}", + "impeccable-cache-root-{}-{}-{}", std::process::id(), - std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_nanos() + std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_nanos(), + // A per-process counter: Windows' clock is coarse enough that two + // parallel tests can share a nanosecond stamp and then delete each + // other's directories. + TMP_SEQ.fetch_add(1, std::sync::atomic::Ordering::Relaxed) )); std::fs::create_dir_all(&base).unwrap(); // Like Node's `realpathSync`: no `\\?\` verbatim prefix on Windows, so the