from __future__ import annotations

from pathlib import Path


ROOT = Path(__file__).resolve().parents[3]
SCRIPT = ROOT / "scripts" / "reboot-recovery" / "signoz-188-upstream-bridge.sh"


def test_signoz_bridge_is_user_level_reversible_and_bounded() -> None:
    text = SCRIPT.read_text(encoding="utf-8")
    executable_text = "\n".join(
        line for line in text.splitlines() if not line.lstrip().startswith("#")
    )

    assert "TARGET_HOST=\"${TARGET_HOST:-ollama@192.168.0.188}\"" in text
    assert "LISTEN_HOST=\"${LISTEN_HOST:-127.0.0.1}\"" in text
    assert "LISTEN_PORT=\"${LISTEN_PORT:-3301}\"" in text
    assert "UPSTREAM_HOST=\"${UPSTREAM_HOST:-192.168.0.110}\"" in text
    assert "UPSTREAM_PORT=\"${UPSTREAM_PORT:-8080}\"" in text
    assert "-o ConnectionAttempts=1" in text
    assert "-o ServerAliveInterval=5" in text
    assert "-o ServerAliveCountMax=1" in text
    assert "socat" in text
    assert "@reboot" in text
    assert "--rollback" in text
    assert "SIGNOZ_BRIDGE_STATUS" in text
    assert "systemctl " not in executable_text
    assert "sudo " not in executable_text
    assert "docker " not in executable_text
    assert "nginx -s reload" not in executable_text
