//! Integration tests for the result-cache flags on `mcptest run`.
//!
//! Run-path result caching is opt-in via `--cache` (WOR-1398). The
//! `--no-cache*` flags refine an opted-in run; passed without `--cache`
//! they have no effect, and `mcptest run` says so. `--cache-filter`
//! selection is still deferred, so it keeps its own "not yet honored"
//! warning. These tests pin those messages and confirm they stay out of
//! the way under `--quiet` or when no cache flag is set.

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

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

/// Fresh tempdir per test so the bare default config resolution never
/// picks up the repo's checked-in mcptest.yml (WOR-1350).
fn empty_dir() -> tempfile::TempDir {
    tempfile::tempdir().expect("tempdir")
}

#[test]
fn no_cache_without_opt_in_warns_it_has_no_effect() {
    let dir = empty_dir();
    mcptest()
        .current_dir(dir.path())
        .args(["run", "--no-cache"])
        .assert()
        .success()
        .stderr(predicate::str::contains("have no effect without"));
}

#[test]
fn no_cache_warning_is_absent_once_caching_is_opted_in() {
    let dir = empty_dir();
    mcptest()
        .current_dir(dir.path())
        .args(["run", "--cache", "--no-cache-read"])
        .assert()
        .success()
        .stderr(predicate::str::contains("have no effect without").not());
}

#[test]
fn cache_filter_warns_that_selection_is_not_yet_honored() {
    let dir = empty_dir();
    mcptest()
        .current_dir(dir.path())
        .args(["run", "--cache-filter", "NEW"])
        .assert()
        .success()
        .stderr(predicate::str::contains("not yet honored on the run path"));
}

#[test]
fn no_cache_warning_is_suppressed_under_quiet() {
    let dir = empty_dir();
    mcptest()
        .current_dir(dir.path())
        .args(["--quiet", "run", "--no-cache"])
        .assert()
        .success()
        .stderr(predicate::str::contains("have no effect").not());
}

#[test]
fn warning_absent_when_no_cache_flag_is_set() {
    let dir = empty_dir();
    mcptest()
        .current_dir(dir.path())
        .args(["run"])
        .assert()
        .success()
        .stderr(predicate::str::contains("have no effect").not())
        .stderr(predicate::str::contains("not yet honored").not());
}
