use super::*;
static HEALTH_CACHE_LOCK: tokio::sync::Mutex<()> = tokio::sync::Mutex::const_new(());
#[tokio::test]
async fn check_server_health_returns_false_for_unreachable_server() {
let _guard = HEALTH_CACHE_LOCK.lock().await;
let config = ConnectConfig {
url: "https://127.0.0.1:19999".to_string(), token: "test-token".to_string(),
username: None,
};
let _ = std::fs::remove_file(ConnectConfig::health_cache_path());
let healthy = check_server_health(&config).await;
assert!(!healthy);
}
#[tokio::test]
async fn check_server_health_uses_cache() {
let _guard = HEALTH_CACHE_LOCK.lock().await;
let _ = ConnectConfig::update_health_cache();
let config = ConnectConfig {
url: "https://127.0.0.1:19999".to_string(), token: "test-token".to_string(),
username: None,
};
let healthy = check_server_health(&config).await;
assert!(
healthy,
"should return true from cache even if server is unreachable"
);
let _ = std::fs::remove_file(ConnectConfig::health_cache_path());
}
#[test]
fn matches_filter_single_match() {
let event = serde_json::json!({"type": "SessionEnded", "success": "true"});
assert!(matches_filter(&event, "type=SessionEnded"));
}
#[test]
fn matches_filter_no_match() {
let event = serde_json::json!({"type": "SessionStarted"});
assert!(!matches_filter(&event, "type=SessionEnded"));
}
#[test]
fn matches_filter_multiple_conditions() {
let event = serde_json::json!({"type": "ToolResult", "success": "true"});
assert!(matches_filter(&event, "type=ToolResult,success=true"));
assert!(!matches_filter(&event, "type=ToolResult,success=false"));
}