From b84ab4507aa2fc5ace1dd0c4a8848441bc8226fc Mon Sep 17 00:00:00 2001 From: cyfung1031 <44498510+cyfung1031@users.noreply.github.com> Date: Mon, 12 Oct 2026 14:29:56 +0900 Subject: [PATCH] M13: isolate automation workdirs by call site (#1223) --- crates/automation/tests/automation.rs | 31 ++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/crates/automation/tests/automation.rs b/crates/automation/tests/automation.rs index 30765cc0..5f76908a 100644 --- a/crates/automation/tests/automation.rs +++ b/crates/automation/tests/automation.rs @@ -36,8 +36,10 @@ fn fixture(n: usize) -> Vec { } /// A fresh directory with `a.pdf` (3 pages) and `b.pdf` (2 pages). +#[track_caller] fn workdir(test: &str) -> PathBuf { - let dir = std::env::temp_dir().join(format!("pdfcraft-automation-{test}-{}", std::process::id())); + let caller = std::panic::Location::caller(); + let dir = std::env::temp_dir().join(format!("pdfcraft-automation-{test}-{}-{}-{}", std::process::id(), caller.line(), caller.column(),)); let _ = std::fs::remove_dir_all(&dir); std::fs::create_dir_all(&dir).unwrap(); std::fs::write(dir.join("a.pdf"), fixture(3)).unwrap(); @@ -45,6 +47,33 @@ fn workdir(test: &str) -> PathBuf { dir } +#[test] +fn workdir_call_sites_do_not_delete_each_other() { + let first = workdir("same-tag"); + let sentinel = first.join("sentinel"); + std::fs::write(&sentinel, b"first call site").unwrap(); + + let second = workdir("same-tag"); + let paths_differ = first != second; + let sentinel_bytes = std::fs::read(&sentinel).ok(); + let first_a = std::fs::read(first.join("a.pdf")).ok(); + let first_b = std::fs::read(first.join("b.pdf")).ok(); + let second_a = std::fs::read(second.join("a.pdf")).ok(); + let second_b = std::fs::read(second.join("b.pdf")).ok(); + + let _ = std::fs::remove_dir_all(&first); + if paths_differ { + let _ = std::fs::remove_dir_all(&second); + } + + assert!(paths_differ, "distinct call sites shared {first:?}"); + assert_eq!(sentinel_bytes.as_deref(), Some(&b"first call site"[..])); + assert_eq!(first_a, Some(fixture(3))); + assert_eq!(first_b, Some(fixture(2))); + assert_eq!(second_a, Some(fixture(3))); + assert_eq!(second_b, Some(fixture(2))); +} + fn auto(dir: &Path) -> Automation { Automation::new().with_root(dir).unwrap().with_clock(|| 1_700_000_000) }