Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions scripts/notebook_tools/check_kernel_drift.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
19 changes: 19 additions & 0 deletions scripts/notebook_tools/tests/test_check_kernel_drift_fixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Loading