feat(products): codec detects + maps Shopify dialect at the boundary (INV-17, SLICE-8)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-06-12 02:20:21 -07:00
parent daa237dd59
commit 0c7a76a305
2 changed files with 54 additions and 11 deletions
+26
View File
@@ -67,3 +67,29 @@ def test_missing_column_message_names_the_column():
with pytest.raises(FileRejected) as exc:
parse_csv(_csv("Handle,Vendor", "mug,Acme"))
assert "'Title'" in exc.value.message
def test_parse_detects_and_maps_shopify():
data = (
"Handle,Title,Body (HTML),Cost per item,Variant Price,Variant Grams,Type,Gift Card\n"
"mug,Moon Mug,<p>Grey</p>,9.50,18.00,300,Drinkware,false\n"
).encode("utf-8")
parsed = parse_csv(data)
assert parsed.dialect == "shopify"
cells = parsed.rows[0].cells
assert cells["Description"] == "<p>Grey</p>"
assert cells["Variant Cost"] == "9.50"
assert cells["Variant Weight"] == "300"
assert cells["Variant Weight Unit"] == "g" # synthesized
# Type (free-text) and Gift Card warned, never mapped:
assert "Type" in parsed.unknown_columns
assert "Gift Card" in parsed.unknown_columns
assert "product_type" not in str(cells) # Type never reached canonical
def test_parse_canonical_unchanged():
data = b"Handle,Title,Description,Variant Price\nmug,Moon Mug,Grey,18.00\n"
parsed = parse_csv(data)
assert parsed.dialect == "canonical"
assert parsed.rows[0].cells["Description"] == "Grey"
assert parsed.unknown_columns == []