//! Integration tests proving `klieo-a2a` passes the documented A2A v1.0
//! conformance suite.

use async_trait::async_trait;
use klieo_a2a::conformance::{run_conformance_suite, CaseStatus, ConformanceReport};
use klieo_a2a::{A2aHandler, EchoHandler};

/// Case ids whose `Skip` status is expected today (capability not yet
/// implemented). Update this list whenever a Skip becomes a Pass.
const EXPECTED_SKIPS: &[&str] = &["C-08"];

#[tokio::test]
async fn a2a_v1_conformance_against_echo_handler() {
    let report = run_conformance_suite(&EchoHandler::default()).await;
    assert_eq!(
        report.failed, 0,
        "expected zero failed cases; got:\n{report}"
    );
    for c in &report.cases {
        match &c.status {
            CaseStatus::Fail => panic!("case {} ({}) failed: {:?}", c.id, c.clause, c.detail),
            CaseStatus::Skip(_) => assert!(
                EXPECTED_SKIPS.contains(&c.id),
                "unexpected skip on case {} ({}); add to EXPECTED_SKIPS or implement the case",
                c.id,
                c.clause
            ),
            CaseStatus::Pass => {}
            _ => panic!("unknown CaseStatus variant on case {}", c.id),
        }
    }
}

/// Demonstrates the suite is generic over any `A2aHandler` — important
/// for downstream agents that want to assert conformance against their
/// own handler impl in their own test suite.
#[tokio::test]
async fn conformance_suite_compiles_against_any_handler() {
    struct NoopHandler;
    #[async_trait]
    impl A2aHandler for NoopHandler {}

    // Force the generic to instantiate against NoopHandler. We don't
    // assert anything about its score — only that the suite is callable.
    let _: ConformanceReport = run_conformance_suite(&NoopHandler).await;
}
