//! Integration test for the composition `eval:` block.
//!
//! Walks a composition YAML through `suite::parse` and asserts the
//! resolved composition carries the same typed `EvalMetric` vector
//! the agent loader produces, so a future judged-output pipeline
//! can reuse the rubric / mcp_task_completion / mcp_use /
//! argument_correctness / plan_quality engine without re-parsing.

use mcptest_core::suite::{parse, EvalMetric};

#[test]
fn composition_eval_block_parses_through_the_loader() {
    let yaml = r##"
servers:
  m:
    command: ["echo"]
compositions:
  - name: judged
    nodes:
      - id: search
        tool: t
        mock: { result: { hits: [] } }
    eval:
      mcp_task_completion: { threshold: 0.8 }
      mcp_use: { threshold: 0.7, strict: false }
"##;
    let value: serde_yaml::Value = serde_yaml::from_str(yaml).unwrap();
    let suite = parse(&value).expect("composition with eval loads");
    assert_eq!(suite.compositions.len(), 1);
    let c = &suite.compositions[0];
    assert_eq!(c.eval.len(), 2);
    let mut saw_task_completion = false;
    let mut saw_mcp_use = false;
    for metric in &c.eval {
        match metric {
            EvalMetric::TaskCompletion { threshold, .. } => {
                saw_task_completion = true;
                assert!((threshold - 0.8).abs() < 1e-9);
            }
            EvalMetric::McpUse { threshold, .. } => {
                saw_mcp_use = true;
                assert!((threshold - 0.7).abs() < 1e-9);
            }
            _ => {}
        }
    }
    assert!(saw_task_completion, "missing TaskCompletion");
    assert!(saw_mcp_use, "missing McpUse");
}

#[test]
fn composition_without_eval_block_has_empty_metrics() {
    let yaml = r##"
servers:
  m:
    command: ["echo"]
compositions:
  - name: bare
    nodes:
      - id: a
        tool: t
        mock: { result: 1 }
"##;
    let value: serde_yaml::Value = serde_yaml::from_str(yaml).unwrap();
    let suite = parse(&value).unwrap();
    assert!(suite.compositions[0].eval.is_empty());
}
