//! Integration tests for `mcptest concurrency` (concurrent-session correctness).

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

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

/// The mcptest binary path, used to spawn a stable stdio server under test.
const BIN: &str = env!("CARGO_BIN_EXE_mcptest");

#[test]
fn concurrent_sessions_against_a_stable_server_pass() {
    // Each session spawns its own well-behaved `mcptest mcp-server` process,
    // so every session sees an identical, isolated catalog.
    let server = format!("{BIN} mcp-server");
    mcptest()
        .arg("concurrency")
        .arg(&server)
        .arg("--sessions")
        .arg("3")
        .assert()
        .success()
        .stdout(predicate::str::contains("PASS"));
}

#[test]
fn json_output_reports_the_session_count() {
    let server = format!("{BIN} mcp-server");
    mcptest()
        .arg("concurrency")
        .arg(&server)
        .arg("--sessions")
        .arg("2")
        .arg("--json")
        .assert()
        .success()
        .stdout(predicate::str::contains("\"sessions\": 2"));
}

#[test]
fn an_unreachable_server_exits_two() {
    mcptest()
        .arg("concurrency")
        .arg("definitely-not-a-real-binary-xyz")
        .assert()
        .code(2);
}
