fix: 采集后关闭自动新建商品页

- 新增 close_tab 和 create_tab_info,区分断开 CDP 连接与关闭浏览器 target

- open_product 标记商品页是否本轮自动新建,collect 结束后只关闭自动新建 tab

- 保留用户原本打开的商品 tab,③ 更新流程暂不自动关闭页面

- 补充 editor tab 生命周期测试并同步架构、API、任务和进度文档
This commit is contained in:
chengma
2026-06-27 16:39:12 +08:00
parent 789e82991f
commit e6d7de3d7c
9 changed files with 186 additions and 15 deletions
+9
View File
@@ -509,3 +509,12 @@
- 文档:`docs/06-tasks.md` 将 T-303 标为 DONE;同步 `docs/api.md`、`docs/routes.md`、`docs/current-state.md`,下一个可领取任务更新为 T-401。
- 验证:`python -m unittest discover -s tests -p "test_ai.py"` 通过(6 tests);`python -m unittest discover -s tests -p "test_gui.py"` 通过(22 tests);`python -m compileall app main.py tests` 通过;`python -m unittest discover -s tests` 通过(73 tests)。
- 注意:本轮仍为 mock AI 单测,未调用真实 AI 服务;真实生成需在 `config/ai_models.json` 配好可用 text/image 模型后做小样本实测。
## 【2026-06-27】T-205b 采集后关闭自动新建商品页 tab
- 状态:DONE
- 背景:真机采集时发现程序为不同商品新建编辑页 tab,采集标题和封面后只断开 CDP 连接,不会关闭浏览器页面,批量采集后 Chrome 会堆积多个商品页。
- 方案:区分“复用用户已有 tab”和“本轮程序自动新建 tab”。`CDP.close()` 仍只断开 WebSocket;新增 `close_tab(target_id)` 调 Chrome `/json/close/<targetId>` 关闭浏览器 target;`open_product()` 给 CDP 对象标记 `target_id/created_by_app/cdp_host`;`collect()` finally 中只关闭 `created_by_app=True` 的商品页,用户原本打开的 tab 不关闭。③ 更新流程暂不自动关页,失败时保留现场便于排查。
- 变更:更新 `app/cdp.py`、`app/editor.py`;同步 `docs/06-tasks.md`、`docs/04-architecture.md`、`docs/api.md`、`docs/routes.md`、`docs/current-state.md`。
- 测试:`tests/test_editor_login.py` 增加 `open_product()` 新/旧 tab 标记、`collect()` 关闭自动新建 tab、不关闭复用 tab 的覆盖。
- 验证:`python -m unittest discover -s tests -p "test_editor_login.py"` 通过(9 tests);`python -m compileall app main.py tests` 通过;`python -m unittest discover -s tests` 通过(77 tests)。