fix(m3): uuid secure-context fallback + middle-tier SKU business rules

- frontend: uuid() helper (crypto.randomUUID -> getRandomValues) for plain-HTTP LAN UAT
- slabs.py: empty SKU at create -> NULL (no-SKU-yet is transient, filled in Review)
- review.py: ready-gate enforces REVIEW-45 (SKU 3-24 alnum+hyphen) in the middle tier
- DB CHECK stays as backstop only (referential/structural), per layering principle
This commit is contained in:
Ty
2026-09-20 21:15:29 -07:00
parent c8d6d5eda0
commit e36979617b
6 changed files with 90 additions and 5 deletions
+12
View File
@@ -114,8 +114,20 @@ def missing_required(slab: dict) -> list[str]:
return [f for f in _REQUIRED if slab.get(f) in (None, "", [])]
# REVIEW-45: SKU is 3 to 24 chars, alphanumeric and hyphen only. The middle tier
# (not the DB CHECK) is the business-logic arbiter here; the DB constraint is a backstop.
_SKU_RE = re.compile(r"^[A-Za-z0-9-]{3,24}$")
def sku_valid(sku: Any) -> bool:
return isinstance(sku, str) and bool(_SKU_RE.match(sku))
def compute_ready(slab: dict) -> tuple[bool, list[str]]:
missing = missing_required(slab)
# A present-but-malformed SKU is not ready (business rule, enforced in the middle tier).
if "sku" not in missing and not sku_valid(slab.get("sku")):
missing.append("sku")
return (len(missing) == 0), missing