#!/usr/bin/env python3
"""Verify the MVP 30-minute critical log soak QA gate is covered."""

from pathlib import Path


ROOT = Path(__file__).resolve().parents[1]
ROADMAP = ROOT / "AGRARIAN_DEVELOPMENT_ROADMAP.md"
QA_DOC = ROOT / "Docs" / "QA" / "MvpQaGates.md"
MVP_DEF = ROOT / "Docs" / "SixMonthMvpDefinition.md"
SCANNER = ROOT / "Scripts" / "scan_critical_log_spam.py"
VISUAL_QA = ROOT / "Scripts" / "RunWindowsInvestorVisualQACheck.bat"
SERVER_GATE = ROOT / "Scripts" / "verify_server_launch_gate.py"
TWO_CLIENT_GATE = ROOT / "Scripts" / "verify_two_client_connection_gate.py"

REQUIRED = {
    QA_DOC: [
        "## Thirty-Minute Critical Log Soak",
        "at least 30 minutes",
        "Scripts/scan_critical_log_spam.py",
        "fatal/crash/assert/ensure/critical-error",
        "client and server relevant",
    ],
    MVP_DEF: [
        "no critical crash blocks the first 30 minutes of testing",
    ],
    SCANNER: [
        "CRITICAL_PATTERNS",
        "ALLOWLIST_PATTERNS",
        "Ensure condition failed",
        "Unhandled Exception",
        "Access violation",
        "no critical log spam detected",
    ],
    VISUAL_QA: [
        "visual-qa-summary.txt",
        "Saved\\VisualQA\\InvestorDemo",
    ],
    SERVER_GATE: [
        "agrarian-game-server.service",
        "7777/udp",
    ],
    TWO_CLIENT_GATE: [
        "Two-Client Connection",
        "play.agrariangame.com:7777",
    ],
    ROADMAP: [
        "[x] No critical log spam during 30-minute test.",
    ],
}


def main() -> None:
    missing: list[str] = []
    for path, snippets in REQUIRED.items():
        text = path.read_text(encoding="utf-8")
        for snippet in snippets:
            if snippet not in text:
                missing.append(f"{path.relative_to(ROOT)} missing {snippet!r}")
    if missing:
        raise SystemExit("FAILED: " + "; ".join(missing))
    print("OK: 30-minute critical log soak gate is documented and backed by a log scanner.")


if __name__ == "__main__":
    main()
