from pathlib import Path


ROOT = Path(__file__).resolve().parents[1]


def test_ollama111_proxy_default_allowlist_stays_production_only():
    proxy_source = (ROOT / "scripts/ops/ollama111_allow_proxy.py").read_text()
    installer_source = (ROOT / "scripts/ops/install_ollama111_allow_proxy.sh").read_text()

    assert "192.168.0.188/32" in proxy_source
    assert "192.168.0.188/32" in installer_source
    assert "192.168.0.111/32" in proxy_source
    assert "192.168.0.111/32" in installer_source
    assert "192.168.0.80/32" not in proxy_source
    assert "192.168.0.80/32" not in installer_source


def test_ollama111_proxy_logs_to_stdout_for_launchagent_collection():
    proxy_source = (ROOT / "scripts/ops/ollama111_allow_proxy.py").read_text()

    assert "import sys" in proxy_source
    assert "stream=sys.stdout" in proxy_source


def test_ollama111_proxy_reject_logs_are_deduplicated():
    proxy_source = (ROOT / "scripts/ops/ollama111_allow_proxy.py").read_text()

    assert "OLLAMA111_PROXY_REJECT_LOG_DEDUP_SEC" in proxy_source
    assert "_LAST_REJECT_LOG" in proxy_source
    assert "now - last_log >= REJECT_LOG_DEDUP_SEC" in proxy_source
