use super::tests::{AGENT, repo_with};
use super::tests_own_product::{OneCallFails, commit_side_effect, nothing_staged};
use super::*;
use crate::prompt::dispatch::MESSAGES_DIR;
use crate::template::RealGit;
use std::cell::RefCell;
#[test]
fn a_failed_removal_set_read_surfaces_as_a_git_error() {
let git = OneCallFails {
fails: "ls-files",
founding: "cafe1234\n".into(),
seen: RefCell::new(Vec::new()),
};
let err = mark_for_deletion(
std::path::Path::new("/nowhere"),
AGENT,
"summary/001.md",
&git,
)
.unwrap_err();
assert!(
matches!(
err,
Error::Git {
op: "mark_for_deletion removal set",
..
}
),
"{err:?}"
);
}
#[test]
fn nominating_the_summary_directory_is_declined_for_this_passs_summary() {
let dir = repo_with("messages/002-user.md");
let wt = dir.path();
let rel = write_summary(wt, "the span so far\n").unwrap();
commit_side_effect(wt);
let err = mark_for_deletion(wt, AGENT, SUMMARY_DIR, &RealGit::new()).unwrap_err();
assert!(
matches!(&err, Error::NotCompactionEligible { path, .. } if path == SUMMARY_DIR),
"{err:?}"
);
let text = err.to_string();
assert!(text.contains(&rel), "{text}");
assert!(
text.contains("this compaction pass's own product"),
"{text}"
);
assert!(wt.join(&rel).exists());
nothing_staged(wt);
}
#[test]
fn nominating_the_summary_directory_still_supersedes_an_earlier_passs_chain() {
let dir = repo_with("summary/001.md");
let wt = dir.path();
mark_for_deletion(wt, AGENT, SUMMARY_DIR, &RealGit::new()).unwrap();
assert!(!wt.join("summary/001.md").exists());
}
#[test]
fn nominating_the_messages_directory_is_declined_for_the_dispatch_entry() {
let dir = repo_with("messages/001-user.md");
let wt = dir.path();
std::fs::write(wt.join("messages/002-user.md"), "later\n").unwrap();
commit_side_effect(wt);
let err = mark_for_deletion(wt, AGENT, MESSAGES_DIR, &RealGit::new()).unwrap_err();
assert!(
matches!(&err, Error::NotCompactionEligible { path, .. } if path == MESSAGES_DIR),
"{err:?}"
);
let text = err.to_string();
assert!(text.contains("messages/001-user.md"), "{text}");
assert!(text.contains("dispatch entry"), "{text}");
assert!(wt.join("messages/001-user.md").exists());
assert!(wt.join("messages/002-user.md").exists());
nothing_staged(wt);
}
#[test]
fn nominating_the_worktree_root_is_declined_for_the_system_slot() {
let dir = repo_with("goal.md");
let wt = dir.path();
let err = mark_for_deletion(wt, AGENT, ".", &RealGit::new()).unwrap_err();
assert!(
matches!(&err, Error::NotCompactionEligible { path, .. } if path == "."),
"{err:?}"
);
let text = err.to_string();
assert!(text.contains("goal.md"), "{text}");
assert!(text.contains("system slot"), "{text}");
assert!(wt.join("goal.md").exists());
nothing_staged(wt);
}
#[test]
fn a_directory_with_nothing_not_eligible_under_it_is_shed_whole() {
let dir = repo_with("notes/scratch/a.md");
let wt = dir.path();
mark_for_deletion(wt, AGENT, "notes", &RealGit::new()).unwrap();
assert!(!wt.join("notes/scratch/a.md").exists());
}