feat: include failed step in task errors

This commit is contained in:
chengma
2026-07-08 11:08:01 +08:00
parent ffbad8e64d
commit 75d545f182
7 changed files with 212 additions and 23 deletions
+7 -2
View File
@@ -3,7 +3,7 @@ id: T-552
title: 任务失败原因带上失败步骤(①②③ 阶段/状态列可见)
phase: 7
deps: [T-207, T-523]
status: TODO
status: DONE
created: 2026-07-08
---
@@ -43,4 +43,9 @@ created: 2026-07-08
## 执行记录
(做完在此记录:改了哪些文件、跑的验证命令与结果、决策)
- 2026-07-08:完成 T-552。
- 代码:`app/db.py` 新增 `FAILURE_STEP_LABELS`、`failure_step_label()`、`format_failure_error()`;`mark_failed()` 与 `set_applied()` 增加可选 `step` 参数,带 step 时把 `last_error` 统一保存为「<中文步骤>失败:<原因>」,无 step 时保持旧行为,已带步骤前缀时不重复添加。
- 代码:①`CollectWorker` 采集失败时把当前 step 传给 `mark_failed`,并立即向 GUI 发出带步骤前缀的 `last_error`;②`app/ai.py` 的生成失败写库传入当前 title/cover step;③`ApplyWorker` 更新失败和异常失败传入当前 step 给 `set_applied`,默认归因为 `apply_task`,真实编辑器步骤仍由 `on_step` 覆盖。
- 展示:①②③ 表格模型原本 tooltip 已读取 `last_error`,因此失败行悬停可直接看到失败步骤与原因;未新增列、不改 DB schema、不改 run_log_events。
- 测试:`tests/test_db.py` 覆盖 `mark_failed` 带 step 前缀、未知 step 兜底、重复前缀不叠加、无 step 保持原样,以及 `set_applied` 更新失败 step 前缀;`tests/test_gui.py` 覆盖①②③失败行 tooltip 显示步骤与原因,并更新③ worker 失败原因断言。
- 验证:`py -3.10 -m unittest discover -s tests -p "test_db.py"` 通过(9 tests);`py -3.10 -m unittest discover -s tests -p "test_gui.py"` 通过(104 tests);`py -3.10 -m unittest discover -s tests -p "test_ai.py"` 通过(40 tests);`python -m ruff check app tests main.py` 通过;`python -m ruff check scripts\gen_task_board.py tests\test_task_board.py` 通过;`py -3.10 -m compileall app main.py` 通过;`py -3.10 -m py_compile scripts/gen_task_board.py` 通过;`git diff --check` 通过;`py -3.10 -m unittest discover -s tests` 通过(257 tests)。