use std::process::Command; use std::time::Instant; use clap::Parser; // ── CLI ───────────────────────────────────────────────────────────── #[derive(Parser)] #[command(name = "xtask", about = "Development task runner")] struct Cli { /// Test group to run (core, simulation, formal-verification, essential, all) group: Option, /// Show all groups and the cargo commands they run #[arg(long)] list: bool, } // ── Test infrastructure ───────────────────────────────────────────── struct TestStep { label: &'static str, args: &'static [&'static str], } struct Group { name: &'static str, description: &'static str, steps: &'static [TestStep], } const CORE: Group = Group { name: "core", description: "Actor runtime, message delivery, property tests", steps: &[TestStep { label: "actor runtime", args: &["test", "-p", "swactor", "--features", "transport"], }], }; const SIMULATION: Group = Group { name: "simulation", description: "Deterministic cluster simulations", steps: &[TestStep { label: "cluster simulations", args: &["test", "-p", "simulation"], }], }; const FORMAL_VERIFICATION: Group = Group { name: "formal-verification", description: "Kani proofs + Stateright model checking", steps: &[ TestStep { label: "kani proofs", args: &["kani", "-p", "swactor-datastore"], }, TestStep { label: "gateway dispatch model check", args: &[ "test", "-p", "swactor-datastore", "--test", "gateway_model_check", ], }, ], }; const GROUPS: &[&Group] = &[&CORE, &SIMULATION, &FORMAL_VERIFICATION]; fn groups_for(name: &str) -> Option> { match name { "core" => Some(vec![&CORE]), "simulation" => Some(vec![&SIMULATION]), "formal-verification" => Some(vec![&FORMAL_VERIFICATION]), "essential" => Some(vec![&CORE, &SIMULATION]), "all" => Some(vec![&CORE, &SIMULATION, &FORMAL_VERIFICATION]), _ => None, } } fn run_step(group_name: &str, step: &TestStep) -> bool { println!("\n=== {group_name}: {} ===", step.label); println!(" cargo {}", step.args.join(" ")); println!(); let status = Command::new("cargo").args(step.args).status(); match status { Ok(s) => s.success(), Err(e) => { eprintln!("Failed to execute cargo: {e}"); false } } } fn print_usage() { println!( "\ USAGE: cargo xtask test GROUPS: core Actor runtime, message delivery, property tests simulation Deterministic cluster simulations formal-verification Kani proofs + Stateright model checking essential core + simulation all Every test group FLAGS: --list Show all groups and the cargo commands they run" ); } fn print_list() { println!("Available test groups:\n"); for group in GROUPS { println!(" {:<22}{}", group.name, group.description); for step in group.steps { println!(" → cargo {}", step.args.join(" ")); } println!(); } println!(" {:<22}core + simulation", "essential"); println!(" {:<22}Every test group", "all"); } // ── Dispatch ──────────────────────────────────────────────────────── fn main() { let cli = Cli::parse(); if cli.list { print_list(); return; } let group_name = match cli.group { Some(g) => g, None => { print_usage(); std::process::exit(1); } }; let groups = match groups_for(&group_name) { Some(g) => g, None => { eprintln!("Unknown test group: {group_name}\n"); print_usage(); std::process::exit(1); } }; let start = Instant::now(); let mut passed = 0usize; let mut failed = 0usize; for group in &groups { for step in group.steps { if run_step(group.name, step) { passed += 1; } else { failed += 1; let elapsed = start.elapsed(); println!( "\n--- FAILED after {:.1}s ({passed} passed, {failed} failed) ---", elapsed.as_secs_f64() ); std::process::exit(1); } } } let elapsed = start.elapsed(); println!( "\n--- All {passed} step(s) passed in {:.1}s ---", elapsed.as_secs_f64() ); }