use assert_cmd::Command;
fn bin() -> Command {
Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap()
}
fn config_dir_in(tmp: &std::path::Path) -> std::path::PathBuf {
tmp.join(".config").join(env!("CARGO_PKG_NAME"))
}
#[test]
fn agent_info_works_with_malformed_config() {
let tmp = tempfile::tempdir().unwrap();
let config_dir = config_dir_in(tmp.path());
std::fs::create_dir_all(&config_dir).unwrap();
std::fs::write(config_dir.join("config.toml"), "{{invalid toml").unwrap();
bin()
.env("HOME", tmp.path())
.arg("agent-info")
.assert()
.code(0);
}
#[test]
fn config_path_works_with_malformed_config() {
let tmp = tempfile::tempdir().unwrap();
let config_dir = config_dir_in(tmp.path());
std::fs::create_dir_all(&config_dir).unwrap();
std::fs::write(config_dir.join("config.toml"), "{{invalid toml").unwrap();
bin()
.env("HOME", tmp.path())
.args(["config", "path"])
.assert()
.code(0);
}
#[test]
fn config_show_fails_with_malformed_config() {
let tmp = tempfile::tempdir().unwrap();
let config_dir = config_dir_in(tmp.path());
std::fs::create_dir_all(&config_dir).unwrap();
std::fs::write(config_dir.join("config.toml"), "{{invalid toml").unwrap();
bin()
.env("HOME", tmp.path())
.args(["config", "show"])
.assert()
.code(2);
}
#[test]
fn invalid_format_rejected() {
bin()
.args(["speak", "World", "--format", "nonsense"])
.assert()
.code(3);
}
#[test]
fn script_works_with_temp_home() {
let tmp = tempfile::tempdir().unwrap();
bin()
.env("HOME", tmp.path())
.args(["script", "World"])
.assert()
.code(0);
}