Files
vscode-workbench/PLANNING/tasks/S-01-DSP测试基建.md
T

68 lines
3.6 KiB
Markdown
Raw 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.
# S-01 · DSP 测试基建 + 缺陷清扫
| 字段 | 值 |
|---|---|
| 项目 | DSP · `Desktop/dsp/dsp`(backend + web + android) |
| 优先级 | P0 · M2 |
| 建议模型 | deepseek-v4.1-flash(主)/ qwen3.8-flash(用例设计复核) |
| 依赖 | 无 |
| 预估 | 2.5 天 |
## 一、背景(为什么做)
**修正侦察结论**:DSP 并非零测试——实测已有 `backend/tests/` 1421 行(test_ranking 434 / test_regressions 346 / test_new_modules 314 / test_smoke 212 / test_ws_chat 65)+ `web/e2e/` 253 行(smoke.mjs / feed-tabs.mjs)+ 完整 conftest.py(隔离库 + 迁移清空策略)。
**真正的问题**:测试散在 pytest 与 Node e2e 两套体系里,**没有统一入口、没有通过率看板、没有双模式交叉验证**(ASGI vs 真实 HTTP),且 12 个 app 中 moderation/catalog 等域覆盖不明。对标 EnglishDrill 的 84/84 双模式 E2E 报告体系(`run_e2e.py` + `report.json` + 分组通过率),DSP 缺的是**统一化与可汇报**,不是从零建。
## 二、目标(交付物)
1. **统一 E2E 入口**(参照 `english-drill/tests/e2e/` 设计,适配 DSP 栈):
- `tests/e2e/run_e2e.py`:整合现有 pytest 域 + 新增 HTTP 域
- 双模式:进程内 ASGI(默认)+ 真实 HTTP(`--http` 交叉验证)
- `report.json` + 分组通过率产出(对标 ED 的报告格式)
- 隔离库沿用现有 conftest 策略(**先读 50 行 conftest.py 理解现有迁移/flush/缓存清理逻辑,不许重复造**)
2. **覆盖补全**:先盘点现有 1421 行测试覆盖了哪些域,**只补缺口**——重点:moderation(审核)、catalog/creator、通知(notifications)、访客(visitors)、搜索边界。目标:统一入口下 ≥60 有效用例(现有可直接复用不重写)。
3. **缺陷清扫**:统一跑一遍,跑出的 5xx/数据不一致 → 修复 + 回归用例。三大反模式静态自查(ED 教训):
- 外部 id 未归一化就进 ORM(`int()` 裸调用)
- 统计口径不一致(软删过滤缺失)
- 类型混淆(list/dict/1e999 直塞字段操作)
4. 原有测试**零删除**,双模式统一入口下全绿。
## 三、执行步骤
```text
1. 先跑现有两套测试(pytest -q + npm run e2e)记录基线通过数
2. 读 backend/conftest.py 与 tests/*.py 盘点覆盖域;读 web/e2e/*.mjs 看前端 e2e 模式
3. 建 tests/e2e/run_e2e.py 统一入口(复用现有 conftest 隔离策略 + 现有用例)
4. 补缺口域用例(moderation/catalog/notifications/visitors/搜索边界)
5. 双模式跑通 → 修缺陷(一缺陷一用例)→ 产出 report.json + 修复清单
```
## 四、验收标准
- [ ] 统一入口 `python tests/e2e/run_e2e.py` ≥60 用例全绿;`--http` 模式同样全绿
- [ ] **原有 1421 行测试 + web e2e 零删除零跳过**(基线通过数不减)
- [ ] 覆盖缺口域(moderation/catalog/notifications/visitors)明确盘点结论
- [ ] `report.json` 分组通过率产出(对标 ED 格式)
- [ ] 每个修复的缺陷都有对应回归用例(清单对照)
- [ ] 隔离库确认(原始开发库零改动)
- [ ] 发现的 5xx 全部归零(或明确记录未修复项的阻塞原因)
## 五、验收命令(参考)
```bash
cd backend && python tests/e2e/run_e2e.py
python tests/e2e/run_e2e.py --http
cat tests/e2e/report.json
```
## 六、边界(不许做)
- 不为过测试改业务断言(修产品代码,不改测试标准)
- 不动 Android 端(本轮 Web/后端)
- 不迁移技术栈
## 七、交接
写 `PROGRESS_S-01.md`(含通过率、缺陷修复对照表、双模式输出)。