From b603e3799ee9836a10a81178ba8eaaa5ba20b14d Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 9 Oct 2026 07:02:10 +0000 Subject: [PATCH] Fix Windows flake in read-set replacement test a_read_set_notices_a_changed_file evicted PR #1215 from the merge queue (merge_group run 37892957346, test (windows-latest, 1)) with "a replacement": the read set missed a same-bytes rename-over. On Windows a file's identity stat is only its creation time (no inode), and the replaced file was written moments earlier, so when the old write and the replacement land in the same file-time tick every stat matches, and the racy content check passes because the bytes are identical. Whether the assertion holds depends on timing. Backdate the file before recording so the replacement must be told apart by stats alone, which a fresh mtime always does. Simulating Windows identity and ~15.6 ms stamps on Linux, the old test failed 136/200 runs with the CI panic; the new one fails 0/200. Co-Authored-By: Claude Opus 5.5 (1M context) --- .../src/vendor/lock_inventory/view.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/crates/socket-patch-core/src/vendor/lock_inventory/view.rs b/crates/socket-patch-core/src/vendor/lock_inventory/view.rs index 5d150ebdb..b59f2eb8b 100644 --- a/crates/socket-patch-core/src/vendor/lock_inventory/view.rs +++ b/crates/socket-patch-core/src/vendor/lock_inventory/view.rs @@ -1175,8 +1175,20 @@ mod tests { // Rewritten in place with the same length. std::fs::write(root.join("a.lock"), "two").unwrap(); assert!(!set.unchanged(), "an in-place rewrite"); - // Replaced (rename over) with the same bytes. + // Replaced (rename over) with the same bytes. Backdate the file + // first so its stats alone must vouch for it: on Windows a file's + // identity is only its creation time, so a replacement stamped in + // the same timestamp tick as the write it replaces would keep every + // stat (and the same bytes pass the racy content check). + std::fs::File::options() + .write(true) + .open(root.join("a.lock")) + .unwrap() + .set_modified(std::time::SystemTime::now() - std::time::Duration::from_secs(3600)) + .unwrap(); let set = recorded(root, read).await.unwrap(); + assert!(set.racy.is_empty(), "backdated"); + assert!(set.unchanged()); std::fs::write(root.join("a.tmp"), "two").unwrap(); std::fs::rename(root.join("a.tmp"), root.join("a.lock")).unwrap(); assert!(!set.unchanged(), "a replacement");