tests/probe_suite.rs
//! Runs the `probe/` crate's own test suite as part of THIS crate's `cargo test`.
//!
//! # Why this file exists
//!
//! `probe/` is a deliberately standalone workspace (`probe/Cargo.toml` declares its
//! own `[workspace]`) so the probe can cross-compile to static musl without the
//! parent's ring/zbus/rcgen closure. That isolation has a cost nobody had paid:
//! **the parent's `cargo test` never reaches it, and this repo has no CI.** The
//! probe's tests therefore only ever ran if a human hand-typed
//! `--manifest-path probe/Cargo.toml`.
//!
//! That is the same failure the probe itself was just fixed for, one level up: a
//! suite that cannot fail because it is never invoked is not evidence. The probe is
//! the component the whole install matrix TRUSTS as ground truth
//! (`matrix::ProbeReport::is_healthy` → `running && health.ok`), so its tests are
//! precisely the ones that must not be optional.
//!
//! The nested crate has **zero dependencies** (std only), so this costs a sub-second
//! compile and needs no network — hence `--offline`, which also keeps a `cargo test`
//! in an airgapped guest honest.
use std::path::Path;
use std::process::Command;
#[test]
fn the_probe_crates_own_tests_pass() {
let root = Path::new(env!("CARGO_MANIFEST_DIR"));
let manifest = root.join("probe/Cargo.toml");
assert!(
manifest.exists(),
"probe/Cargo.toml is missing — the install matrix has no ground-truth probe \
to inject ({})",
manifest.display()
);
// A private target dir: never share the parent's (different workspace, and a
// shared dir invites fingerprint churn between the two).
let target_dir = Path::new(env!("CARGO_TARGET_TMPDIR")).join("probe-suite");
let out = Command::new(env!("CARGO"))
.args(["test", "--offline", "--manifest-path"])
.arg(&manifest)
.arg("--target-dir")
.arg(&target_dir)
// Inherited CARGO_* from the outer invocation would otherwise redirect the
// nested build back into the parent's workspace.
.env_remove("CARGO_TARGET_DIR")
.env_remove("CARGO_BUILD_TARGET")
.output()
.expect("invoke cargo for the probe crate");
if !out.status.success() {
panic!(
"the probe crate's tests FAILED — the install matrix's ground truth is \
untrustworthy until they pass.\n\
--- stdout ---\n{}\n--- stderr ---\n{}",
String::from_utf8_lossy(&out.stdout),
String::from_utf8_lossy(&out.stderr),
);
}
// Guard against the suite silently emptying out: `cargo test` exits 0 for a
// crate with no tests at all, which would restore the very hole this closes.
let stdout = String::from_utf8_lossy(&out.stdout);
let ran: usize = stdout
.lines()
.filter_map(|l| l.strip_prefix("running "))
.filter_map(|l| l.split_whitespace().next())
.filter_map(|n| n.parse::<usize>().ok())
.sum();
assert!(
ran >= 15,
"expected the probe suite to still contain its regression tests, but only \
{ran} test(s) ran. Did a target get renamed or a test file dropped?\n{stdout}"
);
}