use super::super::{OUTPUT_FILE, STEP_TOOLS_SUBDIR, 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 a_fan_is_answered_entirely_by_the_host_in_list_order() {
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 input = json!({});
let results = exec.execute_all(
&[
ToolCall {
id: "f_local",
name: "greet",
input: &input,
},
ToolCall {
id: "f_routed",
name: "teleop",
input: &input,
},
],
&step.path,
&AtomicBool::new(false),
None,
);
let rendered: Vec<String> = results
.into_iter()
.map(|r| String::from_utf8_lossy(&r.unwrap().content).into_owned())
.collect();
assert_eq!(
rendered,
vec![
"Exit code: 127\n--- stderr ---\nno such tool: greet",
"Exit code: 0\nrouted product",
],
);
for id in ["f_local", "f_routed"] {
assert!(
step.path
.join(STEP_TOOLS_SUBDIR)
.join(id)
.join(OUTPUT_FILE)
.exists(),
"{id} landed no output record"
);
}
}
#[test]
fn a_fan_with_a_failed_prepare_reports_it_per_call_and_routes_nothing() {
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 results = exec.execute_all(
&[ToolCall {
id: "f_nowhere",
name: "teleop",
input: &input,
}],
std::path::Path::new("/nonexistent/steps/agent/001"),
&AtomicBool::new(false),
None,
);
assert_eq!(results.len(), 1);
assert!(
matches!(
results.into_iter().next().unwrap(),
Err(super::super::ExecError::NoWorktree { .. })
),
"an unresolvable caller declines before anything is routed"
);
assert!(host.seen.borrow().is_empty());
}