use callisto_cli::cli::{Cli, Command, OutputFormat};
use std::path::PathBuf;
#[test]
fn test_cli_parse_global_args() {
use clap::Parser;
let cli = Cli::parse_from(["callisto", "--format", "json", "--cwd", "/tmp", "status"]);
assert_eq!(cli.global.format, OutputFormat::Json);
assert_eq!(cli.global.cwd, PathBuf::from("/tmp"));
assert!(matches!(cli.command, Command::Status(_)));
}
#[test]
fn test_cli_parse_add_command() {
use clap::Parser;
let cli = Cli::parse_from([
"callisto",
"add",
"--package",
"foo:minor",
"--summary",
"Added feature foo",
]);
if let Command::Add(args) = cli.command {
assert_eq!(args.packages, vec!["foo:minor"]);
assert_eq!(args.summary, Some("Added feature foo".to_string()));
} else {
panic!("Expected Add command");
}
}
#[test]
fn test_add_non_interactive_via_pipe() {
use std::process::{Command, Stdio};
use tempfile::TempDir;
let tmp = TempDir::new().unwrap();
let root = tmp.path();
drop(
Command::new("git")
.args(["init", "-q"])
.current_dir(root)
.output(),
);
std::fs::write(
root.join("Cargo.toml"),
"[workspace]\nmembers = []\nresolver = \"2\"\n",
)
.unwrap();
std::fs::write(root.join("callisto.toml"), "[workspace]\n").unwrap();
let bin = env!("CARGO_BIN_EXE_callisto");
let stdin_file = std::fs::File::open(std::path::Path::new("/dev/null")).unwrap();
let output = Command::new(bin)
.args(["--cwd", &root.to_string_lossy(), "add"])
.stdin(stdin_file)
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.output()
.expect("failed to spawn callisto binary");
assert!(
!output.status.success(),
"callisto add with piped stdin and no --package flags should fail with NotATty"
);
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(
stderr.contains("stdin is not a terminal") || stderr.contains("not_a_tty"),
"stderr should mention the TTY check; got: {stderr}"
);
}