refactor(api): TOML 配置 SSOT、统一错误契约、Auth/事务加固与可观测性 (#33)
配置 SSOT(TOML + .env) 统一错误契约 Auth 与事务边界 Redis / Celery 可靠性:业务 Redis(DB/0)与 Celery broker/backend(DB/1)显式拆分;连接池、sync client 可观测性(OpenTelemetry + LGTM)
This commit is contained in:
@@ -19,10 +19,23 @@ alwaysApply: false
|
||||
- 用 `httpx.AsyncClient` + `ASGITransport` 进行异步 HTTP 测试。
|
||||
- `api/tests/conftest.py` 和 `api/tests/factories.py` 只提供通用基础设施,不要把具体业务测试硬编码进去。
|
||||
|
||||
## HTTP 错误契约
|
||||
|
||||
- 失败响应断言 **`error_code` + `message`**(及可选 `request_id`),不要断言 FastAPI 旧格式 `{ detail }`。
|
||||
- OpenAPI / router 级 smoke:参考 `tests/test_http_router_error_contract.py`、`tests/test_openapi_error_response.py`。
|
||||
- Auth / payment / SMS 等 feature 码:断言具体 `error_code`(如 `INVALID_SMS_CODE`、`REFRESH_TOKEN_REUSE`),不只测 status code。
|
||||
|
||||
## 配置 / TOML 测试
|
||||
|
||||
- TOML 加载测试用 `CONFIG_DIR` 指向 fixture 目录,或 `reload_app_config()`;见 `tests/test_app_config_loader.py`。
|
||||
- **不要**用 `os.environ["OTEL_ENABLED"]` 等已迁出 Settings 的 env 键驱动应用行为(运行时已读 TOML)。
|
||||
- 新增 TOML 默认值时,若影响产品行为,更新 `tests/test_default_toml_legacy_parity.py` 或明确 overlay 意图。
|
||||
|
||||
## Test Layering
|
||||
|
||||
- HTTP 场景测试:注册、登录、刷新、登出、受保护资源访问、关键资源 CRUD、重要失败分支。
|
||||
- 纯单元测试:纯函数、规则计算、序列化、适配器错误分支与格式转换。
|
||||
- Service / 事务边界测试:仅当保护明确业务承诺(如 refresh rotation、SMS 回滚、幂等 ingest)且 HTTP 层难以稳定复现时允许;参考 `tests/test_auth_refresh_rotation.py`、`tests/test_db_transactional.py`。
|
||||
- 手工 / E2E:WebSocket 多轮对话、真实短信、Celery + Redis + LLM 编排、支付/对象存储/ASR/图像生成联调。
|
||||
|
||||
## Decision Filter
|
||||
|
||||
Reference in New Issue
Block a user