from __future__ import annotations

from pathlib import Path


ROOT = Path(__file__).resolve().parents[3]
SCRIPT = ROOT / "scripts" / "reboot-recovery" / "post-start-quick-check.sh"


def test_post_start_self_checks_can_run_locally_on_110() -> None:
    text = SCRIPT.read_text(encoding="utf-8")

    assert "is_local_target()" in text
    assert 'ips="$(local_ip_list)"' in text
    assert 'local_ip_list | grep' not in text
    assert 'bash -lc "$command"' in text
    assert 'SSH_COMMAND_TIMEOUT_SECONDS="${SSH_COMMAND_TIMEOUT_SECONDS:-25}"' in text
    assert "printf -v quoted_command '%q' \"$command\"" in text
    assert '-o ConnectionAttempts=1' in text
    assert '-o ServerAliveInterval=5' in text
    assert '-o ServerAliveCountMax=1' in text
    assert '-o NumberOfPasswordPrompts=0' in text
    assert "timeout ${SSH_COMMAND_TIMEOUT_SECONDS}s bash -lc ${quoted_command}" in text


def test_runner_pressure_is_capacity_evidence_after_routes_recover() -> None:
    text = SCRIPT.read_text(encoding="utf-8")

    assert "service_route_recovered()" in text
    assert "capacity_or_runner_issue()" in text
    assert "cold-start non-route blockers retained as capacity/freshness evidence" in text
    assert 'capacity_or_runner_issue "110 host pressure gate is blocking"' in text
