ci/verbs/tests/ci_runner_prunes_its_target.rs
//! Guard: the CI runner's shared target stays bounded **after** every step and every run,
//! not only before the next one (coordinator, 2026-10-25: /work/ci's target grew to 131 GB
//! inside one monetize run, because the bound was checked only before a step).
use std::path::Path;
use std::process::Command;
fn ci(name: &str) -> std::path::PathBuf {
Path::new(env!("CARGO_MANIFEST_DIR")).join("..").join(name)
}
fn runner() -> String {
std::fs::read_to_string(ci("runner.sh")).expect("ci/runner.sh")
}
/// `ci/prune-target.sh <dir> <limit-GB>` removes the target above the limit and keeps it
/// at or under it.
#[test]
fn the_prune_script_removes_a_target_over_its_bound_and_keeps_one_under_it() {
let base = std::env::temp_dir().join(format!("ci-prune-{}", std::process::id()));
let t = base.join("target");
std::fs::create_dir_all(t.join("debug")).unwrap();
std::fs::write(t.join("debug/blob"), vec![7u8; 2 << 20]).unwrap();
let run = |lim: &str| Command::new("sh").arg(ci("prune-target.sh")).arg(&t).arg(lim).status().expect("run prune-target.sh");
assert!(run("5").success());
assert!(t.join("debug/blob").exists(), "2 MB is under a 5 GB bound: kept");
assert!(run("0").success());
assert!(!t.exists(), "over a 0 GB bound: removed");
assert!(run("0").success(), "a missing target is no error");
let _ = std::fs::remove_dir_all(&base);
}
/// The runner bounds its target after EVERY verb and once more at the end of the run.
#[test]
fn the_runner_prunes_after_each_step_and_after_the_run() {
let s = runner();
let code: Vec<&str> = s.lines().filter(|l| !l.trim_start().starts_with('#')).collect();
let body = code.join("\n");
assert!(body.contains("prune-target.sh"), "bound() calls ci/prune-target.sh");
let after_verb = body.find("run_verb \"$name\"").and_then(|i| body[i..].find("bound").map(|j| i + j));
let file = body.find("file_run \"$name\"");
assert!(matches!((after_verb, file), (Some(b), Some(f)) if b > f), "bound runs after each verb and its filing:\n{body}");
let status = body.find("-- status --runs").expect("the status step");
assert!(body[status..].contains("bound"), "bound runs once more at the end of the run");
}