//! Integration tests for `mcptest drift check`.
//!
//! Drives the binary over the shipped baseline/drifted state files (offline,
//! no server) asserting the classified-diff output and the gate's exit code:
//! a renamed param and an empty-result regression must fail the run.

use assert_cmd::Command;
use predicates::prelude::*;

fn mcptest() -> Command {
    Command::cargo_bin("mcptest").expect("binary builds")
}

fn workspace_root() -> std::path::PathBuf {
    std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
        .ancestors()
        .nth(2)
        .expect("crates/mcptest is two levels below the workspace root")
        .to_path_buf()
}

#[test]
fn a_renamed_param_and_empty_result_fail_the_gate() {
    mcptest()
        .current_dir(workspace_root())
        .args([
            "drift",
            "check",
            "--baseline",
            "examples/drift-watch/baseline.json",
            "--current",
            "examples/drift-watch/current-drifted.json",
        ])
        .assert()
        .failure()
        .stdout(predicate::str::contains("schema drift:"))
        .stdout(predicate::str::contains("BREAKING"))
        .stdout(predicate::str::contains("behavioral drift"));
}

#[test]
fn an_unchanged_capture_passes() {
    mcptest()
        .current_dir(workspace_root())
        .args([
            "drift",
            "check",
            "--baseline",
            "examples/drift-watch/baseline.json",
            "--current",
            "examples/drift-watch/baseline.json",
        ])
        .assert()
        .success()
        .stdout(predicate::str::contains("clean"));
}

#[test]
fn json_output_carries_the_report_shape() {
    mcptest()
        .current_dir(workspace_root())
        .args([
            "drift",
            "check",
            "--baseline",
            "examples/drift-watch/baseline.json",
            "--current",
            "examples/drift-watch/current-drifted.json",
            "--json",
        ])
        .assert()
        .failure()
        .stdout(predicate::str::contains("\"schema_changes\""))
        .stdout(predicate::str::contains("\"behavioral_changes\""));
}

#[test]
fn passing_both_current_and_spec_is_an_invocation_error() {
    mcptest()
        .current_dir(workspace_root())
        .args([
            "drift",
            "check",
            "--baseline",
            "examples/drift-watch/baseline.json",
            "--current",
            "examples/drift-watch/baseline.json",
            "--spec",
            "examples/drift-watch/spec.yml",
        ])
        .assert()
        .code(2)
        .stderr(predicate::str::contains("exactly one of"));
}
