use super::{Error, Fx, Outcome};
use crate::harness_root::{self, Roots};
use crate::install::Founding;
#[derive(clap::Args, Debug)]
pub struct Args {}
pub fn run(_args: Args, _fx: &mut Fx) -> Result<Outcome, Error> {
go().map_err(|e| Error::new("prime", e))
}
fn go() -> Result<Outcome, Box<dyn std::error::Error>> {
let roots = harness_root::resolve()?;
let founding = crate::install::prime(&roots)?;
eprintln!("{}", report(&roots, &founding));
Ok(Outcome::Quiet)
}
fn report(roots: &Roots, founding: &Founding) -> String {
let Founding { seeded, kept } = *founding;
format!(
"lernie prime: config root {} — models.yaml, workflows/\n\
lernie prime: data root {} — tools/, skills/, workspaces/\n\
lernie prime: harness root founded: {seeded} files seeded, {kept} already present \
and left alone (seed-if-absent, ARCH §2.2)",
roots.config.display(),
roots.data.display(),
)
}
#[cfg(test)]
mod tests {
use super::*;
use std::path::PathBuf;
fn roots() -> Roots {
Roots {
config: PathBuf::from("/xc/lernie"),
data: PathBuf::from("/xd/lernie"),
}
}
#[test]
fn report_names_both_roots_and_what_this_run_seeded() {
let r = report(
&roots(),
&Founding {
seeded: 15,
kept: 0,
},
);
assert_eq!(
r,
"lernie prime: config root /xc/lernie — models.yaml, workflows/\n\
lernie prime: data root /xd/lernie — tools/, skills/, workspaces/\n\
lernie prime: harness root founded: 15 files seeded, 0 already present \
and left alone (seed-if-absent, ARCH §2.2)"
);
}
#[test]
fn report_on_a_re_run_says_nothing_was_re_seeded() {
let r = report(
&roots(),
&Founding {
seeded: 0,
kept: 15,
},
);
assert!(
r.ends_with(
"0 files seeded, 15 already present and left alone (seed-if-absent, ARCH §2.2)"
),
"{r}"
);
}
}