"""Single source of truth for case priority/risk tiers (used by triage/classifier.py and reports/generate_report.py). Canonical mapping = QA's tiers (qa/test-strategy.md section 2): P1 / critical P2 / high P3 / medium P4 / low (bare digits 1-4 = P1-P4) High-risk = P1 or P2. Anything unrecognised -> None (untiered, not high-risk). """ from __future__ import annotations import re _WORDS = (("critical", "P1"), ("high", "P2"), ("medium", "P3"), ("low", "P4")) def tier(priority) -> str | None: s = str(priority if priority is not None else "").strip().lower() if not s: return None m = re.match(r"p\s*([1-4])\b", s) or re.match(r"([1-4])$", s) if m: return "P" + m.group(1) for word, t in _WORDS: if s.startswith(word): return t return None def is_high_risk(priority) -> bool: return tier(priority) in ("P1", "P2")