An integration test that runs a binary of another workspace package must take its path from cargo, not from target/debug or current_exe
Symptom#
A test helper runs cargo build -p other-crate --bin other and then spawns target/debug/other, which is stale or missing. CARGO_BIN_EXE_<name> is not set, because the binary belongs to another package. With build.build-dir set in the cargo config, a helper that finds the binary from std::env::current_exe() also fails: the test runs from ~/.cargo/build/<hash>/debug/deps, but the binaries land in $CARGO_TARGET_DIR/debug.
Cause#
CARGO_TARGET_DIR moves the final binaries out of the repo's target/, and build.build-dir (for example "{cargo-cache-home}/build/{workspace-path-hash}") moves the test executables to another folder again. Cargo sets CARGO_BIN_EXE_* only for binaries of the package under test. A guess from either folder breaks when the user's config changes.
Fix#
In the helper, run Command::new(env!("CARGO")).args(["build", "-p", "<pkg>", "--bin", "<bin>", "--message-format", "json"]) once per test program with a OnceLock. Read the binary path from the "executable" field of the JSON line for that binary. Pass --release when the test runs in a release profile. Keep env!("CARGO_BIN_EXE_<name>") for binaries of the package under test. Pass the path to the code under test through an env var on the spawned command, since std::env::set_var is unsafe in edition 2024. Do not change the user's cargo config to make the tests pass.
Evidence#
rmaestro daemon tests, 2026-10-15: a reviewer that used target/debug ran a stale binary. rmaestro client tests, 2026-10-19: after build-dir was set, the current_exe parent-of-parent guess pointed at ~/.cargo/build/<hash>/debug, the client tests and 34 cli tests failed, and the client tests passed again after they read executable from cargo build --message-format json.