fix(call2): no metadata dump in long description
Long desc is Hook + Benefits (+ brief trust close) only; forbid Full specs / Attribute list / product-name header that re-lists DECLARED ATTRIBUTES or DIMENSION FACT BLOCK. Defensively strip trailing Category:/Length:/Board Feet: labeled dumps in parse.
This commit is contained in:
@@ -101,6 +101,16 @@ def test_call2_seed_has_short_long_structure(env):
|
||||
assert '"description"' in CALL2_SEED
|
||||
assert "<HTML long description>" not in CALL2_SEED
|
||||
assert "plain text long description" in CALL2_SEED
|
||||
# No Full-specs / attribute metadata dump in long desc (specs live on Woo fields).
|
||||
assert "Hook + Benefits only" in CALL2_SEED
|
||||
assert "Do NOT restate DECLARED" in CALL2_SEED
|
||||
assert 'no "Full specs"' in CALL2_SEED or "Do NOT add a Full specs" in CALL2_SEED
|
||||
assert "Category:/Figure:/Edge:" in CALL2_SEED
|
||||
assert "1–2 key traits" in CALL2_SEED
|
||||
assert "labeled catalog" in CALL2_SEED or "labeled metadata list" in CALL2_SEED
|
||||
# Must not instruct a Full-specs numbered part (old 4-part structure).
|
||||
assert "3. Full specs" not in CALL2_SEED
|
||||
assert "Four parts, in order" not in CALL2_SEED
|
||||
|
||||
|
||||
def test_taxonomy_lists_call1_closed_shape():
|
||||
@@ -296,6 +306,71 @@ def test_parse_call2_response_json_and_fenced():
|
||||
assert _html_to_plain(" Kiln-dried walnut for a bar top. ") == "Kiln-dried walnut for a bar top."
|
||||
|
||||
|
||||
def test_strip_attribute_dump_trailing_and_header():
|
||||
"""Defensive: drop labeled Category:/Length: dumps from long description."""
|
||||
from backend.inference import _strip_attribute_dump, parse_call2_response
|
||||
import json as _json
|
||||
|
||||
hook_benefits = (
|
||||
"Kiln-dried maple suited to a compact bar top.\n"
|
||||
"- Stable stock: kiln dried, ready to mill.\n"
|
||||
"- Live edge on one side for a natural apron.\n"
|
||||
"- Character grade with usable burl figure."
|
||||
)
|
||||
dump = (
|
||||
"Maple Slab\n"
|
||||
"- Category: Live edge wood\n"
|
||||
"- Figure: Burl, Curl, Figured\n"
|
||||
"- Edge: Live Edge 1 side\n"
|
||||
"- Grade: Character\n"
|
||||
"- Moisture: Kiln dried\n"
|
||||
"- Length: 45.0in\n"
|
||||
"- Board Feet: 12.4"
|
||||
)
|
||||
trust = "Ships from the mill; ask about returns in Brand voice."
|
||||
full = f"{hook_benefits}\n\n{dump}\n\n{trust}"
|
||||
cleaned = _strip_attribute_dump(full)
|
||||
assert "Category:" not in cleaned
|
||||
assert "Board Feet:" not in cleaned
|
||||
assert "Maple Slab" not in cleaned
|
||||
assert "Kiln-dried maple" in cleaned
|
||||
assert "Live edge on one side" in cleaned
|
||||
assert "Ships from the mill" in cleaned
|
||||
|
||||
# Mid-body Full specs header also stripped; benefits bullets without Label: kept.
|
||||
mid = (
|
||||
"Hook line.\n"
|
||||
"- Good for a bench seat.\n"
|
||||
"\n"
|
||||
"Full specs\n"
|
||||
"- Species: Maple\n"
|
||||
"- Length: 45.0in\n"
|
||||
"- Thickness: 2.0in\n"
|
||||
"\n"
|
||||
"Neutral trust close."
|
||||
)
|
||||
mid_clean = _strip_attribute_dump(mid)
|
||||
assert "Full specs" not in mid_clean
|
||||
assert "Species:" not in mid_clean
|
||||
assert "Good for a bench seat" in mid_clean
|
||||
assert "Neutral trust close" in mid_clean
|
||||
|
||||
# Fewer than 3 attr lines: leave alone (not a dump).
|
||||
short_list = "Hook.\n- Length: 45.0in\n- Thickness: 2in\nTrust."
|
||||
assert _strip_attribute_dump(short_list) == short_list.strip()
|
||||
|
||||
# parse_call2_response applies strip on description (not short).
|
||||
payload = _json.dumps({
|
||||
"short_description": "Short with - Length: 1in - Width: 2in - Thickness: 3in ok",
|
||||
"description": full,
|
||||
})
|
||||
short, desc = parse_call2_response(payload)
|
||||
assert short and "Length: 1in" in short # short untouched by attr-dump strip
|
||||
assert "Category:" not in desc
|
||||
assert "Board Feet:" not in desc
|
||||
assert "Kiln-dried maple" in desc
|
||||
|
||||
|
||||
def test_call1_disabled_even_when_inference_off(env):
|
||||
"""Call 1 hard-disable wins over inference_enabled=false (still 410, not 409)."""
|
||||
client, conn = env
|
||||
|
||||
Reference in New Issue
Block a user