Files
life-echo/api/tests/test_settings_allowlist.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

56 lines
1.2 KiB
Python

"""Settings 字段数量守卫:防止 env 反弹为巨型配置。"""
from app.core.config import Settings
ALLOWLIST_MAX_FIELDS = 22
EXPECTED_PREFIXES = (
"database_",
"redis_",
"celery_",
"app_",
"secret_",
"deepseek_",
"zhipu_",
"tencent_secret_",
"wechat_pay_",
"alipay_",
"liblib_",
"internal_eval_",
)
def test_settings_field_count_within_allowlist() -> None:
assert len(Settings.model_fields) <= ALLOWLIST_MAX_FIELDS
def test_settings_has_only_secrets_and_bootstrap_fields() -> None:
for name in Settings.model_fields:
assert name.startswith(EXPECTED_PREFIXES), (
f"unexpected Settings field {name!r}; "
"non-secret deploy/product config belongs in config/*.toml"
)
def test_settings_has_no_product_tuning_field_names() -> None:
blocked = (
"chat_",
"memory_",
"eval_",
"story_",
"memoir_",
"agent_log_",
"enable_",
"otel_",
"log_",
"access_",
"refresh_",
"mock_",
"tencent_sms_",
"tencent_cos_",
"api_cors_",
"alembic_",
)
for name in Settings.model_fields:
assert not any(name.startswith(p) for p in blocked)