From cee6677121b789a5a03ac5234cb03a339767f28d Mon Sep 17 00:00:00 2001 From: Miguel Palhas Date: Sat, 22 Aug 2026 21:20:24 +0100 Subject: [PATCH] test(e2e): let cargo report the daemon binary path Replaces the current_exe-derived target layout guess with the compiler-artifact message from the build itself. Co-Authored-By: Claude Fable 5 --- crates/arr-e2e/src/lib.rs | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/crates/arr-e2e/src/lib.rs b/crates/arr-e2e/src/lib.rs index 8416f0c..1f12eff 100644 --- a/crates/arr-e2e/src/lib.rs +++ b/crates/arr-e2e/src/lib.rs @@ -265,14 +265,18 @@ impl Drop for Daemon { /// Build the `arr` binary once per test run and return its path. /// /// `cargo nextest run -p arr-e2e` compiles only this crate's test binaries, -/// so the daemon is built here. Cargo's own file locking serialises this -/// against concurrent test processes, and a warm target directory makes it a -/// no-op. +/// so the daemon is built here, and cargo itself reports where the executable +/// landed — no guessing at the target layout the test runner uses. Cargo's +/// own file locking serialises this against concurrent test processes, and a +/// warm target directory makes it a no-op. fn daemon_binary() -> &'static PathBuf { static BINARY: OnceLock = OnceLock::new(); BINARY.get_or_init(|| { let mut build = Command::new(env!("CARGO")); - build.args(["build", "--quiet", "-p", "arr-daemon", "--bin", "arr"]); + build + .args(["build", "-p", "arr-daemon", "--bin", "arr"]) + .args(["--message-format", "json-render-diagnostics"]) + .stderr(Stdio::inherit()); // The test process carries the per-crate vars cargo set for *this* // crate (CARGO_MANIFEST_DIR, CARGO_PKG_*). Inherited into a nested // cargo they poison its fingerprints, so every shell build and every @@ -285,23 +289,18 @@ fn daemon_binary() -> &'static PathBuf { build.env_remove(key); } } - let status = build.status().expect("run cargo build"); - assert!(status.success(), "cargo build -p arr-daemon failed"); + let output = build.output().expect("run cargo build"); + assert!(output.status.success(), "cargo build -p arr-daemon failed"); - // The test binary runs from target//deps/; the daemon lands - // one directory up, whatever the target directory and profile are. - let mut path = std::env::current_exe().expect("current test binary path"); - path.pop(); - if path.ends_with("deps") { - path.pop(); - } - let binary = path.join("arr"); - assert!( - binary.is_file(), - "expected daemon binary at {}", - binary.display() - ); - binary + let stdout = String::from_utf8(output.stdout).expect("cargo build output is UTF-8"); + stdout + .lines() + .filter_map(|line| serde_json::from_str::(line).ok()) + .find(|message| { + message["reason"] == "compiler-artifact" && message["target"]["name"] == "arr" + }) + .and_then(|message| message["executable"].as_str().map(PathBuf::from)) + .expect("cargo build reported the arr executable") }) }