File size: 2,905 Bytes
f440f03 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | """Tests runtime konfigurācijai produkcijas izvietošanai."""
from __future__ import annotations
import os
import tomllib
from pathlib import Path
from maris_core.runtime import (
configure_huggingface_environment,
is_reload_enabled,
resolve_host,
resolve_port,
)
def test_resolve_port_prefers_platform_port(monkeypatch) -> None:
monkeypatch.delenv("PORT", raising=False)
assert resolve_port() == 8000
monkeypatch.setenv("PORT", "10000")
assert resolve_port() == 10000
def test_resolve_port_rejects_invalid_value(monkeypatch) -> None:
monkeypatch.setenv("PORT", "invalid")
try:
resolve_port()
except ValueError as exc:
assert str(exc) == "Invalid PORT value: 'invalid'"
else:
raise AssertionError("resolve_port() should reject invalid PORT values")
def test_resolve_host_defaults_to_ipv4_locally(monkeypatch) -> None:
monkeypatch.delenv("HOST", raising=False)
monkeypatch.delenv("RAILWAY_PRIVATE_DOMAIN", raising=False)
monkeypatch.delenv("RAILWAY_PUBLIC_DOMAIN", raising=False)
monkeypatch.delenv("RAILWAY_ENVIRONMENT_ID", raising=False)
assert resolve_host() == "0.0.0.0"
def test_resolve_host_prefers_explicit_host_env(monkeypatch) -> None:
monkeypatch.setenv("HOST", "127.0.0.1")
monkeypatch.setenv("RAILWAY_PRIVATE_DOMAIN", "maris-core-python.railway.internal")
assert resolve_host() == "127.0.0.1"
def test_resolve_host_keeps_ipv4_binding_on_railway(monkeypatch) -> None:
monkeypatch.delenv("HOST", raising=False)
monkeypatch.setenv("RAILWAY_PRIVATE_DOMAIN", "maris-core-python.railway.internal")
assert resolve_host() == "0.0.0.0"
def test_reload_disabled_by_default(monkeypatch) -> None:
monkeypatch.delenv("MARIS_RELOAD", raising=False)
assert is_reload_enabled() is False
def test_reload_can_be_enabled_from_env(monkeypatch) -> None:
monkeypatch.setenv("MARIS_RELOAD", "true")
assert is_reload_enabled() is True
def test_configure_huggingface_environment_sets_standard_runtime_aliases(monkeypatch) -> None:
monkeypatch.setenv("MARIS_REPO_TOKEN", "hf-secret")
monkeypatch.delenv("HF_TOKEN", raising=False)
monkeypatch.delenv("HUGGING_FACE_HUB_TOKEN", raising=False)
monkeypatch.delenv("HUGGINGFACEHUB_API_TOKEN", raising=False)
monkeypatch.delenv("HF_HUB_DISABLE_XET", raising=False)
configure_huggingface_environment()
assert os.environ["HF_TOKEN"] == "hf-secret"
assert os.environ["HUGGING_FACE_HUB_TOKEN"] == "hf-secret"
assert os.environ["HUGGINGFACEHUB_API_TOKEN"] == "hf-secret"
assert os.environ["HF_HUB_DISABLE_XET"] == "1"
def test_railway_healthcheck_uses_health_endpoint() -> None:
railway_config = tomllib.loads(
(Path(__file__).resolve().parents[1] / "railway.toml").read_text(encoding="utf-8")
)
assert railway_config["deploy"]["healthcheckPath"] == "/health"
|