feat: snapshot product suite reference assets

This commit is contained in:
chengma
2026-07-17 17:03:40 +08:00
parent d11dc752b5
commit 1fabd8afcf
12 changed files with 252 additions and 5 deletions
+83
View File
@@ -246,6 +246,89 @@ class ImageStudioGenerationTests(TempDirMixin, unittest.TestCase):
self.assert_removed(temp_dir)
def test_job_reference_snapshot_submits_ordered_images(self):
with self.make_temp_dir() as temp_dir:
cfg, project, source = self._project_source(temp_dir)
reference_path = os.path.join(temp_dir, "reference.png")
with open(reference_path, "wb") as fh:
fh.write(self._png_bytes())
reference = image_studio.add_asset(
project.id,
image_studio.ASSET_KIND_ORIGINAL,
local_path=reference_path,
source_order=2,
path=cfg["db_path"],
)
job = image_studio.create_job(
project.id,
source_asset_id=source.id,
reference_asset_ids=[reference.id],
prompt="多图提示词",
path=cfg["db_path"],
)
submitted = []
def fake_submit(method, url, api_key, **kwargs):
submitted.append(kwargs["payload"])
return {"task_id": "multi-image-task", "status": "queued"}
with mock.patch("app.image_studio_generation._runtime", return_value=self._runtime()), \
mock.patch("app.image_studio_generation.ai._cmhub_call_with_retry", side_effect=fake_submit), \
mock.patch(
"app.image_studio_generation.ai._cmhub_call_once",
return_value={
"task_id": "multi-image-task",
"status": "succeeded",
"result": {"image_url": "https://cdn.example.com/multi.png"},
},
), \
mock.patch(
"app.image_studio_generation.ai._download_cmhub_image_with_retry",
return_value=(self._png_bytes(), 0.1),
):
summary = image_studio_generation.run_jobs(
[job],
config=cfg,
path=cfg["db_path"],
)
self.assertEqual(1, summary["success"])
self.assertEqual(2, len(submitted[0]["images"]))
self.assertNotIn("image_base64", submitted[0])
self.assert_removed(temp_dir)
def test_missing_reference_snapshot_fails_without_submitting(self):
with self.make_temp_dir() as temp_dir:
cfg, project, source = self._project_source(temp_dir)
reference = image_studio.add_asset(
project.id,
image_studio.ASSET_KIND_ORIGINAL,
local_path=os.path.join(temp_dir, "missing-reference.png"),
source_order=2,
path=cfg["db_path"],
)
job = image_studio.create_job(
project.id,
source_asset_id=source.id,
reference_asset_ids=[reference.id],
prompt="多图提示词",
path=cfg["db_path"],
)
with mock.patch("app.image_studio_generation._runtime", return_value=self._runtime()), \
mock.patch("app.image_studio_generation.ai._cmhub_call_with_retry") as submit:
summary = image_studio_generation.run_jobs(
[job],
config=cfg,
path=cfg["db_path"],
)
self.assertEqual(1, summary["failed"])
self.assertIn("参考图尚未下载", summary["jobs"][0]["error"])
submit.assert_not_called()
self.assert_removed(temp_dir)
def test_stop_after_download_discards_temporary_result(self):
with self.make_temp_dir() as temp_dir:
cfg, project, source = self._project_source(temp_dir)