use super::fixtures::*;
use crate::prompt::{Error, run};
use brazen::FinishReason;
use serde_json::json;
#[test]
fn loop_terminates_on_non_tool_use_finish() {
let repo = scaffold_repo(VALID_PER_REPO_PROVIDERS_YAML, Some("body"));
let harness = scaffold_harness_root();
let r1 = stream_of(FinishReason::Length, &[Block::Text("done")]);
let adapter = StubAdapter::happy(&r1);
let git = StubGit::ok();
let (clock, id) = (FixedClock::default(), FixedIdGen);
let (sleeper, tool_executor) = (StubSleeper::default(), StubToolExecutor::ok());
run(
repo.path(),
"hi",
&valid_deps(
&adapter,
&sleeper,
&git,
&clock,
&id,
&tool_executor,
harness.path(),
),
)
.unwrap();
assert!(tool_executor.invocations.borrow().is_empty());
}
#[test]
fn loop_surfaces_tool_executor_failure_as_tool_exec_error() {
let repo = scaffold_repo(VALID_PER_REPO_PROVIDERS_YAML, Some("body"));
let harness = scaffold_harness_root();
let r1 = stream_of(
FinishReason::ToolUse,
&[Block::ToolUse {
id: "toolu_01",
name: "bash",
input: json!({"cmd": "ls"}),
}],
);
let adapter = StubAdapter::happy(&r1);
let git = StubGit::ok();
let (clock, id) = (FixedClock::default(), FixedIdGen);
let (sleeper, tool_executor) = (StubSleeper::default(), StubToolExecutor::failing_on("bash"));
let err = run(
repo.path(),
"hi",
&valid_deps(
&adapter,
&sleeper,
&git,
&clock,
&id,
&tool_executor,
harness.path(),
),
)
.unwrap_err();
match err {
Error::ToolExec { tool, .. } => assert_eq!(tool, "bash"),
other => panic!("expected ToolExec, got {other:?}"),
}
}