mod common;
use common::Root;
use std::process::Command;
fn line_for<'a>(out: &'a str, pattern: &str) -> &'a str {
out.lines()
.find(|line| line.contains(&format!("`{pattern}`")) && line.contains("in scope"))
.unwrap_or_else(|| panic!("no scope line for `{pattern}` in:\n{out}"))
}
#[test]
fn the_audit_leaves_a_file_git_ignores_out_of_the_governed_scope() {
let root = Root::new("scope-audit-ignored");
let cache = root.at.join("tools/__pycache__/stub.cpython-312.pyc");
std::fs::create_dir_all(cache.parent().expect("a parent")).expect("the cache is made");
std::fs::write(&cache, "").expect("the cache writes");
std::fs::write(root.at.join(".gitignore"), "__pycache__/\n").expect("the ignore file writes");
let before = root.run(&["taxonomy", "audit", "--now", "2026-09-25"]);
assert_eq!(before.code, Some(0), "{before:?}");
let line = line_for(&before.out, "tools/**");
assert!(line.contains(" 2 in scope"), "{line}");
let init = Command::new("git")
.args(["init", "-q"])
.current_dir(&root.at)
.status()
.expect("git runs");
assert!(init.success());
let after = root.run(&["taxonomy", "audit", "--now", "2026-09-25"]);
assert_eq!(after.code, Some(0), "{after:?}");
let line = line_for(&after.out, "tools/**");
assert!(line.contains(" 1 in scope"), "{line}");
assert!(!after.out.contains("__pycache__"), "{}", after.out);
}