Add the startup self-test and the loopd selftest command
Implemented-By: OpenCode session (model recorded in docs/implementer-log.md)
This commit is contained in:
@@ -1,4 +1,47 @@
|
||||
fn main() {
|
||||
eprintln!("loopd: not implemented until M2");
|
||||
std::process::exit(2);
|
||||
//! `loopd`: the agent loop daemon. Its one command today is `selftest`, which runs the startup
|
||||
//! checks before `loopd` serves anyone.
|
||||
|
||||
use std::path::Path;
|
||||
use std::process::ExitCode;
|
||||
|
||||
use loopd::config::Config;
|
||||
use loopd::llama::Client;
|
||||
use loopd::selftest::run;
|
||||
|
||||
fn main() -> ExitCode {
|
||||
let args: Vec<String> = std::env::args().skip(1).collect();
|
||||
let args: Vec<&str> = args.iter().map(String::as_str).collect();
|
||||
match args.as_slice() {
|
||||
["selftest", "--config", path] => run_selftest(path),
|
||||
_ => {
|
||||
eprintln!("usage: loopd selftest --config <path>");
|
||||
ExitCode::from(2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn run_selftest(path: &str) -> ExitCode {
|
||||
let cfg = match Config::load(Path::new(path)) {
|
||||
Ok(cfg) => cfg,
|
||||
Err(e) => {
|
||||
eprintln!("loopd: {e}");
|
||||
return ExitCode::from(1);
|
||||
}
|
||||
};
|
||||
|
||||
let mut on_step = |step: &str| {
|
||||
eprintln!("selftest: {step}");
|
||||
};
|
||||
let result = run(&Client::new(cfg), &mut on_step);
|
||||
|
||||
match result {
|
||||
Ok(()) => {
|
||||
eprintln!("selftest: ok");
|
||||
ExitCode::SUCCESS
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("selftest: FAILED: {e}");
|
||||
ExitCode::from(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user