fix(collect): handle login target close race
Tests / Python 3.11 / Windows (push) Has been cancelled
Tests / Python 3.11 / Windows (push) Has been cancelled
This commit is contained in:
+14
-2
@@ -3,7 +3,7 @@ id: T-630
|
||||
title: ①采集关闭商品页后的登录检测竞态修复
|
||||
phase: 2
|
||||
deps: [T-620]
|
||||
status: TODO
|
||||
status: DONE
|
||||
created: 2026-07-14
|
||||
---
|
||||
|
||||
@@ -131,4 +131,16 @@ step=login_check result=retry detail=任务 71 商品 52313423890 账号 <别名
|
||||
|
||||
## 执行记录
|
||||
|
||||
- 待实现。
|
||||
- 2026-07-14 完成。
|
||||
- `app/cdp.py` 新增有界 `wait_target_closed()` / `close_tab_and_wait()`:关闭 target 后按 ID 轮询 `/json`,默认最多等待 2 秒,不使用固定休眠。
|
||||
- `app/editor.py` 的登录检测现在保留 Cookie API 是否成功、探测错误类别和尝试次数;URL/Cookie 探测失败返回 `LOGIN_CHECK_TARGET_UNAVAILABLE`,不会伪装成 `NO_SESSION_COOKIE`。多个 Shopee 页面并存时优先稳定 portal,失效 target 会在同一检测预算内快速重选。
|
||||
- ①采集及⑥共用的后台只读商品页,在成功采集或 `open_product()` 打开失败时都会确认程序新建 target 已消失;关闭确认超时仅返回 `close_target_confirmed=False` 并记录警告,不覆盖采集结果。③前台更新和提交后 2 秒观察逻辑未修改。
|
||||
- `CollectWorker` 的登录 retry/recovered 日志已带任务 ID、商品 ID 和账号;首次不确定、后续恢复时明确记录恢复。关闭确认超时写可见警告和本地诊断,任务仍按采集成功落库。账号管理把 target 暂不可用显示为“登录状态暂不可确认”。
|
||||
- 已同步 `docs/04-architecture.md` 与 `docs/api.md`,并补充 CDP、editor、账号状态和 worker 回归测试。
|
||||
- 自动验证通过:
|
||||
- `py -3.10 -m unittest tests.test_editor_login`:50 项通过;
|
||||
- 仅导出本任务暂存内容的干净副本运行 `py -3.10 -m unittest tests.test_gui`:182 项通过;
|
||||
- 同一干净副本运行 `py -3.10 -m unittest discover -s tests`:470 项通过;
|
||||
- `python -m ruff check app tests main.py`、`py -3.10 -m compileall app main.py`、`git diff --check` 均通过。
|
||||
- 真实 CDP 验证:当前已有 1 个账号 Chrome 运行且登录检测成功;最终代码连续 3 轮“后台新建只读 target → 有界关闭 → 立即检测登录”均通过,关闭确认均为 true、登录均为 true、`probe_attempts=1`,单轮分别耗时约 0.14 秒、0.05 秒、0.03 秒,无假 `NO_SESSION_COOKIE`,且 target 均已确认消失。
|
||||
- 商品采集实测限制:按仓库规则尝试测试商品 `51100639510` 时,Shopee 返回“商品失效:please input correct product id”,无法继续完成该商品的标题/封面三轮实采;未改用真实运营商品规避测试边界。标题、封面下载和 SQLite 流程由自动回归覆盖。
|
||||
|
||||
Reference in New Issue
Block a user