use super::fixtures::*;
use super::stubs::AdapterReply;
use crate::prompt::Error;
use crate::prompt::inbox::{inbox_dir, try_acquire};
const CONV_ID: &str = "ct-1-deadbeef";
fn version_only_adapter() -> StubAdapter {
StubAdapter::scripted([AdapterReply::Ok(version_line())])
}
#[test]
fn driver_that_loses_the_acquire_is_a_clean_noop() {
let repo = scaffold_repo(VALID_PER_REPO_PROVIDERS_YAML, Some("body"));
let _held = try_acquire(&inbox_dir(repo.path(), CONV_ID))
.unwrap()
.expect("fresh inbox is acquirable");
let adapter = version_only_adapter();
let git = StubGit::ok();
let branch = run_with_stubs(repo.path(), "hello", &adapter, &git).unwrap();
assert_eq!(branch, CONV_ID);
assert!(
git.runs.borrow().iter().all(|(_, a)| a[0] != "worktree"),
"no git branch work on the no-op path"
);
assert!(
!worktree_path(repo.path()).exists(),
"no worktree materialized"
);
}
#[test]
fn acquire_failure_surfaces_executorlock_error() {
let repo = scaffold_repo(VALID_PER_REPO_PROVIDERS_YAML, Some("body"));
std::fs::write(repo.path().join("inbox"), b"not a dir").unwrap();
let adapter = version_only_adapter();
let git = StubGit::ok();
let err = run_with_stubs(repo.path(), "hello", &adapter, &git).unwrap_err();
assert!(matches!(err, Error::ExecutorLock { .. }), "{err}");
}
#[test]
fn fresh_root_prompt_wins_its_lease_and_drives() {
let repo = scaffold_repo(VALID_PER_REPO_PROVIDERS_YAML, Some("body"));
let adapter = StubAdapter::happy(&happy_response_bytes());
let git = StubGit::ok();
let branch = run_with_stubs(repo.path(), "hello", &adapter, &git).unwrap();
assert_eq!(branch, CONV_ID);
assert!(!git.runs.borrow().is_empty(), "the branch was driven");
}