mod support;

use tail_fin_daemon::handshake::{handshake, verify_compatible};
use tempfile::tempdir;

#[tokio::test]
async fn handshake_reports_version_and_verify_compatible_accepts_it() {
    let dir = tempdir().unwrap();
    let (sock, daemon) = support::spawn_mock_daemon(dir.path(), 300, 900, 3).await;

    let reply = handshake(&sock).await.unwrap();
    assert_eq!(reply.version, env!("CARGO_PKG_VERSION"));
    assert!(verify_compatible(&sock).await.is_ok());

    let _ = night_fury_daemon_core::client::send(
        &sock,
        &night_fury_daemon_core::cli::make_req("daemon.shutdown", None, serde_json::json!({})),
    )
    .await;
    let _ = tokio::time::timeout(std::time::Duration::from_secs(3), daemon).await;
}
