feat(product-suite): add global generation history

This commit is contained in:
chengma
2026-07-17 09:59:55 +08:00
parent f1dc7f28dc
commit e232097ba5
13 changed files with 1409 additions and 52 deletions
+154
View File
@@ -1028,6 +1028,160 @@ class ImageStudioTests(TempDirMixin, unittest.TestCase):
self.assert_removed(temp_dir)
def test_global_generation_rounds_filter_paginate_and_exclude_deleted_projects(self):
with self.make_temp_dir() as temp_dir:
db_path = os.path.join(temp_dir, "cmshopee.db")
db.init_db(db_path)
first_project = image_studio.create_or_get_project(
account_alias="main-shop",
account_name="主店",
account_slug="main-shop",
item_id="51100639510",
path=db_path,
)
second_project = image_studio.create_or_get_project(
account_alias="second-shop",
account_name="副店",
account_slug="second-shop",
item_id="51100639511",
path=db_path,
)
deleted_project = image_studio.create_or_get_project(
account_alias="deleted-shop",
account_slug="deleted-shop",
item_id="51100639512",
path=db_path,
)
first_source = image_studio.add_asset(
first_project.id,
image_studio.ASSET_KIND_ORIGINAL,
path=db_path,
)
second_source = image_studio.add_asset(
second_project.id,
image_studio.ASSET_KIND_ORIGINAL,
path=db_path,
)
deleted_source = image_studio.add_asset(
deleted_project.id,
image_studio.ASSET_KIND_ORIGINAL,
path=db_path,
)
first = image_studio.create_job(
first_project.id,
source_asset_id=first_source.id,
task_key="global-first-slot",
generation_round_key="first-round",
generation_slot_index=0,
path=db_path,
)
image_studio.update_job_status(first.id, "failed", path=db_path)
retry = image_studio.create_job(
first_project.id,
source_asset_id=first_source.id,
task_key="global-first-retry",
generation_round_key="first-round",
generation_slot_index=0,
path=db_path,
)
image_studio.update_job_status(retry.id, "succeeded", path=db_path)
second = image_studio.create_job(
second_project.id,
source_asset_id=second_source.id,
task_key="global-second-round",
generation_round_key="second-round",
generation_slot_index=0,
path=db_path,
)
image_studio.update_job_status(second.id, "succeeded", path=db_path)
deleted = image_studio.create_job(
deleted_project.id,
source_asset_id=deleted_source.id,
task_key="global-deleted-round",
generation_round_key="deleted-round",
generation_slot_index=0,
path=db_path,
)
image_studio.update_job_status(deleted.id, "succeeded", path=db_path)
legacy = image_studio.create_job(
first_project.id,
source_asset_id=first_source.id,
task_key="global-legacy-history",
path=db_path,
)
image_studio.update_job_status(legacy.id, "cancelled", path=db_path)
image_studio.set_current_generation_round(
first_project.id,
"first-round",
path=db_path,
)
image_studio.soft_delete_project(
deleted_project.id,
reason="测试软删除",
path=db_path,
)
rounds = image_studio.list_global_generation_rounds(path=db_path)
self.assertEqual(
{first_project.id, second_project.id},
{round_.project_id for round_ in rounds},
)
self.assertIsNone(rounds[0].generation_round_key)
self.assertTrue(rounds[0].is_legacy)
self.assertEqual(first_project.id, rounds[0].project_id)
self.assertEqual(second_project.id, rounds[1].project_id)
first_round = next(
round_
for round_ in rounds
if (
round_.project_id == first_project.id
and round_.generation_round_key == "first-round"
)
)
self.assertEqual("first-round", first_round.generation_round_key)
self.assertEqual("主店", first_round.account_name)
self.assertEqual(1, first_round.job_count)
self.assertEqual(1, first_round.slot_count)
self.assertEqual(1, first_round.retry_count)
self.assertEqual(1, first_round.succeeded_count)
self.assertEqual(0, first_round.failed_count)
self.assertTrue(first_round.is_current)
self.assertEqual(
[first_project.id, first_project.id],
[
round_.project_id
for round_ in image_studio.list_global_generation_rounds(
account_query="主店",
path=db_path,
)
],
)
self.assertEqual(
[second_project.id],
[
round_.project_id
for round_ in image_studio.list_global_generation_rounds(
item_query="51100639511",
path=db_path,
)
],
)
self.assertEqual(
[first_project.id, first_project.id],
[
round_.project_id
for round_ in image_studio.list_global_generation_rounds(
project_id=first_project.id,
path=db_path,
)
],
)
self.assertEqual(1, len(image_studio.list_global_generation_rounds(limit=1, path=db_path)))
self.assertEqual(1, len(image_studio.list_global_generation_rounds(limit=1, offset=1, path=db_path)))
self.assert_removed(temp_dir)
def test_selections_are_consecutive_unique_and_replaceable(self):
with self.make_temp_dir() as temp_dir:
db_path = os.path.join(temp_dir, "cmshopee.db")