feat(call2): short/long desc structure in seed (not brand voice)
Call 2 seed now requires benefit-first short + four-part long HTML, returned as JSON. POST parses and persists both fields; Create-desc gate no longer requires short (Call 2 writes it). Brand voice/geo stay Settings-injected.
This commit is contained in:
@@ -77,6 +77,24 @@ def test_call1_seed_is_locked_expert_prompt(env):
|
||||
assert "character\":" not in CALL1_SEED.replace(" ", "")
|
||||
|
||||
|
||||
def test_call2_seed_has_short_long_structure(env):
|
||||
"""Call 2 seed carries short+long structure and JSON dual output (not brand voice)."""
|
||||
client, _conn = env
|
||||
from backend.inference import CALL2_SEED
|
||||
|
||||
body = client.get("/api/v1/prompts/call2").json()
|
||||
assert body["active_content"] == CALL2_SEED
|
||||
assert "SHORT DESCRIPTION" in CALL2_SEED
|
||||
assert "LONG DESCRIPTION" in CALL2_SEED
|
||||
assert "Lead with the outcome" in CALL2_SEED
|
||||
assert "Hook" in CALL2_SEED
|
||||
assert "Brand voice and Geography sections when provided" in CALL2_SEED
|
||||
assert "Whidbey" not in CALL2_SEED
|
||||
assert "Pacific Northwest" not in CALL2_SEED
|
||||
assert '"short_description"' in CALL2_SEED
|
||||
assert '"description"' in CALL2_SEED
|
||||
|
||||
|
||||
def test_taxonomy_lists_call1_closed_shape():
|
||||
"""#86: Call 1 lists are closed Woo picks only — no grade/thickness/moisture; feat names stripped."""
|
||||
import tempfile, os, shutil
|
||||
@@ -177,10 +195,47 @@ def test_call1_hard_disabled_410(env, monkeypatch):
|
||||
assert conn.execute("SELECT COUNT(*) AS n FROM inference_log").fetchone()["n"] == 0
|
||||
|
||||
|
||||
def test_call2_stores_description(env, monkeypatch):
|
||||
def test_call2_stores_short_and_description(env, monkeypatch):
|
||||
"""Call 2 persists both short_description and description from JSON output."""
|
||||
client, conn = env
|
||||
conn.execute("INSERT OR REPLACE INTO settings(key,value,value_enc) VALUES ('content_llm_enabled','true',NULL)")
|
||||
conn.execute("INSERT INTO slabs(id,sku,length_in,thickness_in,width_avg_in,bdft,title,status,server_rev,client_rev,created_at,updated_at) VALUES ('s1','SLAB-01',100,2,20,18,'Walnut Slab','ready',1,1,'t','t')")
|
||||
conn.execute(
|
||||
"INSERT INTO slabs(id,sku,length_in,thickness_in,width_avg_in,bdft,title,short_description,"
|
||||
"status,server_rev,client_rev,created_at,updated_at) "
|
||||
"VALUES ('s1','SLAB-01',100,2,20,18,'Walnut Slab','old short','ready',1,1,'t','t')"
|
||||
)
|
||||
conn.execute("INSERT INTO slab_photos(id,slab_id,seq,processed_blob,created_at) VALUES ('p1','s1',1,X'89504E47','t')")
|
||||
conn.commit()
|
||||
from backend.inference import InferenceClient
|
||||
import json as _json
|
||||
|
||||
payload = _json.dumps({
|
||||
"short_description": "Turn a blank into a showpiece table — kiln-dried walnut with live edge character. Ready to finish.",
|
||||
"description": "<p><strong>Showpiece ready.</strong></p><ul><li><strong>Stable:</strong> kiln dried</li></ul>",
|
||||
})
|
||||
monkeypatch.setattr(InferenceClient, "chat", lambda self, messages: payload)
|
||||
r = client.post("/api/v1/slabs/s1/inference/call2")
|
||||
assert r.status_code == 200, r.text
|
||||
body = r.json()
|
||||
assert "Showpiece ready" in body["description"] or "kiln" in body["description"]
|
||||
assert body["short_description"].startswith("Turn a blank")
|
||||
row = conn.execute(
|
||||
"SELECT short_description, description, content_source FROM slabs WHERE id='s1'"
|
||||
).fetchone()
|
||||
assert row["short_description"].startswith("Turn a blank")
|
||||
assert "<p>" in row["description"]
|
||||
assert row["content_source"] == "llm"
|
||||
|
||||
|
||||
def test_call2_html_fallback_keeps_prior_short(env, monkeypatch):
|
||||
"""Non-JSON Call 2 body becomes description only; prior short is left alone."""
|
||||
client, conn = env
|
||||
conn.execute("INSERT OR REPLACE INTO settings(key,value,value_enc) VALUES ('content_llm_enabled','true',NULL)")
|
||||
conn.execute(
|
||||
"INSERT INTO slabs(id,sku,length_in,thickness_in,width_avg_in,bdft,title,short_description,"
|
||||
"status,server_rev,client_rev,created_at,updated_at) "
|
||||
"VALUES ('s1','SLAB-01',100,2,20,18,'Walnut Slab','keep me','ready',1,1,'t','t')"
|
||||
)
|
||||
conn.execute("INSERT INTO slab_photos(id,slab_id,seq,processed_blob,created_at) VALUES ('p1','s1',1,X'89504E47','t')")
|
||||
conn.commit()
|
||||
from backend.inference import InferenceClient
|
||||
@@ -189,11 +244,33 @@ def test_call2_stores_description(env, monkeypatch):
|
||||
r = client.post("/api/v1/slabs/s1/inference/call2")
|
||||
assert r.status_code == 200, r.text
|
||||
assert r.json()["description"] == "<p>A fine walnut slab.</p>"
|
||||
row = conn.execute("SELECT description, content_source FROM slabs WHERE id='s1'").fetchone()
|
||||
assert "short_description" not in r.json()
|
||||
row = conn.execute(
|
||||
"SELECT short_description, description, content_source FROM slabs WHERE id='s1'"
|
||||
).fetchone()
|
||||
assert row["short_description"] == "keep me"
|
||||
assert row["description"] == "<p>A fine walnut slab.</p>"
|
||||
assert row["content_source"] == "llm"
|
||||
|
||||
|
||||
def test_parse_call2_response_json_and_fenced():
|
||||
from backend.inference import parse_call2_response
|
||||
import json as _json
|
||||
|
||||
short, desc = parse_call2_response(
|
||||
_json.dumps({"short_description": " Benefit first. ", "description": " <p>Long</p> "})
|
||||
)
|
||||
assert short == "Benefit first."
|
||||
assert desc == "<p>Long</p>"
|
||||
fenced = "```json\n" + _json.dumps({"short_description": "S", "description": "<p>D</p>"}) + "\n```"
|
||||
short2, desc2 = parse_call2_response(fenced)
|
||||
assert short2 == "S"
|
||||
assert desc2 == "<p>D</p>"
|
||||
short3, desc3 = parse_call2_response("<p>only long</p>")
|
||||
assert short3 is None
|
||||
assert desc3 == "<p>only long</p>"
|
||||
|
||||
|
||||
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
|
||||
@@ -407,6 +484,13 @@ def test_assemble_call2_includes_declared_attrs_and_dims(env):
|
||||
assert "Brand voice: Warm and precise." in text
|
||||
assert "Geo: Pacific Northwest mill." in text
|
||||
assert CALL2_SEED.split("\n")[0] in text
|
||||
assert "SHORT DESCRIPTION" in text
|
||||
assert "LONG DESCRIPTION" in text
|
||||
assert "short_description" in CALL2_SEED
|
||||
assert '"description"' in CALL2_SEED or "\"description\"" in CALL2_SEED
|
||||
# Prior short must not be fed back into the prompt (Call 2 writes it).
|
||||
assert "short_description: short line" not in text
|
||||
assert "Write BOTH" in CALL2_SEED or "BOTH the short" in CALL2_SEED
|
||||
# No raw base64 in View-prompt shape
|
||||
assert "photos" in assembled
|
||||
assert assembled["photos"][0]["id"] == "p9"
|
||||
|
||||
Reference in New Issue
Block a user