docs: sync cmhub download diagnostics and progress

04-architecture/api 记录下载层最多 3 次安全重试(复用同一 image_url、
不重发生图)、下载超 20 秒告警、CMSHOPEE_DEBUG_CMHUB_IMAGE_URL 调试开关;
current-state/progress 同步。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
chengma
2026-07-08 00:41:44 +08:00
co-authored by Claude Opus 4.8
parent 979112966e
commit 30497bdda7
4 changed files with 33 additions and 17 deletions
+27 -13
View File
@@ -1060,33 +1060,33 @@
- 代码:`app/editor.py` 在 `open_product()` 导航商品详情页前后安装 toast 观察器,缓存最近 toast 的文本、HTML、URL、可见状态和时间;`_wait_ready()` 超时或检测到失效 toast 时,将商品失效/商品不存在/无权限类文案上浮为 `商品失效:<原始toast>`,其他打开失败仍保持普通失败原因。
- GUI:①导入采集任务表只在 `last_error` 明确包含商品失效类错误时把“阶段”列显示为“商品失效”;底层 DB 不新增 stage 枚举,仍保持 `stage=imported/status=failed`,其他超时、网络、登录、风控类错误仍显示“失败”。
- 测试:`tests/test_editor_login.py` 覆盖隐藏 toast 捕获、失效 toast 错误上浮和 open_product 安装观察器;`tests/test_gui.py` 覆盖只有明确失效错误才显示“商品失效”。
- 验证:已通过相关测试;全量验证见本轮最终结果。
- 验证:已通过相关测试;全量验证见本轮最终结果。
## 【2026-07-02】文档补充 · T-404b 商品失效失败 tab 清理
- 问题:商品 ID 失效时,`_wait_ready()` 在 `open_product()` 内部抛出 `商品失效:...`,上层 `collect()` / `apply_task()` 尚未拿到 `cdp`,因此上层 finally 无法关闭本轮自动新建的商品 tab。
- 方案:补充 T-404b 边界。`open_product()` 如果在返回 `cdp` 前失败,要自行清理:本轮自动新建 tab 先断开 CDP 再调用 `close_tab(target_id, host=...)`;复用用户原本打开的 tab 只断开 CDP,不关闭页面。进入编辑页后的更新失败仍按原设计保留现场。
- 文档:同步 `docs/02-requirements.md`、`docs/04-architecture.md`、`docs/routes.md`、`docs/api.md`、`docs/06-tasks.md`、`docs/current-state.md`。
- 验证:文档-only 更新,未运行单元测试。
- 验证:文档-only 更新,未运行单元测试。
## 【2026-07-02】T-404b 补丁完成 · 商品失效失败 tab 自动清理
- 代码:`app/editor.py` 新增 `open_product()` 内部失败清理。若 `_wait_ready()` 因商品失效 toast 或其他打开页异常在返回 `cdp` 前抛错,会先断开 CDP;本轮自动新建的商品 tab 继续调用 `close_tab(target_id, host=...)` 关闭,复用用户已有 tab 不关闭。
- 边界:只处理 `open_product()` 内部打开失败导致的残留 tab;进入编辑页后的更新失败仍按原设计保留现场,成功提交后的关闭仍受 ⑤ `close_success_tab` 控制。
- 测试:`tests/test_editor_login.py` 增加自动新建 tab 商品失效时关闭、复用 tab 商品失效时不关闭的覆盖。
- 验证:`python -m unittest discover -s tests -p "test_editor_login.py"` 通过(36 tests)。
- 验证:`python -m unittest discover -s tests -p "test_editor_login.py"` 通过(36 tests)。
## 【2026-07-02】文档 · T-103b 登录检测补充识别 Shopee accounts 登录页
- 需求:打开商品详情页或卖家中心时,未登录账号可能跳转到 `https://accounts.shopee.tw/seller/login...`。④「检测登录」以及①/③执行前账号预检应明确把该 URL 判为未登录,不能依赖模糊规则或误判为普通无 Cookie。
- 方案:新增 T-103b。登录页 URL marker 显式加入 `accounts.shopee.tw/seller/login` / Shopee accounts 域名下 `/seller/login`;`login_status()` 返回 `logged_in=false/reason=LOGIN_PAGE/url=<实际URL>`;④状态列显示“未登录”,①/③预检继续阻断并引导去④。
- 边界:不自动登录、不填密码、不绕过验证码;只增强登录页识别和测试覆盖,不改 CDP 商品页、上传、提交逻辑。
- 文档:同步 `docs/02-requirements.md`、`docs/04-architecture.md`、`docs/routes.md`、`docs/api.md`、`docs/06-tasks.md`、`docs/current-state.md`;当前下一个可领取任务改为 T-103b。
- 验证:文档-only 更新,未运行单元测试。
- 验证:文档-only 更新,未运行单元测试。
## 【2026-07-02】T-103b 完成 · 登录检测补充识别 Shopee accounts 登录页
- 代码:`app/editor.py` 的 `LOGIN_PATH_MARKERS` 显式加入 `accounts.shopee.tw/seller/login`,`_is_login_url()` 增加 `accounts.shopee.*` 域名且路径以 `/seller/login` 开头的判断。
- 行为:`login_status()` 遇到 `https://accounts.shopee.tw/seller/login...` 立即返回 `logged_in=false/reason=LOGIN_PAGE/url=<实际URL>`,④状态列会显示未登录,①/③预检继续阻断并引导去④。
- 边界:不自动登录、不填密码、不绕过验证码;未改商品页、上传、提交逻辑。
- 测试:`tests/test_editor_login.py` 增加真实 accounts 登录 URL 覆盖。
- 验证:`python -m unittest discover -s tests -p "test_editor_login.py"` 通过(37 tests)。
- 验证:`python -m unittest discover -s tests -p "test_editor_login.py"` 通过(37 tests)。
## 【2026-07-03】T-524 完成 · PyInstaller 打包为免安装 exe
@@ -1134,7 +1134,7 @@
- 边界:只改②AI生成 UI、worker 事件处理和测试;未改 AI HTTP 协议、DB schema、Excel、Shopee/CDP 流程。
- 文档:`docs/06-tasks.md` 将 T-528 标为 DONE;同步 `docs/current-state.md`,下一个可领取任务回到 T-525 ruff。
- 测试:`python -m unittest discover -s tests -p test_gui.py` 通过(80 tests);`python -m unittest discover -s tests -p test_ai.py` 通过(17 tests);`python -m compileall app main.py` 通过;`python -m unittest discover -s tests` 通过(187 tests);`git diff --check` 通过,仅有本机 LF/CRLF 提示。全量测试仍有本机 PySide6 字体目录提示,不影响结果。
- 下一步:T-525「引入 ruff(lint + format)+ 可选 pre-commit」。
- 下一步:T-525「引入 ruff(lint + format)+ 可选 pre-commit」。
## 【2026-07-04】T-529 完成 · 默认 cmhub 网关并隐藏 AI 后端选择
- 状态:DONE
@@ -1175,22 +1175,22 @@
- 边界:URL、配置键、API 字段、模型别名、第三方/Shopee 原始错误可保留原文,但外围必须给中文解释;不得直接把英文技术报错裸露给用户。
- 文档:同步 `AGENTS.md`、`docs/05-coding-rules.md`、`docs/current-state.md`。
- 代码:同步修正 T-531 设置未保存离开确认框,改用自定义中文按钮“保存 / 放弃 / 取消”,避免系统默认按钮显示英文。
- 验证:`python -m py_compile app\gui\main_window.py tests\test_gui.py` 通过;`python -m unittest discover -s tests -p test_gui.py` 通过(86 tests);`python -m compileall app main.py` 通过;`python -m unittest discover -s tests` 通过(195 tests);`git diff --check` 通过,仅有本机 LF/CRLF 提示。
- 验证:`python -m py_compile app\gui\main_window.py tests\test_gui.py` 通过;`python -m unittest discover -s tests -p test_gui.py` 通过(86 tests);`python -m compileall app main.py` 通过;`python -m unittest discover -s tests` 通过(195 tests);`git diff --check` 通过,仅有本机 LF/CRLF 提示。
## 【2026-07-06】运行修正 · ②AI生成失败状态分阶段提示
- 现象:在②AI生成选择一个批次,列表都是“失败”状态时点击「开始生成」,状态栏提示“当前筛选结果没有可生成任务”。
- 排查:本地最新未删除批次 `20260702_171000_75bd2557` 的 5 条任务均为 `stage=imported/status=failed/collect_attempts=3/generate_attempts=0/apply_attempts=0`,属于①采集失败,不是 AI 生成失败;②没有旧标题/旧封面,不能直接生成。
- 修正:新增 `ai.is_generatable_task()` 统一 GUI/Worker/底层批处理口径;②状态列把失败细分显示为“采集失败 / 生成失败 / 更新失败”;「开始生成」无可重试任务时提示先到①完成旧数据采集。AI 生成失败可重试,③更新失败不会被②误重试。文档补充 `docs/troubleshooting.md` 的同名排查条目。
- 测试:新增 `test_generate_batch_retries_failed_generation_record_after_existing_result`、`test_generate_batch_does_not_retry_apply_failed_records`、`test_generate_tab_explains_collect_failed_records_are_not_generatable`。
- 测试:新增 `test_generate_batch_retries_failed_generation_record_after_existing_result`、`test_generate_batch_does_not_retry_apply_failed_records`、`test_generate_tab_explains_collect_failed_records_are_not_generatable`。
## 【2026-07-06】文档建议 · 状态栏语义颜色
- 建议:左下角状态栏按 muted/info/success/warning/danger 做轻量文字色区分,普通/就绪保持 muted 或默认,进行中用 info,成功用 success,需用户处理但可恢复的问题用 warning,失败/阻断用 danger。
- 落地边界:状态栏只做辅助反馈,不做大面积背景,不替代弹窗、空状态、运行日志和按钮禁用;后续代码建议统一 `MainWindow.show_status(message, level)`,逐步替换直接 `statusBar().showMessage(...)`。
- 文档:同步 `docs/ui-color-design.md`、`docs/ux-review.md`、`docs/06-tasks.md`、`docs/current-state.md`。
- 验证:文档-only 更新,未运行单元测试。
- 验证:文档-only 更新,未运行单元测试。
## 【2026-07-06】文档记录 · T-105b 启动登录复用已打开 Chrome
- 现象:④账号管理同一账号重复点击「启动登录」会再次打开 Chrome 窗口,而不是复用已打开账号 Chrome 创建/激活 tab。
@@ -1219,7 +1219,7 @@
- 代码:`SettingsTab._on_cmhub_finished()` 成功文案会从 worker payload 的 `balance.user`、`balance.account`、顶层字段中提取 `name/account_name/username/email/id`,优先显示 `cmhub 账号「<账号名>」连接成功:...`;无账号信息时保留 `cmhub 连接成功:...`。
- 脱敏:新增 `appconfig.mask_email()`,`sanitize_for_log()` 对 `email` / `*_email` 字段脱敏,worker 返回和 run log summary 不保存完整邮箱;设置页展示邮箱时也使用脱敏格式。
- 边界:未改 cmhub HTTP 协议、配置 schema、保存逻辑、AI 生成流程或 Shopee/CDP 流程。
- 测试:`python -m py_compile app\appconfig.py app\gui\tabs\settings.py tests\test_appconfig.py tests\test_gui.py` 通过;`python -m unittest discover -s tests -p test_appconfig.py` 通过(9 tests);`python -m unittest discover -s tests -p test_gui.py -k cmhub` 通过(9 tests)。
- 测试:`python -m py_compile app\appconfig.py app\gui\tabs\settings.py tests\test_appconfig.py tests\test_gui.py` 通过;`python -m unittest discover -s tests -p test_appconfig.py` 通过(9 tests);`python -m unittest discover -s tests -p test_gui.py -k cmhub` 通过(9 tests)。
## 【2026-07-06】T-532 补充 · 兼容 cmhub 当前账号返回结构
@@ -1469,3 +1469,17 @@
- 测试:`tests/test_ai.py` 覆盖并发计划、下载慢不阻塞后续 cmhub 生图请求提交、下载失败不重复请求 cmhub 生图;`tests/test_gui.py` 覆盖开始日志中的实际并发展示,并把 direct/mock 路径测试明确指定为 direct backend。
- 文档:`docs/06-tasks.md` 将 T-545 标为 DONE;同步 `docs/04-architecture.md`、`docs/cmhub-integration-design.md`、`docs/api.md`、`docs/routes.md` 和 `docs/current-state.md`。
- 验证:`py -3.10 -m unittest discover -s tests -p "test_ai.py"` 通过(27 tests);`py -3.10 -m unittest discover -s tests -p "test_gui.py"` 通过(102 tests);`python -m ruff check app tests main.py` 通过;`py -3.10 -m compileall app main.py` 通过;`git diff --check` 通过;`py -3.10 -m unittest discover -s tests` 通过(237 tests)。
## 【2026-07-07】cmhub 图片 URL 调试开关
- 背景:排查 cmhub 图片下载链路时,需要临时看到网关返回的 `image_url`,但默认把完整 URL 写入 DB/历史日志可能保留带签名参数的临时资源地址。
- 代码:`app/ai.py` 在环境变量 `CMSHOPEE_DEBUG_CMHUB_IMAGE_URL=1` 时发出 `cover_image_url` 调试事件;`app/gui/workers.py` 将该事件显示到②本轮可见运行日志,并通过 `debug_only` 跳过 SQLite `run_log_events` 持久化。日志仍经过 `diagnostics.redact_log_text()` 脱敏。
- 文档:同步 `docs/04-architecture.md`、`docs/api.md` 和 `docs/current-state.md`。
- 验证:`py -3.10 -m unittest discover -s tests -p "test_ai.py"` 通过(28 tests);`py -3.10 -m unittest discover -s tests -p "test_gui.py"` 通过(102 tests);`python -m ruff check app tests main.py` 通过;`py -3.10 -m compileall app main.py` 通过;`git diff --check` 通过。
## 【2026-07-07】cmhub 图片下载安全重试与慢下载警告
- 背景:同一 cmhub 图片 URL 用 `curl` 测试通常 3~14 秒完成,但 GUI 日志中曾出现 1.7MB 下载耗时 72 秒,判断更像静态文件下载链路瞬时波动。
- 代码:`app/ai.py` 的 cmhub `image_url` 下载层新增最多 3 次安全重试,只复用同一个 `image_url`,不重新调用 cmhub 生图接口,避免重复扣点;下载总耗时超过 20 秒时发出 `cover_download` warning 事件。`app/gui/workers.py` 将该事件显示为“图片下载较慢”运行日志。
- 文档:同步 `docs/04-architecture.md`、`docs/api.md` 和 `docs/current-state.md`。
- 验证:`py -3.10 -m unittest discover -s tests -p "test_ai.py"` 通过(30 tests);`py -3.10 -m unittest discover -s tests -p "test_gui.py"` 通过(102 tests);`python -m ruff check app tests main.py` 通过;`py -3.10 -m compileall app main.py` 通过;`git diff --check` 通过;`py -3.10 -m unittest discover -s tests` 通过(240 tests)。