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:
@@ -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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user