use super::*;
use std::os::unix::ffi::OsStringExt as _;
fn args(parts: &[&str]) -> Vec<String> {
parts.iter().map(|s| (*s).to_string()).collect()
}
#[test]
fn parse_accepts_a_verb_and_maps_help_and_errors_to_exit_codes() {
let cli = parse(&args(&["new", "/tmp/ws"])).unwrap();
assert!(matches!(cli.command, cmd::Command::New(_)));
assert_eq!(parse(&args(&["--help"])).unwrap_err(), 0);
assert!(matches!(
parse(&args(&["invoke"])).unwrap().command,
cmd::Command::Invoke(_)
));
assert_eq!(parse(&args(&["no-such-verb"])).unwrap_err(), 2);
assert_eq!(parse(&[]).unwrap_err(), 2);
}
#[test]
fn edit_with_maps_the_editor_exit_to_the_edit_result() {
let dir = tempfile::TempDir::new().unwrap();
let ok = edit_with("test -d", dir.path());
assert!(ok.is_ok());
let err = edit_with("false", dir.path()).unwrap_err();
assert!(err.to_string().contains("editor exited"));
}
#[test]
fn conclude_performs_success_and_prints_the_uniform_failure() {
assert_eq!(conclude(Ok(Outcome::Quiet)), 0);
assert_eq!(conclude(Err(cmd::Error::new("prompt", "boom"))), 1);
}
#[test]
fn perform_maps_each_outcome_to_its_exit() {
assert_eq!(perform(Outcome::Line("a-branch".to_owned())), 0);
assert_eq!(perform(Outcome::Quiet), 0);
assert_eq!(perform(Outcome::Code(7)), 7);
let mut cmd = crate::git_env::command(Path::new("/nonexistent/yog-successor"));
cmd.arg(std::ffi::OsString::from_vec(b"a\0b".to_vec()));
assert_eq!(perform(Outcome::Exec(cmd)), 1);
}
#[test]
fn the_minting_verb_and_the_naming_verb_declare_one_set() {
use ::litany::cmd::ToolInjection as _;
let root = tempfile::TempDir::new().expect("tmp");
let workspace = root.path().join("home");
crate::test_support::workspace::seed_workspace_config(
&workspace,
&[(
"providers.yaml",
"roles:\n worker:\n provider: p\n model: m\n tools: [clients]\n",
)],
);
crate::test_support::workspace::seed_agent_branch(&workspace, "dulcet-mongoose", None);
crate::tool_host::loaded::add(
root.path(),
"home",
"dulcet-mongoose",
&[crate::tool_host::loaded::Entry {
client: "laptop".to_owned(),
tool: crate::registry::tools::Tool {
name: "Bash".to_owned(),
description: "run a command".to_owned(),
input_schema: serde_json::json!({"type": "object"}),
subject_cwd: false,
},
}],
)
.expect("seed the loaded set");
let injection = crate::tool_host::Injection::new(
root.path().to_path_buf(),
root.path().join("no-front-door"),
crate::tool_host::ask::Budget::default(),
crate::tool_host::remote::patience(),
std::sync::Arc::new(SystemClock),
);
let names: Vec<String> = injection
.tools(&workspace, "dulcet-mongoose")
.into_iter()
.map(|t| t.name)
.collect();
assert_eq!(names, vec!["clients".to_owned(), "laptop_Bash".to_owned()]);
}