use super::*;
use crate::delivery_repo::tests::project;
use std::fs;
use std::path::PathBuf;
fn seal_lost() -> io::Error {
io::Error::other(
"sealing onto the anvil failed: the store moved under this op — a concurrent `bl` won \
the seal; nothing was written",
)
}
fn delivered(id: &str, integration: &str) -> (tempfile::TempDir, PathBuf) {
let (tmp, root, p) = project();
let branch = work_branch(id);
let wt = tmp.path().join(id);
p.materialize(&wt, &branch).unwrap();
fs::write(wt.join("feature.txt"), "shipped\n").unwrap();
Project::run(&wt, &["add", "-A"]).unwrap();
Project::run(&wt, &["commit", "-qm", "wip"]).unwrap();
let subject = format!("Add feature [{id}]");
p.deliver(&wt, &branch, integration, &subject, &marker(id)).unwrap();
(tmp, root)
}
#[test]
fn a_close_whose_squash_landed_is_re_voiced_with_the_commit_and_the_ref() {
let (_tmp, root) = delivered("bl-x", "main");
let sha = Project::run(&root, &["rev-parse", "main"]).unwrap().trim().to_string();
let out = amend(seal_lost(), &root, Verb::Close, "bl-x", None).to_string();
assert!(out.contains("nothing was written"), "{out}");
assert!(out.contains("delivered, not sealed"), "{out}");
assert!(out.contains(&format!("commit {sha} is on main.")), "{out}");
assert!(out.contains("Do not redo the work and do not unclaim"), "{out}");
assert!(out.contains("Re-run `bl close`"), "{out}");
}
#[test]
fn every_other_verb_passes_through_even_when_a_delivery_stands() {
let (_tmp, root) = delivered("bl-x", "main");
let out = amend(seal_lost(), &root, Verb::Create, "bl-x", None).to_string();
assert_eq!(out, seal_lost().to_string());
}
#[test]
fn a_close_that_aborted_before_its_squash_passes_through() {
let (tmp, _root, p) = project();
p.materialize(&tmp.path().join("wt"), "work/bl-x").unwrap();
let out = amend(seal_lost(), &p.root, Verb::Close, "bl-x", None).to_string();
assert_eq!(out, seal_lost().to_string());
}
#[test]
fn an_unprovable_delivery_is_silence_not_a_second_abort() {
let (tmp, root, _p) = project();
assert_eq!(amend(seal_lost(), &root, Verb::Close, "bl-none", None).to_string(), seal_lost().to_string());
let bare = tmp.path().join("not-a-repo");
fs::create_dir(&bare).unwrap();
assert_eq!(amend(seal_lost(), &bare, Verb::Close, "bl-x", None).to_string(), seal_lost().to_string());
}
#[test]
fn a_nested_close_names_the_epic_ref_it_delivered_into() {
let (tmp, root, p) = project();
p.mint("work/bl-epic", "main").unwrap();
let wt = tmp.path().join("kid");
p.materialize(&wt, "work/bl-kid").unwrap();
fs::write(wt.join("kid.txt"), "kid\n").unwrap();
Project::run(&wt, &["add", "-A"]).unwrap();
Project::run(&wt, &["commit", "-qm", "kid work"]).unwrap();
p.deliver(&wt, "work/bl-kid", "work/bl-epic", "Kid [bl-kid]", "[bl-kid]").unwrap();
let sha = Project::run(&root, &["rev-parse", "work/bl-epic"]).unwrap().trim().to_string();
let out = amend(seal_lost(), &root, Verb::Close, "bl-kid", Some("bl-epic")).to_string();
assert!(out.contains(&format!("[bl-kid] delivery commit {sha} is on work/bl-epic.")), "{out}");
assert!(!out.contains("is on main"), "{out}");
}