from pathlib import Path
import sys


REPO_ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(REPO_ROOT / "telegram"))

import agent_healthcheck  # noqa: E402


def test_unit_name_uses_teleo_agent_template():
    assert agent_healthcheck.unit_name("leo") == "teleo-agent@leo.service"
    assert agent_healthcheck.unit_name("leo-wallet-test") == "teleo-agent@leo-wallet-test.service"


def test_should_restart_from_transcript_read_only_fault():
    log_text = "OSError: [Errno 30] Read-only file system: '/opt/teleo-eval/transcripts/leo'"

    assert agent_healthcheck.should_restart_from_logs(log_text)


def test_should_restart_from_double_quoted_transcript_read_only_fault():
    log_text = 'OSError: [Errno 30] Read-only file system: "/opt/teleo-eval/transcripts/leo"'

    assert agent_healthcheck.should_restart_from_logs(log_text)


def test_should_not_restart_from_generic_application_log():
    log_text = "INFO:root:Application started\nINFO:root:Bot running as @livingipleobot"

    assert not agent_healthcheck.should_restart_from_logs(log_text)


def test_default_agents_are_live_leo_and_wallet_test():
    assert agent_healthcheck.DEFAULT_AGENTS == ("leo", "leo-wallet-test")
