use std::path::{Path, PathBuf};
fn repo_root() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("../..")
.canonicalize()
.expect("resolve repo root")
}
fn read(path: &Path) -> String {
std::fs::read_to_string(path).unwrap_or_else(|e| panic!("read {}: {e}", path.display()))
}
fn script() -> String {
read(&repo_root().join("scripts/cut-release.sh"))
}
#[test]
fn unset_signing_key_fails_loudly_before_tagging() {
let source = script();
assert!(
source.contains("devflow.releaseSigningKey is not set"),
"cut-release.sh must print a 'devflow.releaseSigningKey is not set' \
diagnostic when the key is unset"
);
let resolve_line = source
.lines()
.find(|l| l.contains("local release_key; release_key="))
.expect("cut-release.sh must resolve devflow.releaseSigningKey via git config --get");
assert!(
resolve_line.contains("|| true"),
"the release-key resolution must tolerate an unset key (`|| true`), \
otherwise `set -e` aborts at the assignment and the guard never \
explains itself\n offending line: {}",
resolve_line.trim()
);
let unset_guard = source
.find("if [ -z \"$release_key\" ]")
.expect("cut-release.sh must guard the unset-key case");
let tag = source
.find("tag -s")
.expect("cut-release.sh must invoke tag -s");
assert!(
unset_guard < tag,
"the unset-key guard must fire before `tag -s` so a missing key fails \
loudly rather than silently signing with the wrong identity"
);
}
#[test]
fn unreadable_key_file_fails_loudly() {
let source = script();
assert!(
source.contains(r#"[ ! -r "$release_key_expanded" ]"#),
"cut-release.sh must guard against an unreadable key file with a \
readability test on the tilde-expanded path"
);
assert!(
source.contains("points at an unreadable file"),
"cut-release.sh must name the unreadable-file failure mode in its \
diagnostic"
);
}
#[test]
fn deterministic_override_is_preserved() {
let source = script();
assert!(
source.contains(r#"git -c user.signingkey="$release_key_expanded""#),
"the tag must still be signed with the resolved maintainer key via the \
in-code `git -c user.signingkey=` override"
);
}