Download triage/ids.py from EnergyVenom/patchwise-agent-studio: direct link, hf CLI and curl.
- Browser
- Download file 1.89 kB
-
https://huggingface.co/spaces/EnergyVenom/patchwise-agent-studio/resolve/main/triage/ids.py
- Command line
-
hf download hf://spaces/EnergyVenom/patchwise-agent-studio/triage/ids.py
-
curl -L -o ids.py https://huggingface.co/spaces/EnergyVenom/patchwise-agent-studio/resolve/main/triage/ids.py
1.89 kB
| """Single shared place for case-ID and tag parsing (classifier, report, stand-in detection, tag parsing). | |
| Case IDs are module-neutral: <MODULE>-<AREA>[-<PART>...]-<NUMBER>, e.g. P2P-INV-006, O2C-ORD-012, R2R-JE-3, | |
| P2P-E2E-001, plus TC-<anything> (e.g. TC-001, TC_01). MODULE is 2-6 chars, starts with a letter | |
| (pattern [A-Z][A-Z0-9]{1,5}). | |
| """ | |
| from __future__ import annotations | |
| import re | |
| # Not preceded/followed by an ID character, so 'XP2P-INV-001' or 'P2P-INV-001X' do not match partially. | |
| CASE_ID_PATTERN = (r"(?<![A-Za-z0-9_-])(?:[A-Z][A-Z0-9]{1,5}(?:-[A-Z0-9]+)+-\d+|TC[-_][A-Za-z0-9]+(?:[-_][A-Za-z0-9]+)*)" | |
| r"(?![A-Za-z0-9_])") | |
| CASE_ID_RE = re.compile(CASE_ID_PATTERN) | |
| # Stand-in (substitute) markers: @stand-in, @standin, @substitute, or "stand-in" in a title. | |
| STANDIN_RE = re.compile(r"@?(?:stand[-_ ]?in|substitute)\b", re.I) | |
| def find_case_ids(text: str) -> list[str]: | |
| """All case IDs in text, in order, de-duplicated.""" | |
| return list(dict.fromkeys(m.group(0) for m in CASE_ID_RE.finditer(str(text or "")))) | |
| def first_case_id(text: str) -> str | None: | |
| ids = find_case_ids(text) | |
| return ids[0] if ids else None | |
| def tag_case_id(tag: str) -> str | None: | |
| """Case ID from a Playwright tag ('@P2P-INV-006' or 'O2C-ORD-001'); None if the tag is not an ID.""" | |
| t = str(tag or "").strip().lstrip("@") | |
| m = CASE_ID_RE.fullmatch(t) | |
| return m.group(0) if m else None | |
| def is_standin(text: str) -> bool: | |
| return bool(STANDIN_RE.search(str(text or ""))) | |
| def module_of(case_id: str) -> str | None: | |
| """'P2P-INV-006' -> 'P2P'; TC-style ids have no module -> None.""" | |
| if not case_id or re.match(r"TC[-_]", case_id): | |
| return None | |
| return case_id.split("-", 1)[0] | |
| def modules(case_ids) -> list[str]: | |
| return sorted({m for m in (module_of(c) for c in case_ids) if m}) | |