diff --git a/scripts/notebook_tools/check_kernel_drift.py b/scripts/notebook_tools/check_kernel_drift.py index 3dc1a63f66..afebbfd025 100644 --- a/scripts/notebook_tools/check_kernel_drift.py +++ b/scripts/notebook_tools/check_kernel_drift.py @@ -198,12 +198,19 @@ def body_has_derive_exemption(body): tolerates the unaccented 'derive' (covers authors who type the header without the accent, a common shortcut when reviewing on a non-French keyboard layout). + + Fix v3 (c.1367): regex tolerates an optional trailing token on the + header line (e.g. ``(C.4)``). The convention adopted in EPIC #16638 PRs + REACCENT was ``## Diagnostic dérive (C.4)`` — the v2 regex required + end-of-line after the word, silently rejecting the suffix as a non-match + despite carrying the same C.4 acknowledgement intent. """ if not body: return False - # Case-insensitive header, optional whitespace, optional accent on 'e'. + # Case-insensitive header, optional whitespace, optional accent on 'e', + # optional trailing token (e.g. "(C.4)") on the same line. pattern = re.compile( - r"^##\s*Diagnostic\s*d[ée]rive\s*$", + r"^##\s*Diagnostic\s*d[ée]rive\b[^\n]*$", re.MULTILINE | re.IGNORECASE, ) return bool(pattern.search(body)) diff --git a/scripts/notebook_tools/tests/test_check_kernel_drift_fixes.py b/scripts/notebook_tools/tests/test_check_kernel_drift_fixes.py index 89934809de..2988069a8a 100644 --- a/scripts/notebook_tools/tests/test_check_kernel_drift_fixes.py +++ b/scripts/notebook_tools/tests/test_check_kernel_drift_fixes.py @@ -297,6 +297,25 @@ def test_body_has_derive_exemption_unaccented(): assert ckd.body_has_derive_exemption(body) is True +def test_body_has_derive_exemption_c4_suffix(): + """Fix v3 (c.1367): regex tolerates an optional trailing token on the + header line, such as ``(C.4)``. EPIC #16638 PRs REACCENT use this form + systematically; the v2 regex rejected it silently. + """ + body = "## Diagnostic dérive (C.4)\nblah\n" + assert ckd.body_has_derive_exemption(body) is True + # Same with unaccented derive and parenthetical + body = "## Diagnostic derive (C.4)\nblah\n" + assert ckd.body_has_derive_exemption(body) is True + # Trailing token after a longer annotation must also pass + body = "## Diagnostic dérive — racine upstream connue\nblah\n" + assert ckd.body_has_derive_exemption(body) is True + # Header MUST begin with '## Diagnostic dérive' — a body that only + # contains 'dérive' in prose should not match. + body = "Some prose mentioning Diagnostic dérive (C.4) inline\n" + assert ckd.body_has_derive_exemption(body) is False + + # === Defect 1 v2: end-to-end branchement test (PR_BODY_FILE -> _run() -> exit 0) === def test_run_reads_pr_body_file_and_exempts(tmp_path, monkeypatch, capsys):