fix(gate): the plan-code guard catches bare sprint and phase codes, and the purge takes the P ones

The sprint alternative matched only `(S6)` or `S3e2`, so the commonest purged form (`# S6:`,
`S3's`, `"""S6 —`, `S1 justified`) and every phase code (`P1`) would come back unflagged; the phase
codes had in fact survived the purge in 16 lines (Plex client sections, the upload's header shape),
now reworded around them.

One pattern now covers epic, roadmap, sprint and phase codes; the named exceptions are TV episode
notation, a fixture's season or episode title (`title="S1"`) and ruff's `E4/E7/E9`, and a ruff rule
like `S110` does not match. The case test lists the purged forms and no longer claims every form.
audit_metrics copies the definition (ASCII, as JavaScript's \b is) and reports it as
plan_code_lines / plan_code_files.
This commit is contained in:
2026-10-05 00:50:36 +02:00
parent 5257d57196
commit 5ca2a0e6ee
10 changed files with 47 additions and 40 deletions
+11 -14
View File
@@ -27,12 +27,14 @@ BIG_FILE = 800
BE_COMPLEXITY = 10 # ruff's C901 default
FE_COMPLEXITY = 20 # the frontend's line
# what planCodes.contract.test.ts holds the code to: an epic (`E28`, `E9.5`) or a roadmap item (`R14`),
# not `E2E`, not a TV episode (`S2 · E5`); NOT_CODES are its named exceptions, cut first (an episode
# titled "E1", ruff's default `E4/E7/E9`)
EPIC_CODE = re.compile(r"\b(E\d{1,2}(\.\d+)?|R\d{1,2})\b(?!E)")
EPISODE = re.compile(r"S\d{1,2}\s?·?\s?E\d+")
NOT_CODES = re.compile(r'"E\d{1,2}"|\bE4/E7/E9\b')
# planCodes.contract.test.ts's definition, copied: an epic, roadmap item, sprint or phase code, or a
# review round; NOT_CODES are its named exceptions, cut first (TV episode notation, a fixture's
# season or episode title, ruff's default `E4/E7/E9`). ASCII, because JavaScript's `\b` is.
NOT_CODES = re.compile(r'\bS\d{1,2} ?·? ?E\d+|\btitle[=:] ?"[ES]\d{1,2}"|\bE4/E7/E9\b', re.ASCII)
PLAN_CODE = re.compile(
r"\b(?:E\d{1,2}(?:\.\d+)?|R\d{1,2}|S(?!3h\b)\d{1,2}(?:[a-z]\d?)?|P\d)\b|\b[Rr]ound[ -]\d|deep-review",
re.ASCII,
)
NARRATION = re.compile(r"\b(used to|no longer)\b", re.IGNORECASE)
@@ -116,17 +118,12 @@ def _complexity() -> dict[str, object]:
def _noise(be: list[tuple[Path, list[str]]], fe: list[tuple[Path, list[str]]]) -> dict[str, object]:
every = be + fe
epic = [
(p, ln)
for p, ls in every
for ln in ls
if EPIC_CODE.search(NOT_CODES.sub("", EPISODE.sub("", ln)))
]
plan = [(p, ln) for p, ls in every for ln in ls if PLAN_CODE.search(NOT_CODES.sub("", ln))]
be_c = sum(_comment_lines(ls, True) for _, ls in be)
fe_c = sum(_comment_lines(ls, False) for _, ls in fe)
return {
"epic_code_lines": len(epic),
"epic_code_files": len({p for p, _ in epic}),
"plan_code_lines": len(plan),
"plan_code_files": len({p for p, _ in plan}),
"history_narration_lines": sum(1 for _, ls in every for ln in ls if NARRATION.search(ln)),
"backend_comment_share": round(be_c / sum(len(ls) for _, ls in be), 3),
"frontend_comment_share": round(fe_c / sum(len(ls) for _, ls in fe), 3),