//! Dispatch coverage for subcommands that lacked a direct integration
//! test: `compliance`, `prompt`, `cache`, `mcp-server`, `exec`.
//!
//! Each test proves the binary routes the subcommand to its handler
//! rather than rejecting it as unknown. `--help` is the universal probe:
//! clap only emits subcommand-specific usage (and exits `0`) once the
//! command name has matched a `Command` variant, so a passing `--help`
//! assertion is proof of dispatch without spawning a server or blocking
//! on stdin.

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

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

#[test]
fn compliance_help_dispatches() {
    mcptest()
        .args(["compliance", "--help"])
        .assert()
        .success()
        .stdout(predicate::str::contains("Usage: mcptest compliance"));
}

#[test]
fn prompt_help_dispatches() {
    mcptest()
        .args(["prompt", "--help"])
        .assert()
        .success()
        .stdout(predicate::str::contains("Usage: mcptest prompt"));
}

#[test]
fn prompt_with_no_args_prints_grounding_prompt() {
    // The minimal valid invocation: `prompt` needs no flags and never
    // touches a server, so a bare run proves the handler executes (not
    // just that clap parsed the name).
    mcptest()
        .arg("prompt")
        .assert()
        .success()
        .stdout(predicate::str::contains("mcptest"));
}

#[test]
fn cache_help_dispatches() {
    mcptest()
        .args(["cache", "--help"])
        .assert()
        .success()
        .stdout(predicate::str::contains("Usage: mcptest cache"));
}

#[test]
fn mcp_server_help_dispatches() {
    // Bare `mcp-server` would block on the stdio JSON-RPC loop, so probe
    // dispatch with `--help`, which clap handles before the handler runs.
    mcptest()
        .args(["mcp-server", "--help"])
        .assert()
        .success()
        .stdout(predicate::str::contains("Usage: mcptest mcp-server"));
}

#[test]
fn exec_help_dispatches() {
    mcptest()
        .args(["exec", "--help"])
        .assert()
        .success()
        .stdout(predicate::str::contains("Usage: mcptest exec"));
}
