use super::super::{SpawnTool, ToolCall, ToolExecutor};
use super::fixtures::{FixedClock, HarnessRoot, StepDir, driver_target};
use super::injection::Embedder;
use serde_json::json;
use std::sync::atomic::AtomicBool;
#[test]
fn an_installed_host_answers_a_name_an_installed_binary_would_have() {
let root = HarnessRoot::new();
root.install("greet", r#"printf hello"#);
let clock = FixedClock::default();
let step = StepDir::new();
let host = Embedder::new("teleop");
let exec = SpawnTool::new(root.path(), &clock, driver_target()).with_injection(Some(&host));
let outcome = exec
.execute(
ToolCall {
id: "toolu_local",
name: "greet",
input: &json!({}),
},
&step.path,
&AtomicBool::new(false),
None,
)
.unwrap();
assert!(outcome.is_error, "an unowned name refuses in band");
assert_eq!(
String::from_utf8_lossy(&outcome.content),
"Exit code: 127\n--- stderr ---\nno such tool: greet",
);
assert_eq!(host.seen.borrow().len(), 1, "the host saw the invocation");
}
#[test]
fn an_unresolvable_caller_declines_before_anything_is_routed() {
let root = HarnessRoot::new();
let clock = FixedClock::default();
let host = Embedder::new("teleop");
let exec = SpawnTool::new(root.path(), &clock, driver_target()).with_injection(Some(&host));
let input = json!({});
let result = exec.execute(
ToolCall {
id: "f_nowhere",
name: "teleop",
input: &input,
},
std::path::Path::new("/nonexistent/steps/agent/001"),
&AtomicBool::new(false),
None,
);
assert!(
matches!(result, Err(super::super::ExecError::NoWorktree { .. })),
"an unresolvable caller declines before anything is routed"
);
assert!(host.seen.borrow().is_empty());
}