"""Tests for mcts pentest orchestration."""

from __future__ import annotations

from mcts.core.config import ScanConfig
from mcts.pentest import run_pentest


def test_pentest_runs_static_phases_on_vulnerable_server() -> None:
    report = run_pentest(
        ScanConfig(target="examples/vulnerable-mcp-server/server.py"),
        run_fuzz=False,
    )
    assert report.verdict in {"critical", "high", "medium"}
    assert any(phase.name == "static_recon" and phase.status == "complete" for phase in report.phases)
    assert any(phase.name == "attack_chains" for phase in report.phases)
    assert report.top_findings
    assert report.recommendations


def test_pentest_skips_fuzz_without_live() -> None:
    report = run_pentest(
        ScanConfig(target="examples/baseline-mcp-server/server.py"),
        run_fuzz=True,
    )
    fuzz_phase = next(phase for phase in report.phases if phase.name == "protocol_fuzz")
    assert fuzz_phase.status == "skipped"


def test_pentest_skips_attack_chains_without_tools() -> None:
    """Prompt-only servers have no tool surface — attack_chains should be skipped."""
    report = run_pentest(
        ScanConfig(target="examples/prompt-only-server/server.py"),
        run_fuzz=False,
    )
    chains_phase = next(phase for phase in report.phases if phase.name == "attack_chains")
    assert report.pentest_limits.tools_discovered == 0
    assert chains_phase.status == "skipped"
    assert "reason" in chains_phase.details
    assert report.pentest_limits.attack_chains_available is False
    assert report.pentest_limits.coverage == "static-only"


def test_pentest_completes_attack_chains_with_tools() -> None:
    report = run_pentest(
        ScanConfig(target="examples/vulnerable-mcp-server/server.py"),
        run_fuzz=False,
    )
    chains_phase = next(phase for phase in report.phases if phase.name == "attack_chains")
    assert chains_phase.status == "complete"
    assert report.pentest_limits.tools_discovered > 0
    assert report.pentest_limits.attack_chains_available is True
    assert report.pentest_limits.coverage == "full"
