76 lines
2.2 KiB
Python
76 lines
2.2 KiB
Python
from __future__ import annotations
|
|
|
|
import pytest
|
|
from pydantic import ValidationError
|
|
|
|
from app.core.config import Settings
|
|
|
|
|
|
def _settings(**overrides: object) -> Settings:
|
|
return Settings(_env_file=None, **overrides)
|
|
|
|
|
|
def test_guest_access_is_opt_in_by_default() -> None:
|
|
settings = _settings()
|
|
assert settings.guest_access_enabled is False
|
|
|
|
|
|
def test_yolo_validation_scope_is_enforced_by_default() -> None:
|
|
settings = _settings()
|
|
assert settings.yolo_enforce_validation_scope is True
|
|
|
|
|
|
def test_production_yolo_rejects_disabled_validation_scope() -> None:
|
|
with pytest.raises(ValidationError, match="YOLO_ENFORCE_VALIDATION_SCOPE"):
|
|
_settings(
|
|
app_env="production",
|
|
yolo_enabled=True,
|
|
yolo_enforce_validation_scope=False,
|
|
yolo_require_cuda=True,
|
|
yolo_device="cuda:0",
|
|
)
|
|
|
|
|
|
def test_production_yolo_can_start_without_scope_evidence() -> None:
|
|
settings = _settings(
|
|
app_env="production",
|
|
yolo_enabled=True,
|
|
yolo_require_cuda=True,
|
|
yolo_device="cuda:0",
|
|
)
|
|
assert settings.yolo_enforce_validation_scope is True
|
|
assert settings.yolo_validation_scope_manifest_path is None
|
|
assert settings.yolo_validation_scope_manifest_sha256 is None
|
|
|
|
|
|
def test_production_yolo_requires_cuda() -> None:
|
|
with pytest.raises(ValidationError, match="YOLO_REQUIRE_CUDA"):
|
|
_settings(
|
|
app_env="production",
|
|
yolo_enabled=True,
|
|
yolo_require_cuda=False,
|
|
yolo_device="cuda:0",
|
|
)
|
|
|
|
|
|
def test_production_yolo_requires_cuda_device() -> None:
|
|
with pytest.raises(ValidationError, match="YOLO_DEVICE"):
|
|
_settings(
|
|
app_env="production",
|
|
yolo_enabled=True,
|
|
yolo_require_cuda=True,
|
|
yolo_device="cpu",
|
|
)
|
|
|
|
|
|
def test_production_yolo_accepts_checksum_bound_cuda_scope() -> None:
|
|
settings = _settings(
|
|
app_env="production",
|
|
yolo_enabled=True,
|
|
yolo_validation_scope_manifest_path="/app/storage/model-scope.json",
|
|
yolo_validation_scope_manifest_sha256="a" * 64,
|
|
yolo_require_cuda=True,
|
|
yolo_device="cuda:0",
|
|
)
|
|
assert settings.yolo_enforce_validation_scope is True
|