diff --git a/src/config/skill_policy.rs b/src/config/skill_policy.rs index c331bce..7411a91 100644 --- a/src/config/skill_policy.rs +++ b/src/config/skill_policy.rs @@ -277,7 +277,10 @@ mod tests { SkillPolicy::effective_with(&global, None, None, None, &always_true, &empty_installed) .unwrap_err(); - assert!(err.to_string().contains("not in visible_skills")); + assert!( + err.to_string() + .contains("not in the global 'visible_skills'") + ); assert!(err.to_string().contains("beta")); } diff --git a/src/graph/validator.rs b/src/graph/validator.rs index 90e58b4..bd0a2cd 100644 --- a/src/graph/validator.rs +++ b/src/graph/validator.rs @@ -93,6 +93,7 @@ impl AgentValidationContext { pub struct GraphValidator { base_dir: PathBuf, agent_ctx: Option, + skill_exists: fn(&str) -> bool, } impl GraphValidator { @@ -100,6 +101,7 @@ impl GraphValidator { Self { base_dir: base_dir.into(), agent_ctx: None, + skill_exists: paths::has_skill, } } @@ -108,6 +110,12 @@ impl GraphValidator { self } + #[cfg(test)] + pub fn with_skill_exists(mut self, f: fn(&str) -> bool) -> Self { + self.skill_exists = f; + self + } + pub fn validate(&self, graph: &Graph) -> ValidationResult { let mut result = ValidationResult::default(); self.validate_node_references(graph, &mut result); @@ -196,24 +204,14 @@ impl GraphValidator { .as_ref() .and_then(|c| c.app_config.visible_skills.as_deref()); + let skill_exists = self.skill_exists; let check_visibility = |name: &str| -> Option { match visible_skills { - Some(list) => { - if !list.iter().any(|s| s == name) { - Some(format!( - "'{name}' is not in the global 'visible_skills' allow-list" - )) - } else { - None - } - } - None => { - if !paths::has_skill(name) { - Some(format!("'{name}' is not installed")) - } else { - None - } - } + Some(list) if !list.iter().any(|s| s == name) => Some(format!( + "'{name}' is not in the global 'visible_skills' allow-list" + )), + None if !skill_exists(name) => Some(format!("'{name}' is not installed")), + _ => None, } }; @@ -1375,7 +1373,7 @@ mod tests { } fn validator() -> GraphValidator { - GraphValidator::new(env::current_dir().unwrap()) + GraphValidator::new(env::current_dir().unwrap()).with_skill_exists(|_: &str| true) } #[test]