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 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
d2ba3a9ee5
commit
cee6677121
+19
-20
@@ -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<PathBuf> = 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/<profile>/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::<serde_json::Value>(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")
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user