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:
2026-09-18 15:28:37 -07:00
parent 59cf89e7ba
commit f1d880568f
5 changed files with 428 additions and 3 deletions
+46 -3
View File
@@ -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)
}
}
}