"""Unit tests for scripts/prod_probe.py helpers."""

from __future__ import annotations

import json
import sys
from pathlib import Path

import pytest

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

from prod_probe import assert_json, build_config  # noqa: E402


def test_assert_json_ok():
    data = assert_json(200, json.dumps({"a": 1}), "/x")
    assert data["a"] == 1


def test_assert_json_fail_status():
    with pytest.raises(RuntimeError, match="HTTP 500"):
        assert_json(500, "err", "/x")


def test_build_config_defaults(monkeypatch):
    monkeypatch.delenv("NEXUS_PROBE_BASE", raising=False)
    monkeypatch.delenv("NEXUS_SSH", raising=False)
    monkeypatch.setattr(
        "prod_probe._load_secrets_env",
        lambda: None,
    )
    cfg = build_config()
    assert cfg.base_external == "https://api.synaglobal.vip"
    assert cfg.ssh_host == "nexus"
    assert cfg.origin_url == "http://127.0.0.1:8600"
