//! End-to-end test for `mcptest run --header-env NAME=VAR`.
//!
//! Confirms the env-backed header form parses and the override banner names
//! the `--header-env` flag separately from `--header`, so an operator
//! scanning the banner can tell which form was used.

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

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

#[test]
fn run_accepts_header_env_flag() {
    let dir = tempdir().unwrap();
    mcptest()
        .current_dir(dir.path())
        .args(["--header-env", "X-API=MY_API_KEY", "run"])
        .assert()
        .success()
        .stdout(predicate::str::contains(
            "Server-target override applied: --header-env",
        ))
        .stdout(predicate::str::contains("no config at"));
}

#[test]
fn run_rejects_header_env_with_missing_var_name() {
    let dir = tempdir().unwrap();
    mcptest()
        .current_dir(dir.path())
        .args(["--header-env", "X-API=", "run"])
        .assert()
        .failure()
        .stderr(predicate::str::contains("env var name is empty"));
}

#[test]
fn run_accepts_literal_and_env_headers_together() {
    let dir = tempdir().unwrap();
    mcptest()
        .current_dir(dir.path())
        .args([
            "--header",
            "X-Tenant=acme",
            "--header-env",
            "X-API=MY_API_KEY",
            "run",
        ])
        .assert()
        .success()
        .stdout(predicate::str::contains("--header"))
        .stdout(predicate::str::contains("--header-env"));
}
