xtask/tests/deploy_check.rs
//! **The deployment check reports red**, injury by injury (roadmap phase 5).
//!
//! `xtask/src/deploy_check.rs` asserts rules about `deploy/`. This asserts the
//! checker: every deliberate defect must turn it red, and the pristine
//! manifests must be green.
//!
//! Without this, a check that never fires would be indistinguishable from
//! manifests that hold. `xtask/src/images.rs` records this repository shipping
//! a guard that was green while the constraint it protected was broken; the
//! `Injury` sweep is the standing answer to that.
use xtask::deploy_check::{check, red, Injury, Manifests};
fn root() -> std::path::PathBuf {
// `CARGO_MANIFEST_DIR` is `<root>/xtask`.
std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
.parent()
.expect("xtask has a parent")
.to_path_buf()
}
fn manifests() -> Manifests {
Manifests::read(&root()).expect("deploy/ is part of the repository")
}
/// The manifests that ship hold every rule they claim.
#[test]
fn the_shipped_manifests_are_green() {
let violations = check(&manifests());
assert!(
violations.is_empty(),
"the deployment manifests broke their own rules:\n{}",
violations
.iter()
.map(|v| format!(" {}: {}", v.where_, v.what))
.collect::<Vec<_>>()
.join("\n")
);
}
/// **Every injury turns it red.** Named individually, so a failure says which
/// check stopped biting rather than that "the sweep failed".
#[test]
fn every_injury_is_caught() {
let manifests = manifests();
let survived = red(&manifests);
assert!(
survived.is_empty(),
"these defects were not caught, so those checks do not bite: {}",
survived
.iter()
.map(|injury| injury.label())
.collect::<Vec<_>>()
.join(", ")
);
assert_eq!(
Injury::ALL.len(),
7,
"the injury list changed; a new rule in `check` needs an injury proving it fires, \
and a removed one needs its injury removed with it"
);
}
/// The injuries are not all the same injury.
///
/// A sweep where every variant happened to break the same rule would pass
/// `every_injury_is_caught` while proving one check and nothing else, which is
/// exactly the vacuous-guard shape this file exists to prevent.
#[test]
fn each_injury_breaks_a_different_rule() {
let manifests = manifests();
let mut seen: Vec<String> = Vec::new();
for injury in Injury::ALL {
let violations = check(&manifests.injured(*injury));
let first = violations
.first()
.unwrap_or_else(|| panic!("{} was not caught at all", injury.label()));
let signature = format!(
"{}::{}",
first.where_,
&first.what[..40.min(first.what.len())]
);
assert!(
!seen.contains(&signature),
"{} broke the same rule as an earlier injury ({signature}); the sweep proves \
fewer checks than it appears to",
injury.label()
);
seen.push(signature);
}
}