fix(collect): handle login target close race
Tests / Python 3.11 / Windows (push) Has been cancelled

This commit is contained in:
chengma
2026-07-14 12:08:12 +08:00
parent cbfd36af56
commit f99cde8e05
11 changed files with 588 additions and 88 deletions
+27 -3
View File
@@ -8465,6 +8465,7 @@ class GuiTests(TempDirMixin, unittest.TestCase):
db_path=cfg["db_path"],
config=cfg,
preflight=False,
diagnostic_log_dir=os.path.join(temp_dir, "logs"),
).execute()
self.assertTrue(summary["ok"])
@@ -8480,6 +8481,19 @@ class GuiTests(TempDirMixin, unittest.TestCase):
self.assertEqual(1, sleep.call_count)
self.assertEqual(2, collect.call_count)
events = db.list_run_log_events(summary["run_id"], path=cfg["db_path"])
messages = "\n".join(event.message for event in events)
self.assertIn(
"step=login_check result=retry detail=任务 "
f"{tasks[0].id} 商品 51100639510",
messages,
)
self.assertIn(
"step=login_check result=recovered detail=任务 "
f"{tasks[0].id} 商品 51100639510",
messages,
)
updated = db.list_tasks(batch_id=batch_id, path=cfg["db_path"])
self.assertTrue(all(task.stage == "collected" for task in updated))
self.assertTrue(all(task.status == "success" for task in updated))
@@ -8516,7 +8530,11 @@ class GuiTests(TempDirMixin, unittest.TestCase):
with mock.patch("app.gui.accounts.detect_login", return_value=status) as detect_login, \
mock.patch(
"app.gui.editor.collect",
return_value={"old_title": "旧标题", "old_cover_path": "old.jpg"},
return_value={
"old_title": "旧标题",
"old_cover_path": "old.jpg",
"close_target_confirmed": False,
},
) as collect, \
mock.patch("app.gui.workers.time.sleep") as sleep:
summary = CollectWorker(
@@ -8524,6 +8542,7 @@ class GuiTests(TempDirMixin, unittest.TestCase):
db_path=cfg["db_path"],
config=cfg,
preflight=False,
diagnostic_log_dir=os.path.join(temp_dir, "logs"),
).execute()
self.assertTrue(summary["ok"])
@@ -8544,6 +8563,11 @@ class GuiTests(TempDirMixin, unittest.TestCase):
events = db.list_run_log_events(summary["run_id"], path=cfg["db_path"])
messages = "\n".join(event.message for event in events)
self.assertIn("登录状态检测暂时不稳定", messages)
self.assertIn(
"step=close_product result=uncertain detail=任务 "
f"{tasks[0].id} 商品 51100639510",
messages,
)
self.assertNotIn("采集中途掉登录", messages)
self.assert_removed(temp_dir)
@@ -8604,9 +8628,9 @@ class GuiTests(TempDirMixin, unittest.TestCase):
events = db.list_run_log_events(summary["run_id"], path=cfg["db_path"])
messages = "\n".join(event.message for event in events)
self.assertIn("LOGIN_CHECK_FAILED", messages)
self.assertIn("登录检测调用失败", messages)
self.assertNotIn("LOGIN_CHECK_FAILED", messages)
self.assertNotIn("SECRET-TOKEN", messages)
self.assertIn("token=***", messages)
self.assert_removed(temp_dir)