from __future__ import annotations

from tools.accept_torch_candidate import _decision


def _report(*, validation_passed: bool = True, trades: int = 30, total: float = 10.0) -> dict:
    return {
        "recommended": {"score": 0.5},
        "full_replay": {
            "trades": trades,
            "avg_net_percent": 0.4,
            "total_net_percent": total,
            "profit_factor": 2.0,
            "max_drawdown_percent": 1.0,
        },
        "walk_forward": {"summary": {"trades": trades, "avg_net_percent": 0.3}},
        "validation": {"passed": validation_passed, "status": "pass" if validation_passed else "fail"},
    }


def test_guard_rejects_candidate_without_honest_validation() -> None:
    decision = _decision(
        _report(),
        _report(validation_passed=False),
        min_trades=8,
        min_profit_factor=1.05,
        min_avg_net_percent=0.0,
        max_score_regression=0.05,
    )

    assert decision == {"accepted": False, "reason": "candidate_failed_honest_validation"}


def test_guard_accepts_candidate_that_passes_honest_validation() -> None:
    decision = _decision(
        _report(total=9.0),
        _report(total=12.0),
        min_trades=8,
        min_profit_factor=1.05,
        min_avg_net_percent=0.0,
        max_score_regression=0.05,
    )

    assert decision == {"accepted": True, "reason": "candidate_passed_guard"}
