use super::attempt;
use crate::fork::{Fire, argv, pool, skills_root};
use std::path::{Path, PathBuf};
fn fire(ws: &str, parent: &str, goal: &str, attempt: crate::fork::Attempt, pool: &str) -> Fire {
Fire {
workspace: PathBuf::from(ws),
parent: parent.to_owned(),
goal: goal.to_owned(),
attempt,
skills_root: PathBuf::from(pool),
}
}
#[test]
fn one_attempt_is_the_ordinary_dispatch_with_a_ref() {
let out = argv(&fire(
"/w/home",
"20260803T090000Z-aaaa",
"try it the other way\nagain",
attempt("aaaa1111", "worker", &[]),
"/pool",
));
assert_eq!(
out,
vec![
"dispatch",
"worker",
"/w/home",
"20260803T090000Z-aaaa",
"--goal",
"try it the other way\nagain",
"--from",
"aaaa1111",
],
"the goal reaches the model unmutated, spacing and newlines included"
);
}
#[test]
fn a_clean_start_differs_only_in_the_ref() {
let here = argv(&fire(
"/w",
"root",
"g",
attempt("aaaa1111", "worker", &[]),
"/pool",
));
let clean = argv(&fire(
"/w",
"root",
"g",
attempt("config/strict", "worker", &[]),
"/pool",
));
let differ: Vec<usize> = here
.iter()
.zip(&clean)
.enumerate()
.filter(|(_, (a, b))| a != b)
.map(|(i, _)| i)
.collect();
assert_eq!(differ, vec![7], "only the ref moves: {here:?} vs {clean:?}");
}
#[test]
fn every_skill_is_one_pin_at_the_pools_own_layout() {
let out = argv(&fire(
"/w",
"root",
"g",
attempt("aaaa1111", "worker", &["bash", "read_file"]),
"/pool/skills",
));
let pins: Vec<&String> = out
.iter()
.skip_while(|a| a.as_str() != "--pin")
.filter(|a| a.as_str() != "--pin")
.collect();
assert_eq!(
pins,
vec![
"skills/bash/SKILL.md=/pool/skills/bash/SKILL.md",
"skills/read_file/SKILL.md=/pool/skills/read_file/SKILL.md",
]
);
}
#[test]
fn the_pool_is_the_worlds_skill_directories() {
let dir = tempfile::tempdir().unwrap();
let root = dir.path();
for name in ["read_file", "bash"] {
std::fs::create_dir_all(root.join(name)).unwrap();
std::fs::write(root.join(name).join("SKILL.md"), "---\nname: x\n---\n").unwrap();
}
std::fs::create_dir_all(root.join("references")).unwrap();
std::fs::write(root.join("notes.md"), "").unwrap();
assert_eq!(pool(root), vec!["bash".to_owned(), "read_file".to_owned()]);
assert!(pool(&root.join("nowhere")).is_empty());
}
#[test]
fn the_pool_lives_in_yogs_nested_world() {
assert_eq!(
skills_root(Path::new("/d/yog")),
Path::new("/d/yog/world/litany/skills")
);
}