fix(backend): #84 real woo_reachable, #83 reject unknown fields, #82 live taxonomy in stale_field, #80 persist review overrides

#84: /api/health woo_reachable is now a real check (GET /wp-json/ with a
3s timeout) instead of a hardcoded False stub. Version bumped to 0.5.0-m3-s1.

#83: POST /slabs rejects unknown (non-ALLOWED_FIELDS) keys with a 400
'unknown fields' error, instead of silently dropping them. The INSERT
binding count is now provably correct (no more assert needed).

#82: stale_field 422 error now returns the LIVE taxonomy ids
(SELECT id FROM table) as current_options, plus the field name and
submitted value, instead of echoing the submitted value back.

#80: regular review (no lock) persists owner overrides (price/sku/title/
short_description) from the payload to the DB via an UPDATE, so the
review endpoint is self-contained. server_rev is incremented on persist.

Tests: +3 (test_create_rejects_unknown_fields,
test_update_stale_field_returns_live_options,
test_review_persists_owner_overrides). 87/87 passing.
This commit is contained in:
Ty
2026-09-20 23:38:29 -07:00
parent 693719e85f
commit fe82133ca4
5 changed files with 113 additions and 8 deletions
+20 -3
View File
@@ -208,9 +208,12 @@ async def review_slab(slab_id: str, payload: dict[str, Any] | None = None) -> di
}
# --- Regular review (no lock): report ready/missing + suggested prose.
# #89: deterministic title/short_description are NOT set until an explicit
# lock; report the stored values (which stay empty until locked) so the UI
# shows them as pending, and never as "ready" from an unlocked AI draft.
# #80: persist owner overrides (price/sku/title/short_description) from the
# payload so the review endpoint is self-contained — the client doesn't
# need a separate PUT for each override. #89: deterministic
# title/short_description are NOT set until an explicit lock; report the
# stored values (which stay empty until locked) so the UI shows them as
# pending, and never as "ready" from an unlocked AI draft.
cats, terms = _taxonomy_lookup(conn)
primary_id = payload.get("primary_wood_category_id")
wood_cats = slab.get("wood_category_ids") or []
@@ -221,6 +224,20 @@ async def review_slab(slab_id: str, payload: dict[str, Any] | None = None) -> di
figure_term_ids = slab.get("figure_term_ids") or []
figure = terms.get(figure_term_ids[0], {}).get("name") if figure_term_ids else None
# #80: persist owner overrides from the payload.
overrides: dict[str, Any] = {}
for k in ("price", "sku", "title", "short_description"):
if k in payload and payload[k] is not None:
overrides[k] = payload[k]
if overrides:
set_clause = ", ".join(f"{k} = ?" for k in overrides)
conn.execute(
f"UPDATE slabs SET {set_clause}, server_rev=server_rev+1, updated_at=? WHERE id=?",
[*overrides.values(), _now(), slab_id],
)
conn.commit()
slab.update(overrides)
if not locked:
title = slab.get("title") or None
short_desc = slab.get("short_description") or None