feat(ai-outfit): auto-append output requirements to prompt (§19.6)

- core/ai_outfit: OUTPUT_REQUIREMENTS constant + build_output_requirements();
  render_prompt(template, task, resolution=None) appends the block when a
  resolution is given; generate_outfit_image passes the current resolution.
- ai_outfit_panel: inline preview now uses render_prompt/build_output_requirements
  with the selected resolution and refreshes when the resolution combo changes,
  so the preview equals what is actually sent.
- tests: +3 cases (tail with resolution, none without, helper empty/filled);
  updated the success test for the appended tail. Full suite (12 files) green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-22 10:40:28 +08:00
co-authored by Claude Opus 4.8
parent 031c420f33
commit d4082ec477
4 changed files with 62 additions and 13 deletions
+23 -1
View File
@@ -39,8 +39,28 @@ class TestAiOutfitCore(unittest.TestCase):
prompt = render_prompt("商品 {title} / {product_id}", self._task())
# No resolution -> no appended requirements tail.
self.assertEqual(prompt, "商品 纯棉短袖 / TY001")
def test_render_prompt_appends_requirements_with_resolution(self):
from core.ai_outfit import render_prompt
prompt = render_prompt("话术 {title}", self._task(), resolution="2K")
self.assertTrue(prompt.startswith("话术 纯棉短袖"))
self.assertIn("批量生成输出要求:", prompt)
self.assertIn("参考解析度:2K", prompt)
self.assertIn("不可跑版", prompt)
def test_build_output_requirements_empty_and_filled(self):
from core.ai_outfit import build_output_requirements
self.assertEqual(build_output_requirements(""), "")
self.assertEqual(build_output_requirements(None), "")
filled = build_output_requirements("4K")
self.assertIn("参考解析度:4K", filled)
self.assertIn("固定 1:1 正方形主图", filled)
def test_safe_product_filename_replaces_invalid_chars(self):
from core.ai_outfit import safe_product_filename
@@ -83,7 +103,9 @@ class TestAiOutfitCore(unittest.TestCase):
self.assertTrue(result.success, result.error)
self.assertTrue(Path(result.output_path).exists())
self.assertEqual(client.prompt, "为 纯棉短袖 生成 TY001")
# generate passes resolution -> rendered prompt + appended requirements.
self.assertTrue(client.prompt.startswith("为 纯棉短袖 生成 TY001"))
self.assertIn("批量生成输出要求:", client.prompt)
self.assertTrue(client.image_path.endswith("garment.png"))
def test_generate_outfit_image_failure(self):