//! Integration test for `--server-command`.
//!
//! Confirms that the override flag accepts a quoted command, splits it via
//! `shell-words`, and prints the override banner before the runner stub.

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

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

#[test]
fn run_with_server_command_prints_override_note_and_exits_zero() {
    // Tempdir keeps the no-config path: the bare default would otherwise
    // resolve the repo's checked-in mcptest.yml (WOR-1350).
    let dir = tempfile::tempdir().unwrap();
    mcptest()
        .current_dir(dir.path())
        .args(["run", "--server-command", "./demo arg1 arg2"])
        .assert()
        .success()
        .stdout(predicate::str::contains(
            "Server-target override applied: --server-command",
        ))
        .stdout(predicate::str::contains("no config at"));
}

#[test]
fn malformed_server_command_quoting_fails() {
    let dir = tempfile::tempdir().unwrap();
    mcptest()
        .current_dir(dir.path())
        .args(["run", "--server-command", "'unbalanced"])
        .assert()
        .failure()
        .stderr(predicate::str::contains("failed to parse --server-command"));
}
