test(e2e): let cargo report the daemon binary path
ci / web (pull_request) Successful in 1m2s
ci / rust (pull_request) Successful in 1m21s
e2e / e2e (pull_request) Successful in 1m40s

Replaces the current_exe-derived target layout guess with the
compiler-artifact message from the build itself.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Miguel Palhas
2026-08-22 21:20:24 +01:00
co-authored by Claude Fable 5
parent d2ba3a9ee5
commit cee6677121
+19 -20
View File
@@ -265,14 +265,18 @@ impl Drop for Daemon {
/// Build the `arr` binary once per test run and return its path. /// 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, /// `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 /// so the daemon is built here, and cargo itself reports where the executable
/// against concurrent test processes, and a warm target directory makes it a /// landed — no guessing at the target layout the test runner uses. Cargo's
/// no-op. /// own file locking serialises this against concurrent test processes, and a
/// warm target directory makes it a no-op.
fn daemon_binary() -> &'static PathBuf { fn daemon_binary() -> &'static PathBuf {
static BINARY: OnceLock<PathBuf> = OnceLock::new(); static BINARY: OnceLock<PathBuf> = OnceLock::new();
BINARY.get_or_init(|| { BINARY.get_or_init(|| {
let mut build = Command::new(env!("CARGO")); 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* // The test process carries the per-crate vars cargo set for *this*
// crate (CARGO_MANIFEST_DIR, CARGO_PKG_*). Inherited into a nested // crate (CARGO_MANIFEST_DIR, CARGO_PKG_*). Inherited into a nested
// cargo they poison its fingerprints, so every shell build and every // cargo they poison its fingerprints, so every shell build and every
@@ -285,23 +289,18 @@ fn daemon_binary() -> &'static PathBuf {
build.env_remove(key); build.env_remove(key);
} }
} }
let status = build.status().expect("run cargo build"); let output = build.output().expect("run cargo build");
assert!(status.success(), "cargo build -p arr-daemon failed"); assert!(output.status.success(), "cargo build -p arr-daemon failed");
// The test binary runs from target/<profile>/deps/; the daemon lands let stdout = String::from_utf8(output.stdout).expect("cargo build output is UTF-8");
// one directory up, whatever the target directory and profile are. stdout
let mut path = std::env::current_exe().expect("current test binary path"); .lines()
path.pop(); .filter_map(|line| serde_json::from_str::<serde_json::Value>(line).ok())
if path.ends_with("deps") { .find(|message| {
path.pop(); message["reason"] == "compiler-artifact" && message["target"]["name"] == "arr"
} })
let binary = path.join("arr"); .and_then(|message| message["executable"].as_str().map(PathBuf::from))
assert!( .expect("cargo build reported the arr executable")
binary.is_file(),
"expected daemon binary at {}",
binary.display()
);
binary
}) })
} }