//! Integration test for capability-only suites reaching the lanes (WOR-1490).
//!
//! A suite that declares only a capability block (here `compliance:`) with no
//! `tools:` or `agents:` used to short-circuit with "no tests" before the
//! post-drive lanes ran. The run now falls through to the lanes when the suite
//! declares one, so a single `mcptest run` audits a lane-only suite. Offline
//! and key-free: the server is the built-in mock.

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

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

fn mcptest_bin() -> &'static str {
    env!("CARGO_BIN_EXE_mcptest")
}

/// Write a clean mock manifest exposing one `echo` tool, the server the
/// compliance checks probe.
fn write_manifest(dir: &std::path::Path) -> std::path::PathBuf {
    let manifest = r#"mock_server:
  name: echo
  tools:
    - name: echo
      description: "Echo a fixed line."
      input_schema:
        type: object
      response:
        isError: false
        content:
          - type: text
            text: "hello"
"#;
    let path = dir.join("echo.yaml");
    std::fs::write(&path, manifest).expect("write mock manifest");
    path
}

/// A `compliance:`-only suite has no tool or agent tests, so selection is empty.
/// The run must still reach the compliance lane, score the check, and exit on
/// the lane verdict (here the initialize check passes, so the run exits 0 and
/// the `compliance/` row appears).
#[test]
fn a_compliance_only_suite_runs_the_lane_with_no_tool_tests() {
    let dir = tempfile::tempdir().unwrap();
    let manifest = write_manifest(dir.path());
    let suite = format!(
        r#"servers:
  mock:
    command: ['{bin}', 'mock', '--tools-from', '{manifest}']
compliance:
  - name: PROTO-002 initialize returns capabilities
    server: mock
    check: initialize
    expect:
      - target: result.capabilities
        matcher:
          schema: {{ type: object }}
"#,
        bin = mcptest_bin(),
        manifest = manifest.display(),
    );
    let path = dir.path().join("suite.yml");
    std::fs::write(&path, suite).expect("write suite");
    mcptest()
        .args(["run", "--config", path.to_str().unwrap()])
        .assert()
        .success()
        .stdout(predicate::str::contains("compliance/PROTO-002"));
}
