facett-core/examples/checkout_surface.rs
//! **Pre-build assertion: are this build's siblings at the ref you think?**
//!
//! ```sh
//! cargo run -p facett-core --example checkout_surface -- [workspace-root ...]
//! ```
//!
//! Exit 0 when every repo-escaping `path =` dependency of every named workspace
//! resolves into a checkout sitting on its own `origin/HEAD` with a clean tree.
//! Exit 1 otherwise, naming each offender in one line — which is the sentence
//! three phantom findings on 2026-08-22 needed and did not get: *your sibling is
//! stale*, said before a build turns it into a mystery compile error.
//!
//! Cheap enough to run in front of a build: it reads manifests and asks `git`,
//! and never resolves a dependency graph — the graph is exactly what a missing
//! or stale sibling breaks.
use facett_core::law;
use std::path::PathBuf;
fn main() {
let roots: Vec<PathBuf> = {
let a: Vec<String> = std::env::args().skip(1).collect();
if a.is_empty() { vec![std::env::current_dir().unwrap()] } else { a.into_iter().map(PathBuf::from).collect() }
};
let mut bad = 0usize;
let mut checked = 0usize;
for root in &roots {
let root = law::workspace_root(root);
let escapes = law::escaping_path_deps(&root);
let survey = law::sibling_survey(&root);
checked += survey.len();
let offenders: Vec<_> = survey.iter().filter(|s| !s.state.is_trustworthy()).collect();
println!(
"{} — {} — {} repo-escaping path deps into {} distinct checkouts, {} not at origin/HEAD",
root.file_name().map(|s| s.to_string_lossy().to_string()).unwrap_or_else(|| root.display().to_string()),
if offenders.is_empty() { "OK" } else { "STALE" },
escapes.len(),
survey.len(),
offenders.len()
);
for s in offenders {
println!(" {}", s.describe());
bad += 1;
}
}
if bad > 0 {
eprintln!("\n{bad} of {checked} sibling checkouts are not what this build claims to link.");
std::process::exit(1);
}
}