//! ACP mocker integration tests.
//!
//! These tests use the dirigate to validate ACP protocol flows.
//! Most tests are marked as #[ignore] by default since they require spawning processes.
//!
//! Run with: cargo test --package dirigent_core --test acp_mocker_test -- --ignored

#![cfg(feature = "server")]

mod acp_integration;

use acp_integration::*;

#[tokio::test]
async fn test_mocker_utilities_exist() {
    // Just verify the utilities compile and work
    let config = MockerConfig::default();
    assert!(config.to_args().is_empty());
}

#[tokio::test]
async fn test_golden_transcripts_available() {
    // Verify golden transcripts are available
    assert!(load_golden_transcript("initialize").is_some());
    assert!(load_golden_transcript("new_session").is_some());
    assert!(load_golden_transcript("prompt").is_some());
    assert!(load_golden_transcript("tool_call_read").is_some());
    assert!(load_golden_transcript("cancel").is_some());
}

// ============================================================================
// Mocker Spawning Tests (Ignored by default)
// ============================================================================

#[tokio::test]
#[ignore]
async fn test_spawn_stdio_mocker() {
    let mocker = MockerProcess::spawn_stdio().await;
    assert!(mocker.is_ok(), "Failed to spawn stdio mocker: {:?}", mocker.err());

    if let Ok(mocker) = mocker {
        assert!(matches!(mocker.mode(), MockerMode::Stdio));
        assert_eq!(mocker.http_url(), None);
        mocker.kill().await.expect("Failed to kill mocker");
    }
}

#[tokio::test]
#[ignore]
async fn test_spawn_http_mocker() {
    let port = 18888; // Use non-standard port for testing
    let mocker = MockerProcess::spawn_http(port).await;
    assert!(mocker.is_ok(), "Failed to spawn HTTP mocker: {:?}", mocker.err());

    if let Ok(mocker) = mocker {
        assert!(matches!(mocker.mode(), MockerMode::Http { .. }));
        assert_eq!(
            mocker.http_url(),
            Some(format!("http://localhost:{}", port))
        );
        mocker.kill().await.expect("Failed to kill mocker");
    }
}

#[tokio::test]
#[ignore]
async fn test_spawn_mocker_with_config() {
    let config = MockerConfig::with_preset("basic");
    let args_vec = config.to_args();
    let args: Vec<&str> = args_vec.iter().map(|s| s.as_str()).collect();

    let mocker = MockerProcess::spawn_stdio_with_args(&args).await;
    assert!(mocker.is_ok(), "Failed to spawn mocker with config: {:?}", mocker.err());

    if let Ok(mocker) = mocker {
        mocker.kill().await.expect("Failed to kill mocker");
    }
}

// ============================================================================
// Documentation for Future Tests
// ============================================================================

// TODO: TEST-01 - Protocol validation test suite (stdio mode)
// - initialize → response with capabilities
// - session/new → sessionId
// - session/prompt → streaming updates
// - Validate all protocol flows against mocker

// TODO: TEST-02 - Protocol validation test suite (HTTP mode)
// - Same tests as TEST-01 but using HTTP transport
// - SSE stream validation

// TODO: TEST-03 - Session update rendering tests
// - Parse and validate all session update types
// - Verify ToolKind, ToolCallLocation, diff content

// TODO: TEST-04 - Permission prompt flow tests
// - Test all permission outcomes (allow_once, allow_always, reject_once, reject_always, cancel)
// - Decision cache persistence and TTL
