use super::{assert_prefixed, noop_editor, with_fx};
use crate::cmd::{dispatch, prompt};
use crate::workspace::fixture;
#[test]
fn prompt_declines_a_cwd_that_names_nothing_in_its_own_voice() {
let (_h, ws) = fixture::workspace();
let (r, ..) = with_fx("lernie", b"", &noop_editor, |fx| {
prompt::run(
prompt::Args {
repo: ws.clone(),
message: "hi".into(),
from: None,
config: None,
name: None,
pin: vec![],
cwd: Some("/no/such/place/at/all".into()),
},
fx,
)
});
let err = r.unwrap_err();
assert!(err.to_string().contains("no such directory"), "{err}");
assert_prefixed(err, "prompt");
let count = std::fs::read_dir(ws.join(crate::workspace::AGENTS_DIR))
.map(|d| d.count())
.unwrap_or(0);
assert_eq!(count, 0, "a refused --cwd left agent debris");
}
#[test]
fn dispatch_declines_a_cwd_that_is_not_a_directory_in_its_own_voice() {
let (_h, ws) = fixture::workspace();
fixture::spawn_root(&ws, "20260101-p1");
let file = ws.join("not-a-dir");
std::fs::write(&file, b"x").unwrap();
let (r, ..) = with_fx("lernie", b"", &noop_editor, |fx| {
dispatch::run(
dispatch::Args {
role: "worker".into(),
repo: ws.clone(),
branch: "20260101-p1".into(),
goal: Some("go".into()),
from: None,
name: None,
pin: vec![],
cwd: Some(file.clone()),
},
fx,
)
});
let err = r.unwrap_err();
assert!(err.to_string().contains("is not a directory"), "{err}");
assert_prefixed(err, "dispatch worker");
let count = std::fs::read_dir(ws.join(crate::workspace::AGENTS_DIR))
.unwrap()
.count();
assert_eq!(count, 1, "a refused --cwd left a child behind");
}