from __future__ import annotations

from pathlib import Path

import pytest

from sage.edge.core import normalize_mount_path, probe_payload


def test_core_normalize_mount_path() -> None:
    assert normalize_mount_path(None) == "/"
    assert normalize_mount_path("") == "/"
    assert normalize_mount_path("/") == "/"
    assert normalize_mount_path("/llm") == "/llm"
    assert normalize_mount_path("/llm/") == "/llm"

    with pytest.raises(ValueError, match="must start with"):
        normalize_mount_path("llm")


def test_core_probe_payload() -> None:
    payload = probe_payload("ok", llm_mounted=True, llm_prefix="/llm")
    assert payload["status"] == "ok"
    assert payload["service"] == "SAGE Edge"
    assert payload["llm_mounted"] is True
    assert payload["llm_prefix"] == "/llm"


def test_core_module_has_no_web_dependencies() -> None:
    source = (Path(__file__).resolve().parents[1] / "src" / "sage" / "edge" / "core.py").read_text(
        encoding="utf-8"
    )
    assert "fastapi" not in source
    assert "uvicorn" not in source


def test_root_package_does_not_export_web_factory() -> None:
    import sage.edge as edge

    assert "__version__" in edge.__all__
    assert "create_app" not in edge.__all__
