"""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)