Files
life-echo/api/tests/test_app_config_loader.py
Sully 53e0065e3e refactor(api): TOML 配置 SSOT、统一错误契约、Auth/事务加固与可观测性 (#33)
配置 SSOT(TOML + .env)
统一错误契约
Auth 与事务边界
Redis / Celery 可靠性:业务 Redis(DB/0)与 Celery broker/backend(DB/1)显式拆分;连接池、sync client
可观测性(OpenTelemetry + LGTM)
2026-05-22 13:44:50 +08:00

34 lines
1017 B
Python

"""TOML configuration loader tests."""
from pathlib import Path
import pytest
from app.core.app_config_loader import load_app_config
FIXTURES = Path(__file__).resolve().parent / "fixtures" / "config"
def test_load_default_only() -> None:
cfg = load_app_config("development", config_dir=FIXTURES / "minimal")
assert cfg.chat.interview_persona == "default"
assert cfg.deploy.enable_tts is True
def test_staging_overlay_merges_chat_section() -> None:
cfg = load_app_config("staging", config_dir=FIXTURES / "merge")
assert cfg.chat.interview_persona == "staging_persona"
assert cfg.chat.interview_temperature == 0.93
assert cfg.deploy.mock_sms_login_enabled is True
def test_unknown_top_level_key_rejected(tmp_path: Path) -> None:
bad = tmp_path / "default.toml"
bad.write_text(
'[deploy]\nenable_tts = true\n\n[typo_section]\nfoo = 1\n',
encoding="utf-8",
)
with pytest.raises(Exception):
load_app_config("development", config_dir=tmp_path)