Recover inventory items from severely malformed VLM JSON

This commit is contained in:
2026-11-03 11:29:44 +00:00
parent 09529db9d6
commit 91c6659306
2 changed files with 58 additions and 0 deletions
@@ -41,6 +41,17 @@ class ClothingLayoutPlannerTests(unittest.TestCase):
raw = inventory({"id": "hat", "name": "hat"}) + "\nHere is the inventory."
self.assertEqual(PLANNER.normalize_inventory(raw)[0]["id"], "hat")
def test_salvages_schema_items_when_json_repair_cannot_parse(self):
raw = '{"items":[{"id":"shirt","name":"shirt","quantity":1,"description":"blue shirt'
original_repair = PLANNER._repair_vlm_json
PLANNER._repair_vlm_json = lambda _text: '{broken'
try:
items = PLANNER.normalize_inventory(raw)
finally:
PLANNER._repair_vlm_json = original_repair
self.assertEqual(items[0]["id"], "shirt")
self.assertEqual(items[0]["description"], "blue shirt")
def test_quantities_and_pairs_create_deterministic_instances(self):
plan = PLANNER.plan_layout(inventory(
{"id": "sock", "name": "sock", "quantity": 3},