test: improved skill validation test in graph validator
This commit is contained in:
@@ -277,7 +277,10 @@ mod tests {
|
|||||||
SkillPolicy::effective_with(&global, None, None, None, &always_true, &empty_installed)
|
SkillPolicy::effective_with(&global, None, None, None, &always_true, &empty_installed)
|
||||||
.unwrap_err();
|
.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"));
|
assert!(err.to_string().contains("beta"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+15
-17
@@ -93,6 +93,7 @@ impl AgentValidationContext {
|
|||||||
pub struct GraphValidator {
|
pub struct GraphValidator {
|
||||||
base_dir: PathBuf,
|
base_dir: PathBuf,
|
||||||
agent_ctx: Option<AgentValidationContext>,
|
agent_ctx: Option<AgentValidationContext>,
|
||||||
|
skill_exists: fn(&str) -> bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GraphValidator {
|
impl GraphValidator {
|
||||||
@@ -100,6 +101,7 @@ impl GraphValidator {
|
|||||||
Self {
|
Self {
|
||||||
base_dir: base_dir.into(),
|
base_dir: base_dir.into(),
|
||||||
agent_ctx: None,
|
agent_ctx: None,
|
||||||
|
skill_exists: paths::has_skill,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,6 +110,12 @@ impl GraphValidator {
|
|||||||
self
|
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 {
|
pub fn validate(&self, graph: &Graph) -> ValidationResult {
|
||||||
let mut result = ValidationResult::default();
|
let mut result = ValidationResult::default();
|
||||||
self.validate_node_references(graph, &mut result);
|
self.validate_node_references(graph, &mut result);
|
||||||
@@ -196,24 +204,14 @@ impl GraphValidator {
|
|||||||
.as_ref()
|
.as_ref()
|
||||||
.and_then(|c| c.app_config.visible_skills.as_deref());
|
.and_then(|c| c.app_config.visible_skills.as_deref());
|
||||||
|
|
||||||
|
let skill_exists = self.skill_exists;
|
||||||
let check_visibility = |name: &str| -> Option<String> {
|
let check_visibility = |name: &str| -> Option<String> {
|
||||||
match visible_skills {
|
match visible_skills {
|
||||||
Some(list) => {
|
Some(list) if !list.iter().any(|s| s == name) => Some(format!(
|
||||||
if !list.iter().any(|s| s == name) {
|
"'{name}' is not in the global 'visible_skills' allow-list"
|
||||||
Some(format!(
|
)),
|
||||||
"'{name}' is not in the global 'visible_skills' allow-list"
|
None if !skill_exists(name) => Some(format!("'{name}' is not installed")),
|
||||||
))
|
_ => None,
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
if !paths::has_skill(name) {
|
|
||||||
Some(format!("'{name}' is not installed"))
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1375,7 +1373,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn validator() -> GraphValidator {
|
fn validator() -> GraphValidator {
|
||||||
GraphValidator::new(env::current_dir().unwrap())
|
GraphValidator::new(env::current_dir().unwrap()).with_skill_exists(|_: &str| true)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
Reference in New Issue
Block a user