feat: add optional cover generation toggle

This commit is contained in:
chengma
2026-07-02 15:17:11 +08:00
parent f9c6dd3331
commit 21cd02c167
13 changed files with 348 additions and 48 deletions
+15
View File
@@ -1006,3 +1006,18 @@
- AI事件:`app/ai.py` 的 `_call_with_retry()` 支持 `on_retry` 回调,标题/图片请求失败但仍会重试时上报 `retry` 事件;不改 AI HTTP 协议、DB schema、Excel 或 Shopee/CDP 流程。
- 测试:`tests/test_gui.py` 覆盖双进度条初始状态、用户可读日志、重试日志脱敏和旧日志加载;`tests/test_ai.py` 覆盖标题生成重试事件上报。
- 验证:`python -m py_compile app\ai.py app\gui.py tests\test_ai.py tests\test_gui.py` 通过;`python -m unittest discover -s tests -p "test_ai.py"` 通过(7 tests);`python -m unittest discover -s tests -p "test_gui.py"` 通过(68 tests);`python -m compileall app main.py` 通过;`python -m unittest discover -s tests` 通过(156 tests)。Qt 仍有本机字体目录提示,不影响测试结果。
## 【2026-07-02】T-520 文档启动 · ②AI生成封面可选生成开关
- 背景:②AI生成当前默认标题和图片都生成,图片模型成本明显高于标题;用户只想改标题时也会产生图片生成成本。⑤「允许更新封面」只控制③线上提交阶段,不能替代②生成阶段的成本选择。
- 决策:新增 T-520。②AI生成页增加「生成封面图片(成本较高)」复选框,默认关闭并持久化到 `config.json` 的 `ai.generate_cover`;关闭时只生成标题,标题成功即 `db.set_generated(task_id, new_title, NULL)`,③只更新标题;开启时保持标题后图片两段流程。
- 文档:同步 `docs/02-requirements.md`、`docs/04-architecture.md`、`docs/routes.md`、`docs/api.md`、`docs/06-tasks.md`、`docs/current-state.md`。本轮只更新文档,未改代码。
- 下一步:按 T-520 文档更新 `app/appconfig.py`、`app/ai.py`、`app/gui.py` 和相关单测。
## 【2026-07-02】T-520 完成 · ②AI生成封面可选生成开关
- 配置:`app/appconfig.py` 新增 `ai.generate_cover=false` 默认值;②AI生成页复选框状态会持久化到 `config.json`,设置页保存其他 AI 参数时保留该隐藏成本开关。
- 代码:`app/ai.py` 的 `generate_batch()` 按 `generate_cover` 分支执行;关闭时只生成标题,标题成功即 `db.set_generated(task_id, new_title, None)` 并进入 `generated`,不调用 `gen_cover()`、不渲染封面提示词、不创建新封面文件;开启时保留标题后图片两段流程。
- GUI:`app/gui.py` 在②底部增加「生成封面图片(成本较高)」复选框;开始生成前保存当前开关;标题-only 模式进度显示 `图片0/0`,运行日志写明“本轮仅生成标题,不生成图片”,完成统计使用 `generated_done`,避免只看 `cover_done`。
- 测试:`tests/test_appconfig.py` 覆盖默认关闭;`tests/test_ai.py` 覆盖跳过封面时不调用 `gen_cover` 且任务进入 generated;`tests/test_gui.py` 覆盖开关持久化、Worker 标题-only 日志/运行日志统计,以及旧图片路径显式开启开关。
- 验证:`python -m py_compile app\appconfig.py app\ai.py app\gui.py tests\test_appconfig.py tests\test_ai.py tests\test_gui.py` 通过;`python -m unittest discover -s tests -p "test_appconfig.py"` 通过(7 tests);`python -m unittest discover -s tests -p "test_ai.py"` 通过(8 tests);`python -m unittest discover -s tests -p "test_gui.py"` 通过(70 tests);`python -m compileall app main.py` 通过;`python -m unittest discover -s tests` 通过(159 tests);`git diff --check` 无空白错误,仅 LF/CRLF 提示。Qt 仍有本机字体目录提示,不影响测试结果。