feat: 完成T-504更新执行增强

- 新增 dry-run、多账号并行和最大并行账号数设置

- 增加 run_logs/run_log_events 运行日志表及读写接口

- ApplyWorker 支持 dry-run 预览、按账号并行、端口冲突阻断和日志展示

- 补充 DB/GUI 单元测试并同步任务、架构、API、路由和当前状态文档

验证: python -m compileall app main.py tests; python -m unittest discover -s tests
This commit is contained in:
chengma
2026-06-29 10:25:09 +08:00
parent 01e319cad8
commit 0e0ed193b6
17 changed files with 1071 additions and 149 deletions
+48
View File
@@ -139,6 +139,54 @@ class DbTests(TempDirMixin, unittest.TestCase):
self.assert_removed(temp_dir)
def test_run_logs_and_events_are_persisted(self):
with self.make_temp_dir() as temp_dir:
db_path = os.path.join(temp_dir, "cmshopee.db")
db.init_db(db_path)
run_id = db.create_run_log(
"apply",
dry_run=True,
total=2,
options={"api_key": "secret", "mode": "preview"},
path=db_path,
)
db.add_run_log_event(
run_id,
"dry-run 预览任务",
task_id=7,
alias="alias",
item_id="51100639510",
path=db_path,
)
db.finish_run_log(
run_id,
status="done",
done=2,
success_count=1,
skipped_count=1,
failed_count=0,
summary_json={"password": "secret", "done": 2},
path=db_path,
)
run = db.list_run_logs(path=db_path)[0]
self.assertEqual(run_id, run.id)
self.assertEqual("apply", run.run_type)
self.assertEqual(1, run.dry_run)
self.assertEqual("done", run.status)
self.assertEqual(2, run.done)
self.assertEqual("***", run.options["api_key"])
self.assertEqual("***", run.summary["password"])
events = db.list_run_log_events(run_id, path=db_path)
self.assertEqual(1, len(events))
self.assertEqual("alias", events[0].alias)
self.assertEqual("51100639510", events[0].item_id)
self.assertIn("dry-run", events[0].message)
self.assert_removed(temp_dir)
if __name__ == "__main__":
unittest.main()