use super::{Error, compactor, reviewer};
use std::path::Path;
pub(crate) type CheckpointGoal = fn(&Path, &str) -> Result<String, Error>;
pub(crate) fn checkpoint_goal(role: &str) -> Option<CheckpointGoal> {
match role {
compactor::COMPACTOR_ROLE => Some(compactor::compactor_goal),
reviewer::REVIEWER_ROLE => Some(reviewer::reviewer_goal),
_ => None,
}
}
pub(crate) fn is_checkpoint_child(role: &str) -> bool {
checkpoint_goal(role).is_some()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn the_harness_minted_roles_are_exactly_the_ones_it_can_instruct() {
for role in [compactor::COMPACTOR_ROLE, reviewer::REVIEWER_ROLE] {
assert!(checkpoint_goal(role).is_some(), "{role} is instructable");
assert!(is_checkpoint_child(role), "{role} is machinery");
}
}
#[test]
fn an_ordinary_role_is_neither_instructable_nor_machinery() {
for role in ["worker", "verifier", ""] {
assert!(checkpoint_goal(role).is_none(), "{role:?}");
assert!(!is_checkpoint_child(role), "{role:?}");
}
}
#[test]
fn the_goal_builder_it_hands_back_is_the_roles_own() {
let dir = tempfile::tempdir().unwrap();
std::fs::write(dir.path().join("goal.md"), "ship the widget").unwrap();
let compactor_text =
checkpoint_goal(compactor::COMPACTOR_ROLE).unwrap()(dir.path(), "20260101-p1").unwrap();
assert!(
compactor_text.contains("compactor for branch"),
"{compactor_text}"
);
let reviewer_text =
checkpoint_goal(reviewer::REVIEWER_ROLE).unwrap()(dir.path(), "20260101-p1").unwrap();
assert!(
reviewer_text.contains("reviewer for branch"),
"{reviewer_text}"
);
}
}