2026-01-29 17:02:09 +08:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
from pytest import MonkeyPatch
|
|
|
|
|
|
2026-03-06 17:55:01 +08:00
|
|
|
from core.config.settings import PROJECT_ROOT, Settings
|
2026-01-29 17:02:09 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_runtime_settings_defaults() -> None:
|
|
|
|
|
settings = Settings()
|
|
|
|
|
|
|
|
|
|
assert settings.runtime.log_json is True
|
|
|
|
|
assert settings.runtime.log_rotation == "time"
|
|
|
|
|
assert settings.runtime.log_rotation_when == "midnight"
|
|
|
|
|
assert settings.runtime.log_rotation_interval == 1
|
|
|
|
|
assert settings.runtime.log_rotation_backup_count == 14
|
|
|
|
|
assert settings.runtime.log_rotation_max_bytes == 10_000_000
|
|
|
|
|
assert settings.runtime.log_dir == "logs"
|
|
|
|
|
assert settings.runtime.log_error_dir == "logs/errors"
|
|
|
|
|
assert settings.runtime.log_file_name == "app.log"
|
2026-02-25 10:39:47 +08:00
|
|
|
assert settings.runtime.log_error_file_name == "app.error.log"
|
2026-01-29 17:02:09 +08:00
|
|
|
assert "password" in settings.runtime.log_sensitive_fields
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_runtime_settings_env_override(monkeypatch: MonkeyPatch) -> None:
|
|
|
|
|
monkeypatch.setenv("SOCIAL_RUNTIME__LOG_DIR", "var/logs")
|
|
|
|
|
monkeypatch.setenv("SOCIAL_RUNTIME__LOG_ERROR_DIR", "var/logs/errors")
|
2026-02-25 10:32:19 +08:00
|
|
|
monkeypatch.setenv("SOCIAL_RUNTIME__LOG_FILE_NAME", "custom.log")
|
|
|
|
|
monkeypatch.setenv("SOCIAL_RUNTIME__LOG_ERROR_FILE_NAME", "custom-error.log")
|
2026-01-29 17:02:09 +08:00
|
|
|
monkeypatch.setenv("SOCIAL_RUNTIME__LOG_ROTATION", "size")
|
|
|
|
|
monkeypatch.setenv("SOCIAL_RUNTIME__LOG_ROTATION_MAX_BYTES", "2048")
|
|
|
|
|
|
|
|
|
|
settings = Settings()
|
|
|
|
|
|
2026-02-25 10:32:19 +08:00
|
|
|
assert settings.runtime.log_dir == "logs"
|
|
|
|
|
assert settings.runtime.log_error_dir == "logs/errors"
|
2026-02-25 10:39:47 +08:00
|
|
|
assert settings.runtime.log_file_name == "custom.log"
|
|
|
|
|
assert settings.runtime.log_error_file_name == "custom-error.log"
|
2026-01-29 17:02:09 +08:00
|
|
|
assert settings.runtime.log_rotation == "size"
|
|
|
|
|
assert settings.runtime.log_rotation_max_bytes == 2048
|
2026-02-25 10:39:47 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_runtime_settings_default_file_names_follow_service_name(
|
|
|
|
|
monkeypatch: MonkeyPatch,
|
|
|
|
|
) -> None:
|
|
|
|
|
monkeypatch.delenv("SOCIAL_RUNTIME__LOG_FILE_NAME", raising=False)
|
|
|
|
|
monkeypatch.delenv("SOCIAL_RUNTIME__LOG_ERROR_FILE_NAME", raising=False)
|
|
|
|
|
monkeypatch.setenv("SOCIAL_RUNTIME__SERVICE_NAME", "worker-default")
|
|
|
|
|
|
|
|
|
|
settings = Settings()
|
|
|
|
|
|
|
|
|
|
assert settings.runtime.log_dir == "logs"
|
|
|
|
|
assert settings.runtime.log_error_dir == "logs/errors"
|
|
|
|
|
assert settings.runtime.log_file_name == "worker-default.log"
|
|
|
|
|
assert settings.runtime.log_error_file_name == "worker-default.error.log"
|
2026-03-06 17:55:01 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_project_root_points_to_repo_root() -> None:
|
|
|
|
|
assert (PROJECT_ROOT / "backend").is_dir()
|
|
|
|
|
assert (PROJECT_ROOT / "infra").is_dir()
|
|
|
|
|
assert (PROJECT_ROOT / "pyproject.toml").is_file()
|