"""Permission guard (D-7, plan step 1.5): nothing reads v1 perm_* attributes any more. Permissions are keys checked with core.access (holds/can/require). The v1 projection (core/access/legacy.py) is gone since step 2.99; only migrations still name the columns. """ import ast from pathlib import Path BACKEND = Path(__file__).resolve().parents[2] ALLOWED: set[str] = set() def test_no_perm_attribute_reads(): bad = [] for f in sorted(BACKEND.rglob("*.py")): rel = f.relative_to(BACKEND).as_posix() if rel.startswith(("tests/", "migrations/")) or "__pycache__" in rel or rel in ALLOWED: continue for node in ast.walk(ast.parse(f.read_text(encoding="utf-8"))): if isinstance(node, ast.Attribute) and (node.attr.startswith("perm_") or node.attr == "can_cancel_orders"): bad.append(f"{rel}:{node.lineno}: .{node.attr}") assert bad == [], "use core.access.check.holds()/can() instead:\n" + "\n".join(bad)