feat(product-suite): persist current generation rounds

This commit is contained in:
chengma
2026-07-16 23:27:25 +08:00
parent c146c0b41d
commit f3defdeb95
11 changed files with 806 additions and 16 deletions
+56 -1
View File
@@ -1,4 +1,5 @@
import os
import tempfile
import unittest
from types import SimpleNamespace
from unittest import mock
@@ -7,7 +8,7 @@ os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
from _helpers import REPO_ROOT # noqa: F401
from app import image_studio_images, workers
from app import db, image_studio, image_studio_images, workers
if workers.QT_IMPORT_ERROR is not None:
raise unittest.SkipTest("PySide6 未安装")
@@ -19,6 +20,7 @@ from app.workers import BaseWorker, run_worker
from app.gui.workers import (
ImageStudioDownloadOriginalWorker,
ImageStudioPullImagesWorker,
ProductSuiteGenerateWorker,
)
@@ -196,6 +198,59 @@ class WorkerTests(unittest.TestCase):
self.assertEqual({"asset_id": 12, "cancelled": True}, summary)
def test_product_suite_worker_writes_generation_round_and_stable_slots(self):
with tempfile.TemporaryDirectory() as temp_dir:
db_path = os.path.join(temp_dir, "cmshopee.db")
db.init_db(db_path)
project = image_studio.create_or_get_project(
account_alias="alias-a",
account_slug="alias-a",
item_id="51100639510",
path=db_path,
)
source = image_studio.add_asset(
project.id,
image_studio.ASSET_KIND_ORIGINAL,
path=db_path,
)
worker = ProductSuiteGenerateWorker(
project.id,
[
{
"source_asset_id": source.id,
"job_type": "白底图",
"prompt": "第一张",
"generation_round_key": "worker-round",
"generation_slot_index": 0,
},
{
"source_asset_id": source.id,
"job_type": "场景图",
"prompt": "第二张",
"generation_round_key": "worker-round",
"generation_slot_index": 1,
},
],
generation_round_key="worker-round",
db_path=db_path,
)
with mock.patch(
"app.gui.workers.image_studio_generation.run_jobs",
return_value={"total": 2, "success": 0, "failed": 0, "cancelled": 0},
):
summary = worker.execute()
jobs = [image_studio.get_job(job_id, path=db_path) for job_id in worker.job_ids]
self.assertEqual("worker-round", summary["generation_round_key"])
self.assertEqual(
[("worker-round", 0), ("worker-round", 1)],
[
(job.generation_round_key, job.generation_slot_index)
for job in jobs
],
)
if __name__ == "__main__":
unittest.main()