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
+116 -9
View File
@@ -25,9 +25,13 @@ from app.gui.tabs.product_suite import (
ORIGINAL_CHECK_STATE_ROLE,
ProductOriginalDelegate,
ProductOriginalList,
ProductSuiteGlobalHistoryDialog,
ProductSuiteHistoryDialog,
ProductSuitePreviewDialog,
ProductSuiteRoundPreviewDialog,
ProductSuiteTab,
SuiteGlobalHistoryRoundRow,
SuiteGlobalHistoryThumbnail,
SuiteHistoryImageCard,
SuiteResultCard,
)
@@ -1976,7 +1980,103 @@ class ProductSuiteGuiTests(TempDirMixin, unittest.TestCase):
self.assert_removed(temp_dir)
def test_history_button_reuses_project_dialog_and_closes_with_task(self):
def test_global_history_dialog_lists_filters_and_previews_round_images(self):
with self.make_temp_dir() as temp_dir:
config = self._config(temp_dir)
project, sources = self._create_project_with_assets(temp_dir, config, 1)
source = sources[0]
other_project = image_studio.create_or_get_project(
account_alias="other-shop",
account_name="副店",
account_slug="other-shop",
item_id="51100639511",
path=config["db_path"],
)
other_source = image_studio.add_asset(
other_project.id,
image_studio.ASSET_KIND_ORIGINAL,
path=config["db_path"],
)
for index in range(7):
image_path = os.path.join(temp_dir, "global-%d.png" % index)
self._write_image(image_path)
self._create_history_job(
project,
source,
config["db_path"],
round_key="main-round",
slot_index=index,
local_path=image_path,
job_type="场景图",
)
other_path = os.path.join(temp_dir, "other-global.png")
self._write_image(other_path)
self._create_history_job(
other_project,
other_source,
config["db_path"],
round_key="other-round",
slot_index=0,
local_path=other_path,
job_type="卖点图",
)
image_studio.set_current_generation_round(
project.id,
"main-round",
path=config["db_path"],
)
dialog = ProductSuiteGlobalHistoryDialog(
current_project_id=project.id,
db_path=config["db_path"],
)
dialog.show()
self.app.processEvents()
self.assertEqual(2, dialog._round_count)
rows = dialog.findChildren(SuiteGlobalHistoryRoundRow)
main_row = next(
row for row in rows if row.round_info.project_id == project.id
)
self.assertEqual(5, len(main_row.findChildren(SuiteGlobalHistoryThumbnail)))
self.assertTrue(
any(
label.text() == "+2"
for label in main_row.findChildren(QLabel)
)
)
self.assertTrue(
any(label.text() == "当前" for label in main_row.findChildren(QLabel))
)
with mock.patch.object(
ProductSuiteRoundPreviewDialog,
"exec",
return_value=0,
) as preview:
dialog._preview_round(main_row, 1)
preview.assert_called_once_with()
dialog.account_filter_edit.setText("副店")
dialog.refresh_history()
self.app.processEvents()
self.assertEqual(1, dialog._round_count)
self.assertEqual(
[other_project.id],
[row.round_info.project_id for row in dialog._history_rows],
)
dialog.account_filter_edit.clear()
dialog.current_project_checkbox.setChecked(True)
self.app.processEvents()
self.assertEqual(1, dialog._round_count)
self.assertEqual(
[project.id],
[row.round_info.project_id for row in dialog._history_rows],
)
self.assert_removed(temp_dir)
def test_history_button_reuses_global_dialog_and_keeps_it_when_task_closes(self):
with self.make_temp_dir() as temp_dir:
config = self._config(temp_dir)
project, sources = self._create_project_with_assets(temp_dir, config, 1)
@@ -2014,18 +2114,20 @@ class ProductSuiteGuiTests(TempDirMixin, unittest.TestCase):
tab.open_history_dialog()
self.app.processEvents()
dialog = tab._history_dialog
self.assertIsInstance(dialog, ProductSuiteHistoryDialog)
self.assertIsInstance(dialog, ProductSuiteGlobalHistoryDialog)
self.assertEqual(project.id, dialog.current_project_id)
self.assertTrue(dialog.isVisible())
tab.open_history_dialog()
self.assertIs(dialog, tab._history_dialog)
tab.close_task(0)
self.app.processEvents()
self.assertIsNone(tab._history_dialog)
self.assertIs(dialog, tab._history_dialog)
self.assertTrue(dialog.isVisible())
self.assert_removed(temp_dir)
def test_history_button_explains_empty_project_without_opening_dialog(self):
def test_history_button_opens_global_dialog_for_empty_current_project(self):
with self.make_temp_dir() as temp_dir:
config = self._config(temp_dir)
project, _ = self._create_project_with_assets(temp_dir, config, 0)
@@ -2036,13 +2138,18 @@ class ProductSuiteGuiTests(TempDirMixin, unittest.TestCase):
state.item_id = project.item_id
state.project_id = project.id
state.project_binding_state = project.binding_state
messages = []
tab._message = lambda title, message, **kwargs: messages.append((title, message))
tab.open_history_dialog()
self.app.processEvents()
self.assertEqual("暂无历史生成记录", messages[-1][0])
self.assertIsNone(tab._history_dialog)
dialog = tab._history_dialog
self.assertIsInstance(dialog, ProductSuiteGlobalHistoryDialog)
self.assertTrue(dialog.isVisible())
self.assertTrue(
any(
label.text() == "暂无套图历史生成记录,完成套图生成后会自动出现在这里"
for label in dialog.findChildren(QLabel)
)
)
self.assert_removed(temp_dir)