use std::path::PathBuf;
#[must_use]
fn repo_receipt() -> Option<PathBuf> {
let crate_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
crate_dir
.ancestors()
.find(|ancestor| ancestor.join("rust/Cargo.toml").is_file())
.map(|root| root.join(".build-number"))
}
#[test]
#[expect(
clippy::print_stderr,
reason = "a skipped gate must state its reason where the runner shows it"
)]
fn embedded_receipt_matches_the_repo_receipt_file() {
let Some(receipt) = repo_receipt() else {
eprintln!(
"SKIP: no repository root found above {}",
env!("CARGO_MANIFEST_DIR")
);
return;
};
let Ok(text) = std::fs::read_to_string(&receipt) else {
eprintln!(
"SKIP: {} does not exist - a fresh checkout has no receipt until \
the first degenbot-python build writes one",
receipt.display()
);
return;
};
let mut parts = text.split_whitespace();
let (Some(count), Some(fingerprint)) = (parts.next(), parts.next()) else {
eprintln!(
"SKIP: {} is empty or malformed ({text:?}) - nothing to compare against",
receipt.display()
);
return;
};
assert_eq!(
env!("DEGENBOT_CLI_BUILD_NUMBER"),
count,
"the console's embedded build number must equal the repo receipt"
);
assert_eq!(
env!("DEGENBOT_CLI_BUILD_FINGERPRINT"),
fingerprint,
"the console's embedded build fingerprint must equal the repo receipt"
);
}