use super::tests::{BASH_SCHEMA, custom, granted, history_calling, write_schema, write_skill};
use super::*;
use brazen::Content;
use serde_json::json;
use tempfile::TempDir;
#[test]
fn a_tool_the_history_names_but_the_role_may_not_call_is_declared_as_refused() {
let wt = TempDir::new().unwrap();
write_schema(wt.path(), "bash", BASH_SCHEMA);
write_skill(
wt.path(),
"bash",
"name: bash\ndescription: Run a shell command.\n",
);
let tools = compose(wt.path(), &granted(&[]), &history_calling(&["bash"]), &[]).unwrap();
assert_eq!(tools.len(), 1);
let (name, description, input_schema) = custom(&tools[0]);
assert_eq!(name, "bash");
let description = description.expect("a refused entry says so");
assert!(
description.contains("not callable by a worker"),
"{description}"
);
assert!(
description.contains("declaring is not permitting"),
"{description}"
);
assert_eq!(*input_schema, json!({"type":"object"}));
assert_eq!(
Some(description.to_string()),
crate::prompt::dispatch::tool_step::permit::refusal("worker", &[], &[], "bash")
);
}
#[test]
fn a_granted_tool_the_history_names_keeps_its_definition() {
let wt = TempDir::new().unwrap();
write_skill(
wt.path(),
"bash",
"name: bash\ndescription: Run a shell command.\n",
);
let grant = ["bash".to_string()];
let tools = compose(
wt.path(),
&granted(&grant),
&history_calling(&["bash"]),
&[],
)
.unwrap();
assert_eq!(tools.len(), 1);
let (name, description, input_schema) = custom(&tools[0]);
assert_eq!(name, "bash");
assert_eq!(description, Some("Run a shell command."));
assert_eq!(*input_schema, json!({"type":"object"}));
}
#[test]
fn an_already_declared_tool_is_never_declared_twice() {
let wt = TempDir::new().unwrap();
write_schema(wt.path(), "bash", BASH_SCHEMA);
let declared = ["bash".to_string()];
let tools = compose(
wt.path(),
&granted(&declared),
&history_calling(&["bash", "bash"]),
&[],
)
.unwrap();
let names: Vec<&str> = tools.iter().map(|t| custom(t).0).collect();
assert_eq!(names, vec!["bash"]);
}
#[test]
fn a_history_with_no_tool_use_leaves_the_declaration_alone() {
let wt = TempDir::new().unwrap();
write_schema(wt.path(), "bash", BASH_SCHEMA);
let history = vec![Message {
role: brazen::Role::User,
content: vec![Content::Text("just talking".into())],
}];
let declared = ["bash".to_string()];
let tools = compose(wt.path(), &granted(&declared), &history, &[]).unwrap();
let names: Vec<&str> = tools.iter().map(|t| custom(t).0).collect();
assert_eq!(names, vec!["bash"]);
}