#[cfg(unix)]
use std::os::unix::fs::PermissionsExt;
use std::{env, fs};
use tempfile::tempdir;
use crate::agent::availability::{available_agent_kinds_from_path, executable_name};
use crate::model::agent::AgentKind;
#[test]
fn test_executable_name_matches_agent_cli_names() {
assert_eq!(executable_name(AgentKind::Antigravity), "agy");
assert_eq!(executable_name(AgentKind::Claude), "claude");
assert_eq!(executable_name(AgentKind::Codex), "codex");
assert_eq!(executable_name(AgentKind::Gemini), "gemini");
}
#[test]
fn test_real_agent_availability_probe_filters_missing_executables() {
let temp_directory = tempdir().expect("failed to create temp dir");
let codex_path = temp_directory.path().join("codex");
fs::write(&codex_path, "").expect("failed to create codex executable");
fs::set_permissions(&codex_path, fs::Permissions::from_mode(0o750))
.expect("failed to mark codex executable");
let path_value = env::join_paths([temp_directory.path()]).expect("valid path");
let available_agent_kinds = available_agent_kinds_from_path(Some(path_value.as_os_str()));
assert_eq!(available_agent_kinds, vec![AgentKind::Codex]);
}
#[test]
fn test_real_agent_availability_probe_ignores_non_executable_files() {
let temp_directory = tempdir().expect("failed to create temp dir");
let codex_path = temp_directory.path().join("codex");
fs::write(&codex_path, "").expect("failed to create codex file");
fs::set_permissions(&codex_path, fs::Permissions::from_mode(0o640))
.expect("failed to mark codex non-executable");
let path_value = env::join_paths([temp_directory.path()]).expect("valid path");
let available_agent_kinds = available_agent_kinds_from_path(Some(path_value.as_os_str()));
assert_eq!(
available_agent_kinds,
[] as [crate::model::agent::AgentKind; 0]
);
}