Skip to content

Commit f258eeb

Browse files
Fix oracle selftest temp-path collision flake (#1162)
tests/common/mod.rs is compiled twice into some test binaries (as `common` and again as `vlt_e2e_common::common`), so each oracle_selftests test runs twice in one process. The selftests built their scratch paths from the PID alone, so the two copies shared /tmp/socket-patch-oracle-<pid>-* and deleted or overwrote each other's files. This failed coverage in two merge-group runs today (e2e_vendored_production) and 11 of 300 local runs. Use a fresh tempfile::tempdir() per test instead, which is unique per call and removed on drop. Claude-Session: https://claude.ai/code/session_01X2N3HNQzBaBgd8xyi3nxva Co-authored-by: Claude <noreply@anthropic.com>
1 parent d68931f commit f258eeb

1 file changed

Lines changed: 7 additions & 27 deletions

File tree

  • crates/socket-patch-cli/tests/common

‎crates/socket-patch-cli/tests/common/mod.rs‎

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -575,10 +575,9 @@ mod oracle_selftests {
575575
// back and confirm it equals hashing the same bytes in memory,
576576
// and that distinct contents produce distinct hashes (i.e. it
577577
// isn't returning a constant or hashing the path).
578-
let dir = std::env::temp_dir();
579-
let unique = format!("socket-patch-oracle-{}", std::process::id());
580-
let p1 = dir.join(format!("{unique}-a.bin"));
581-
let p2 = dir.join(format!("{unique}-b.bin"));
578+
let dir = tempfile::tempdir().expect("temp dir");
579+
let p1 = dir.path().join("a.bin");
580+
let p2 = dir.path().join("b.bin");
582581
let content_a = b"alpha-content\n";
583582
let content_b = b"beta-content\n";
584583
std::fs::write(&p1, content_a).expect("write temp a");
@@ -591,21 +590,6 @@ mod oracle_selftests {
591590
git_sha256_file(&p2),
592591
"git_sha256_file must reflect file contents"
593592
);
594-
595-
let _ = std::fs::remove_file(&p1);
596-
let _ = std::fs::remove_file(&p2);
597-
}
598-
599-
// Unique temp dir per (pid, callsite) so the fixture-builder self-tests
600-
// never collide with each other or across parallel test binaries.
601-
fn scratch_dir(tag: &str) -> PathBuf {
602-
let d = std::env::temp_dir().join(format!(
603-
"socket-patch-oracle-{}-{}",
604-
std::process::id(),
605-
tag
606-
));
607-
let _ = std::fs::remove_dir_all(&d);
608-
d
609593
}
610594

611595
#[test]
@@ -616,8 +600,8 @@ mod oracle_selftests {
616600
// the suites would pass while exercising nothing. Pin the exact shape
617601
// apply consumes: `patches.<purl>.{uuid,files.<file>.{beforeHash,
618602
// afterHash}}`, all camelCase.
619-
let root = scratch_dir("manifest");
620-
let socket_dir = root.join(".socket");
603+
let root = tempfile::tempdir().expect("temp dir");
604+
let socket_dir = root.path().join(".socket");
621605
let purl = "pkg:npm/dummy@1.0.0";
622606
let uuid = "11111111-1111-4111-8111-111111111111";
623607
let path = write_minimal_manifest(
@@ -669,8 +653,6 @@ mod oracle_selftests {
669653
!socket_dir.join("blobs").join("afterhash111").exists(),
670654
"write_minimal_manifest must not stage after_hash blobs"
671655
);
672-
673-
let _ = std::fs::remove_dir_all(&root);
674656
}
675657

676658
#[test]
@@ -679,8 +661,8 @@ mod oracle_selftests {
679661
// `<socket_dir>/blobs/<hash>` and verifies their bytes. If write_blob
680662
// wrote the wrong path or mangled the bytes, "offline apply succeeds"
681663
// tests would silently fall back to a network path or fail to match.
682-
let root = scratch_dir("blob");
683-
let socket_dir = root.join(".socket");
664+
let root = tempfile::tempdir().expect("temp dir");
665+
let socket_dir = root.path().join(".socket");
684666
let hash = "deadbeefcafef00d";
685667
let payload = &[0u8, 1, 2, 255, b'p', b'a', b't', b'c', b'h', 0, 42];
686668
write_blob(&socket_dir, hash, payload);
@@ -696,8 +678,6 @@ mod oracle_selftests {
696678
payload,
697679
"write_blob must stage the exact bytes, byte-for-byte"
698680
);
699-
700-
let _ = std::fs::remove_dir_all(&root);
701681
}
702682

703683
#[test]

0 commit comments

Comments
 (0)