fabro/lib/crates/fabro-cli/tests/it/cmd/system_prune.rs
Bryan Helmkamp 4dc31192b8 refactor(scratch): remove stale scratch file refs
Drop scratch-only compatibility paths and legacy test scaffolding now that
SlateDB-backed state is authoritative. This removes scratch file fallbacks,
updates docs and UI labels, and moves tests onto durable store-backed helpers.
2026-04-07 20:40:06 -04:00

138 lines
4.3 KiB
Rust

use fabro_test::{fabro_snapshot, test_context};
use super::support::{setup_completed_fast_dry_run, setup_created_fast_dry_run};
#[test]
fn help() {
let context = test_context!();
let mut cmd = context.command();
cmd.args(["system", "prune", "--help"]);
fabro_snapshot!(context.filters(), cmd, @"
success: true
exit_code: 0
----- stdout -----
Delete old workflow runs
Usage: fabro system prune [OPTIONS]
Options:
--json Output as JSON [env: FABRO_JSON=]
--storage-dir <STORAGE_DIR> Local storage directory (default: ~/.fabro/storage) [env: FABRO_STORAGE_DIR=]
--debug Enable DEBUG-level logging (default is INFO) [env: FABRO_DEBUG=]
--server <SERVER> Fabro server target: http(s) URL or absolute Unix socket path [env: FABRO_SERVER=]
--before <BEFORE> Only include runs started before this date (YYYY-MM-DD prefix match)
--no-upgrade-check Disable automatic upgrade check [env: FABRO_NO_UPGRADE_CHECK=true]
--quiet Suppress non-essential output [env: FABRO_QUIET=]
--workflow <WORKFLOW> Filter by workflow name (substring match)
--label <KEY=VALUE> Filter by label (KEY=VALUE, repeatable, AND semantics)
--verbose Enable verbose output [env: FABRO_VERBOSE=]
--orphans Include orphan directories (no matching durable run)
--older-than <DURATION> Only prune runs older than this duration (e.g. 24h, 7d). Default: 24h when no explicit filters are set
--yes Actually delete (default is dry-run)
-h, --help Print help
----- stderr -----
");
}
#[test]
fn system_prune_dry_run_lists_matching_runs_without_deleting() {
let context = test_context!();
let run = setup_completed_fast_dry_run(&context);
let mut filters = context.filters();
filters.push((r"\b\d{8}-\[ULID\]".to_string(), "[DATE]-[ULID]".to_string()));
filters.push((
r"\b\d+(\.\d+)?\s(?:[KMGT]?B|B)\b".to_string(),
"[SIZE]".to_string(),
));
let mut cmd = context.command();
cmd.args([
"system",
"prune",
"--workflow",
"Simple",
"--label",
&context.test_case_label(),
]);
fabro_snapshot!(filters, cmd, @"
success: true
exit_code: 0
----- stdout -----
would delete: [DATE]-[ULID] (Simple)
----- stderr -----
1 run(s) would be deleted ([SIZE] freed). Pass --yes to confirm.
");
assert!(
run.run_dir.exists(),
"dry-run prune should not delete the run"
);
}
#[test]
fn system_prune_yes_deletes_matching_runs() {
let context = test_context!();
let run = setup_completed_fast_dry_run(&context);
let mut filters = context.filters();
filters.push((
r"\b\d+(\.\d+)?\s(?:[KMGT]?B|B)\b".to_string(),
"[SIZE]".to_string(),
));
let mut cmd = context.command();
cmd.args([
"system",
"prune",
"--workflow",
"Simple",
"--label",
&context.test_case_label(),
"--yes",
]);
fabro_snapshot!(filters, cmd, @"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
1 run(s) deleted ([SIZE] freed).
");
assert!(!run.run_dir.exists(), "matching run should be deleted");
let mut ps = context.ps();
ps.args(["-a", "--json", "--label", &context.test_case_label()]);
fabro_snapshot!(context.filters(), ps, @r###"
success: true
exit_code: 0
----- stdout -----
[]
----- stderr -----
"###);
}
#[test]
fn system_prune_does_not_delete_active_or_submitted_runs() {
let context = test_context!();
let run = setup_created_fast_dry_run(&context);
let mut cmd = context.command();
cmd.args([
"system",
"prune",
"--workflow",
"Simple",
"--label",
&context.test_case_label(),
"--yes",
]);
fabro_snapshot!(context.filters(), cmd, @"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
No matching runs to prune.
");
assert!(
run.run_dir.exists(),
"submitted run should not be deleted by system prune"
);
}