xtask: use unique temporary directories for bench tests (#2196)

This commit is contained in:
Dylan M. Taylor
2026-10-23 11:17:15 -04:00
committed by GitHub
parent dd325c7ab8
commit bd3ae8ab14
3 changed files with 7 additions and 14 deletions
Generated
+1
View File
@@ -6628,6 +6628,7 @@ name = "xtask"
version = "0.16.0"
dependencies = [
"serde_json",
"tempfile",
]
[[package]]
+2
View File
@@ -7,3 +7,5 @@ publish = false
[dependencies]
serde_json = { workspace = true }
tempfile = "3"
+4 -14
View File
@@ -1,20 +1,15 @@
//! Regression gates must fail when benchmark evidence is corrupt or incomplete.
use serde_json::{Value, json};
use std::path::PathBuf;
use std::process::{Command, Output};
struct ResultsDir(PathBuf);
struct ResultsDir(tempfile::TempDir);
impl ResultsDir {
fn new() -> Self {
use std::sync::atomic::{AtomicU64, Ordering};
static NEXT: AtomicU64 = AtomicU64::new(0);
let dir = std::env::temp_dir().join(format!("effectcraft-bench-{}-{}", std::process::id(), NEXT.fetch_add(1, Ordering::Relaxed)));
std::fs::create_dir_all(&dir).unwrap();
Self(dir)
Self(tempfile::Builder::new().prefix("effectcraft-bench-").tempdir().unwrap())
}
fn compare(&self, old: &str, new: &str, gate: bool) -> Output {
let baseline = self.0.join("baseline.jsonl");
let candidate = self.0.join("candidate.jsonl");
let baseline = self.0.path().join("baseline.jsonl");
let candidate = self.0.path().join("candidate.jsonl");
std::fs::write(&baseline, old).unwrap();
std::fs::write(&candidate, new).unwrap();
let mut command = Command::new(env!("CARGO_BIN_EXE_xtask"));
@@ -25,11 +20,6 @@ impl ResultsDir {
command.output().unwrap()
}
}
impl Drop for ResultsDir {
fn drop(&mut self) {
let _ = std::fs::remove_dir_all(&self.0);
}
}
fn row(scenario: &str, ok: bool) -> Value {
json!({"scenario": scenario, "run": "full", "ok": ok,