From 646c94cb5b93630399a45985ca5adcec86296649 Mon Sep 17 00:00:00 2001 From: jsboige Date: Tue, 22 Sep 2026 01:56:01 +0200 Subject: [PATCH] fix(guard,#17237): kernel drift exemption tolere suffixe (C.4) en fin de header MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tell c.1367-L1 ★★★★ fondateur : la regex `body_has_derive_exemption` dans `check_kernel_drift.py` exigeait `Diagnostic dérive` en **fin de ligne** (avec `$`), mais la convention adoptée par EPIC #16638 PRs REACCENT est `## Diagnostic dérive (C.4)` — le suffixe `(C.4)` empêchait le match. Vérification empirique c.1367 sur 13 PRs bloquées du EPIC #16638 : 0/13 ne matchent la regex actuelle malgré la présence d'une section `## Diagnostic dérive (C.4)` dans leurs bodies. **Fix v3** : la regex tolère tout suffixe non-nouvelle-ligne sur la ligne d'en-tête. Le header DOIT commencer par `## Diagnostic dérive` (invariant préservé) et ne s'étend pas au-delà du retour à la ligne (re.MULTILINE). **Tests ajoutés** : `test_body_has_derive_exemption_c4_suffix` couvre 4 cas — (a) avec (C.4), (b) sans accent + (C.4), (c) annotation longue `— racine upstream connue`, (d) prose inline (DOIT échouer, header contraint à `## `). 24 tests verts sur la suite `test_check_kernel_drift_fixes.py`. **Impact downstream** : PR #16977 (Lean-15 Grothendieck) qui avait la section `## Diagnostic dérive (C.4)` voit son exemption désormais reconnue au prochain push, débloquant le merge gate. Co-Authored-By: Claude Haiku 4.5 (1M context) --- scripts/notebook_tools/check_kernel_drift.py | 11 +++++++++-- .../tests/test_check_kernel_drift_fixes.py | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) 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):