use super::*;
#[test]
fn load_makes_the_named_tools_callable_and_durable() {
let root = TempDir::new().expect("tmp");
let said = against(
root.path(),
vec![row("laptop", true, vec![tool("Bash"), tool("Read")])],
&json!({"op": "load", "client": "laptop", "tools": ["Bash"]}),
)
.expect("loaded");
assert!(said.contains("loaded, observed 1970-01-01"), "{said}");
assert!(said.contains("laptop_Bash — what Bash does"), "{said}");
assert!(said.contains("now holds 1 loaded tool."), "{said}");
assert!(said.contains("op=unload drops them again"), "{said}");
let held = crate::tool_host::loaded::read(root.path(), "home", "dulcet-mongoose");
assert_eq!(held.len(), 1);
assert_eq!(held[0].tool, tool("Bash"), "the definition is frozen whole");
}
#[test]
fn an_unadvertised_tool_refuses_the_whole_load() {
let root = TempDir::new().expect("tmp");
let e = against(
root.path(),
vec![row("laptop", true, vec![tool("Bash")])],
&json!({"op": "load", "client": "laptop", "tools": ["Bash", "Nope"]}),
)
.expect_err("refused");
assert!(e.contains("advertises no tool \"Nope\""), "{e}");
assert!(
crate::tool_host::loaded::read(root.path(), "home", "dulcet-mongoose").is_empty(),
"nothing was recorded"
);
}
#[test]
fn a_name_a_provider_would_refuse_declines_at_the_load() {
let root = TempDir::new().expect("tmp");
let e = against(
root.path(),
vec![row("laptop.local", true, vec![tool("Bash")])],
&json!({"op": "load", "client": "laptop.local", "tools": ["Bash"]}),
)
.expect_err("refused");
assert!(
e.contains("\"laptop.local_Bash\" is not a usable tool name"),
"{e}"
);
}
#[test]
fn a_load_that_cannot_be_recorded_says_so() {
let root = TempDir::new().expect("tmp");
let mut s = site(root.path(), budget());
s.agent = "..".to_owned();
let (handle, _seen) = engine(
root.path(),
&reply::encode(&Reply::Clients(vec![row(
"laptop",
true,
vec![tool("Bash")],
)])),
);
let e = answer(
&s,
&json!({"op": "load", "client": "laptop", "tools": ["Bash"]}),
&quiet(),
)
.expect_err("unrecordable");
handle.join().expect("engine");
assert!(e.contains("recording the load"), "{e}");
}