Avoid reusing stale CSP test fixtures

Retry an unused test directory on AlreadyExists without deleting or reading any pre-existing fixture contents.

AI assistance: Codex, under maintainer direction.
This commit is contained in:
Paul Bakaus
2026-09-07 13:40:01 -07:00
parent 50be8bb35a
commit 4a80d18059
+12 -6
View File
@@ -214,12 +214,18 @@ mod tests {
impl Fixture {
fn new() -> Self {
let root = std::env::temp_dir().join(format!(
"impeccable-csp-761-{}-{}",
std::process::id(), NEXT_FIXTURE.fetch_add(1, Ordering::Relaxed),
));
std::fs::create_dir(&root).unwrap();
Self(root)
loop {
let root = std::env::temp_dir().join(format!(
"impeccable-csp-761-{}-{}",
std::process::id(), NEXT_FIXTURE.fetch_add(1, Ordering::Relaxed),
));
match std::fs::create_dir(&root) {
Ok(()) => return Self(root),
// Never reuse or remove files left by another run.
Err(e) if e.kind() == std::io::ErrorKind::AlreadyExists => continue,
Err(e) => panic!("create CSP fixture: {e}"),
}
}
}
fn scan(&self, path: &str, body: &str) -> Value {