Add FLUX 3 Klein layout outputs to clothing planner

This commit is contained in:
2026-11-04 10:36:37 +00:00
parent 91c6659306
commit f677b7e567
3 changed files with 147 additions and 4 deletions
@@ -111,6 +111,44 @@ class ClothingLayoutPlannerTests(unittest.TestCase):
self.assertIn("cotton shirt", prompt)
self.assertIn("region", prompt)
def test_flux3_boxes_use_official_order_and_1000_grid(self):
plan = PLANNER.plan_layout(inventory(
{"id": "item_001", "name": "blue shirt", "description": "blue cotton"},
{"id": "item_002", "name": "red bag", "description": "red leather"},
), 1200, 800, "grid")
rows = PLANNER.build_flux3_boxes(plan)
self.assertEqual(len(rows), 2)
for row in rows:
top, left, bottom, right = row["bbox"]
self.assertTrue(0 <= top < bottom <= 1000)
self.assertTrue(0 <= left < right <= 1000)
self.assertEqual(rows[0]["desc"], "blue cotton")
def test_flux3_prompt_has_matching_tags_and_trailing_json(self):
plan = PLANNER.plan_layout(inventory({
"id": "item_001", "name": "blue shirt", "description": "blue cotton",
}))
prompt, boxes_json = PLANNER.build_flux3_prompt(plan)
self.assertIn("<item_001>", prompt)
self.assertTrue(prompt.endswith(boxes_json))
self.assertEqual(json.loads(boxes_json)[0]["id"], "item_001")
def test_flux3_padding_shrinks_without_changing_legacy_plan(self):
plan = PLANNER.plan_layout(inventory({"id": "item_001", "name": "shirt"}))
original = dict(plan["regions"][0])
padded = PLANNER.build_flux3_boxes(plan, 10)[0]["bbox"]
self.assertEqual(plan["regions"][0], original)
self.assertGreater(padded[2] - padded[0], 0)
self.assertGreater(padded[3] - padded[1], 0)
def test_flux3_editing_mode_requires_source_coordinates(self):
with self.assertRaisesRegex(ValueError, "editing.*source bounding boxes"):
PLANNER.DumasClothingLayoutPlanner().plan(
inventory({"id": "item_001", "name": "shirt"}),
640, 480, "balanced", 5, 3, "#EEE8DC", True,
"flux3", 0, True, "editing",
)
def test_invalid_fields_have_actionable_errors(self):
with self.assertRaisesRegex(ValueError, "invalid unit"):
PLANNER.normalize_inventory(inventory({"id": "x", "name": "X", "unit": "trio"}))