Files
Neo 6f8f12314f feat: 累积功能变更 — 聊天集成、租户管理、小程序更新、ETL 增强、迁移脚本
包含多个会话的累积代码变更:
- backend: AI 聊天服务、触发器调度、认证增强、WebSocket、调度器最小间隔
- admin-web: ETL 状态页、任务管理、调度配置、登录优化
- miniprogram: 看板页面、聊天集成、UI 组件、导航更新
- etl: DWS 新任务(finance_area_daily/board_cache)、连接器增强
- tenant-admin: 项目初始化
- db: 19 个迁移脚本(etl_feiqiu 11 + zqyy_app 8)
- packages/shared: 枚举和工具函数更新
- tools: 数据库工具、报表生成、健康检查
- docs: PRD/架构/部署/合约文档更新

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-06 00:03:48 +08:00

79 lines
3.5 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# P5.1→NS3 缺失项 #8各 App 的单元测试用例设计
## 简要结论
- 状态:✅ 已解决
- 风险等级:🟡 低
- 已建立完整的测试体系覆盖属性测试Hypothesis+ 单元测试 + 集成属性测试,涵盖所有 8 个 AI 应用和 3 个 data_fetcher
## 详细审查
### 审查范围
- `tests/test_ai_apps/` — AI 应用测试目录3 个文件)
- `tests/test_data_fetchers/` — 数据获取器测试目录4 个文件)
- `tests/test_p5_ai_integration_properties.py` — P5 AI 集成属性测试
- `tests/test_rns1_*.py` — RNS1 Chat 模块属性测试8 个文件)
### 发现
#### ✅ 测试覆盖情况
**1. AI 应用属性测试(`tests/test_ai_apps/`**
| 文件 | 覆盖内容 | 测试数量 |
|------|----------|----------|
| `test_app1_props.py` | App1 biz_params 注入不变量、System Prompt Token 预算 | 2 个属性 |
| `test_build_prompt_props.py` | App3/4/5/6/7 的 Prompt 结构验证、错误降级、Token 预算 | 13 个属性 |
| `test_ai_apps_unit.py` | App1 页面上下文集成、App3/5/7 完整流程 | 6 个单元测试 |
**2. 数据获取器测试(`tests/test_data_fetchers/`**
| 文件 | 覆盖内容 | 测试数量 |
|------|----------|----------|
| `test_member_data_props.py` | 消费数据必填字段、正交易过滤、items_sum 口径、排序、备注截断 | 7 个属性 |
| `test_assistant_data_props.py` | 废单排除、排序保持 | 2 个属性 |
| `test_page_context_props.py` | 输出长度约束、全页面类型覆盖、敏感字段检测 | 3 个属性 |
| `test_data_fetchers_unit.py` | 空记录、FDW 超时、会员不存在、助教不存在等边界 | 10 个单元测试 |
**3. P5 集成属性测试(`test_p5_ai_integration_properties.py`**
覆盖 App2-App8 全部 7 个应用的 JSON 输出结构验证Pydantic 模型解析),包括:
- 枚举值合法性App3 的 3 分类、App6/8 的 6 分类)
- 字段非空约束
- App6 score 范围 [1,10] 及越界拒绝
- 每个应用 100 个随机用例
**4. Chat 模块属性测试(`tests/test_rns1_*.py`**
8 个文件覆盖 Chat 模块的排序、持久化、引用卡片、对话复用、SSE、标题生成、性能等属性。
#### 测试方法论
- **属性测试Hypothesis**:使用 `@given` + `@settings(max_examples=100)` 生成随机输入,验证不变量
- **单元测试Mock**Mock 数据获取函数(`AsyncMock`),不连真实数据库
- **边界条件**空记录、FDW 超时、数据获取失败降级、超长文本截断等
### 证据
**测试文件统计**
```
tests/test_ai_apps/ → 3 文件21+ 测试用例
tests/test_data_fetchers/ → 4 文件22+ 测试用例
tests/test_p5_ai_integration_properties.py → 9 个属性测试App2-8 + score 越界)
tests/test_rns1_*.py → 8 文件Chat 模块全覆盖
```
**典型属性测试示例test_build_prompt_props.py**
```python
# Property 14: 错误降级 — App5 数据获取失败不阻断
def test_prop14_app5_error_degradation(fail_assistant, fail_service, fail_member, fail_notes):
# Property 15: Token 预算 — App5 system message 长度 ≤ 8000
def test_prop15_app5_token_budget(records, notes):
```
### 建议
测试体系已较完整,以下为可选增强方向(非必须):
1. App2财务洞察和 App4关系分析`build_prompt` 属性测试可补充(当前仅有 App4 的结构测试,无 App2 的 Prompt 构建测试)
2. 端到端集成测试(`scripts/ops/test_chat_e2e.py` 已存在但为运维脚本,非 pytest 用例)