swactor/xtask/src/main.rs

141 lines
3.7 KiB
Rust
Raw Normal View History

2026-05-21 19:48:02 +00:00
use std::process::{Command, ExitCode};
2026-07-07 10:40:02 +00:00
use std::time::Instant;
struct TestStep {
label: &'static str,
args: &'static [&'static str],
}
2026-06-25 12:30:18 +00:00
const BASIC_TESTS: &[TestStep] = &[
TestStep {
label: "root crate",
args: &["test"],
},
TestStep {
label: "datastream",
args: &["test", "-p", "datastream"],
},
TestStep {
label: "distribution",
args: &["test", "-p", "distribution"],
},
TestStep {
label: "iroh-driver",
args: &["test", "-p", "iroh-driver"],
},
TestStep {
label: "mvp-system",
args: &["test", "-p", "mvp-system"],
},
TestStep {
label: "swactor-process",
args: &["test", "-p", "swactor-process"],
},
TestStep {
label: "swactor-transport",
args: &["test", "-p", "swactor-transport"],
},
TestStep {
label: "dashboard",
args: &["test", "-p", "dashboard"],
},
TestStep {
label: "swactor-vastai",
args: &["test", "-p", "swactor-vastai"],
},
TestStep {
label: "xtask",
args: &["test", "-p", "xtask"],
},
];
2026-06-25 12:30:18 +00:00
fn cargo_bin() -> String {
option_env!("CARGO")
.map(str::to_string)
.unwrap_or_else(|| "cargo".to_string())
}
fn print_usage() {
println!(
"\
2026-07-05 09:59:51 +00:00
USAGE: cargo xtask <command>
2026-06-25 12:30:18 +00:00
COMMANDS:
mvp-chat [--process|--docker|--vastai] [--pipeline-stages n] [--cached-model] [-- args...] Run the human chat wrapper against the real orchestrator/worker bins.
2026-07-05 09:59:51 +00:00
test Run all basic non-binding tests. This includes the root crate with
`cargo test` plus each non-binding repository package with `cargo test -p`.
Feature-gated E2E/bin tests are intentionally excluded."
);
}
2026-06-25 12:30:18 +00:00
fn run_step(step: &TestStep) -> bool {
println!("\n=== {} ===", step.label);
println!(" cargo {}", step.args.join(" "));
println!();
2026-06-25 12:30:18 +00:00
match Command::new(cargo_bin()).args(step.args).status() {
Ok(status) => status.success(),
Err(error) => {
eprintln!("Failed to execute cargo: {error}");
false
}
}
}
2026-06-25 12:30:18 +00:00
fn run_tests() -> ExitCode {
let start = Instant::now();
2026-06-25 12:30:18 +00:00
for (index, step) in BASIC_TESTS.iter().enumerate() {
if !run_step(step) {
eprintln!(
"\n--- FAILED after {:.1}s ({index} passed, 1 failed) ---",
start.elapsed().as_secs_f64()
);
return ExitCode::from(1);
}
}
println!(
2026-06-25 12:30:18 +00:00
"\n--- All {} step(s) passed in {:.1}s ---",
BASIC_TESTS.len(),
start.elapsed().as_secs_f64()
);
2026-06-25 12:30:18 +00:00
ExitCode::SUCCESS
}
2026-07-05 09:59:51 +00:00
fn run_mvp_chat(args: Vec<String>) -> ExitCode {
2026-07-07 10:40:02 +00:00
let mut command = Command::new(cargo_bin());
2026-07-12 06:14:34 +00:00
command.args(["run", "--package", "mvp-system", "--bin", "mvp-chat", "--"]);
2026-07-05 09:59:51 +00:00
command.args(args);
2026-07-07 10:40:02 +00:00
match command.status() {
Ok(status) if status.success() => ExitCode::SUCCESS,
Ok(status) => ExitCode::from(
status
.code()
.and_then(|code| u8::try_from(code).ok())
.unwrap_or(1),
),
Err(error) => {
eprintln!("Failed to execute cargo mvp-chat: {error}");
ExitCode::from(1)
2026-07-05 09:59:51 +00:00
}
}
}
2026-05-21 19:48:02 +00:00
fn main() -> ExitCode {
2026-06-25 12:30:18 +00:00
let mut args = std::env::args().skip(1);
2026-07-05 09:59:51 +00:00
match args.next().as_deref() {
Some("test") if args.next().is_none() => run_tests(),
Some("mvp-chat") => run_mvp_chat(args.collect()),
Some("help" | "--help" | "-h") | None => {
2026-06-25 12:30:18 +00:00
print_usage();
2026-05-21 19:48:02 +00:00
ExitCode::SUCCESS
}
2026-06-25 12:30:18 +00:00
_ => {
print_usage();
2026-05-21 19:48:02 +00:00
ExitCode::from(1)
}
}
}