use super::exit_launch::{ProbingLauncher, deposit_files, plain_run};
use super::fixtures::*;
use std::io;
use std::sync::atomic::AtomicBool;
#[test]
fn stopped_exit_never_launches() {
let repo = scaffold_repo(VALID_PER_REPO_PROVIDERS_YAML, Some("body"));
let harness = scaffold_harness_root();
let adapter = StubAdapter::scripted([StubAdapter::reply_ok(&version_line())]);
let git = StubGit::ok();
let (clock, id) = (FixedClock::default(), FixedIdGen);
let (sleeper, tool_executor) = (StubSleeper::default(), StubToolExecutor::ok());
let stop = AtomicBool::new(true);
let launcher = ProbingLauncher::default();
let mut deps = valid_deps(
&adapter,
&sleeper,
&git,
&clock,
&id,
&tool_executor,
harness.path(),
);
deps.stop = &stop;
deps.launcher = &launcher;
plain_run(repo.path(), &deps).unwrap();
assert!(
launcher.invocations.borrow().is_empty(),
"stopped must not launch"
);
}
#[test]
fn budget_exhausted_exit_never_launches() {
const EXHAUSTING: &str = "events: {}\nbudgets:\n max_total_tokens: 8\n";
let repo = scaffold_repo_with_workflow(VALID_PER_REPO_PROVIDERS_YAML, EXHAUSTING, Some("body"));
let harness = scaffold_harness_root();
let adapter = StubAdapter::scripted([
StubAdapter::reply_ok(&version_line()),
StubAdapter::reply_ok(&stream_of(
brazen::FinishReason::ToolUse,
&[Block::ToolUse {
id: "toolu_01",
name: "bash",
input: serde_json::json!({"cmd": "ls"}),
}],
)),
]);
let git = StubGit::ok();
let (clock, id) = (FixedClock::default(), FixedIdGen);
let (sleeper, tool_executor) = (StubSleeper::default(), StubToolExecutor::ok());
let launcher = ProbingLauncher::default();
let mut deps = valid_deps(
&adapter,
&sleeper,
&git,
&clock,
&id,
&tool_executor,
harness.path(),
);
deps.launcher = &launcher;
plain_run(repo.path(), &deps).unwrap();
assert!(
deposit_files(repo.path())
.iter()
.any(|b| b.contains("epitaph: budget-exhausted")),
"the exhaustion deposit landed"
);
assert!(
launcher.invocations.borrow().is_empty(),
"exhausted must not launch"
);
}
#[test]
fn an_errored_executor_never_launches() {
let repo = scaffold_repo(VALID_PER_REPO_PROVIDERS_YAML, Some("body"));
let harness = scaffold_harness_root();
let adapter = StubAdapter::scripted([
StubAdapter::reply_ok(&version_line()),
StubAdapter::reply_err(io::ErrorKind::ConnectionRefused, "no provider"),
]);
let git = StubGit::ok();
let (clock, id) = (FixedClock::default(), FixedIdGen);
let (sleeper, tool_executor) = (StubSleeper::default(), StubToolExecutor::ok());
let launcher = ProbingLauncher::default();
let mut deps = valid_deps(
&adapter,
&sleeper,
&git,
&clock,
&id,
&tool_executor,
harness.path(),
);
deps.launcher = &launcher;
plain_run(repo.path(), &deps).unwrap_err();
assert!(
launcher.invocations.borrow().is_empty(),
"an error must not launch"
);
}