From 2c9f0994fb000e2e31096699c5091684f096643e Mon Sep 17 00:00:00 2001 From: jsboige Date: Mon, 24 Aug 2026 16:39:39 +0200 Subject: [PATCH] =?UTF-8?q?fix(nb,#12585):=20detect=5Fcode=5Fin=5Fmarkdown?= =?UTF-8?q?=5Fcells=20--check=20desarme=20=E2=80=94=20le=20baseline=20cano?= =?UTF-8?q?nique=20devient=20le=20defaut=20+=20ligne=20identite?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Sonnet 4.6 (1M context) --- .../detect_code_in_markdown_cells.py | 17 ++++++++++- .../test_detect_code_in_markdown_cells.py | 28 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/scripts/notebook_tools/detect_code_in_markdown_cells.py b/scripts/notebook_tools/detect_code_in_markdown_cells.py index 92955a8acb..9181f0b7f8 100644 --- a/scripts/notebook_tools/detect_code_in_markdown_cells.py +++ b/scripts/notebook_tools/detect_code_in_markdown_cells.py @@ -140,6 +140,13 @@ def _finding_hash(f: dict[str, Any]) -> str: return hashlib.sha256(payload.encode("utf-8")).hexdigest()[:16] +# #12585 : le seul baseline du depot, celui que la CI passe explicitement. +# Un --check desarme (aucun baseline charge) rend un FAIL fantome sur un main +# vert -- toutes les violations acceptees ressortent « new ». Le default aligne +# l'invocation locale sur l'invocation CI. +DEFAULT_BASELINE = Path(__file__).resolve().parent / "code_in_markdown_cells_baseline.json" + + def load_baseline(path: Path) -> set[str]: if not path or not path.exists(): return set() @@ -450,7 +457,15 @@ def main(argv=None) -> int: print(f"baseline written: {len(hashes)} violations -> {args.baseline}") return 0 - baseline = load_baseline(args.baseline) if args.baseline else set() + # #12585 : --check/--report/--json sans --baseline comparent au baseline + # canonique, pas a un ensemble vide. --update-baseline exige toujours son + # chemin explicitement (garde ci-dessus). L'identite de la reference est + # affichee : un baseline vide et un baseline plein ne doivent plus rendre + # la meme forme de verdict. + baseline_path = args.baseline if args.baseline else DEFAULT_BASELINE + baseline = load_baseline(baseline_path) + if not args.update_baseline: + print(f"baseline: {baseline_path} ({len(baseline)} entries)") new_findings = [f for f in findings if _finding_hash(f) not in baseline] if baseline else findings diff --git a/scripts/notebook_tools/tests/test_detect_code_in_markdown_cells.py b/scripts/notebook_tools/tests/test_detect_code_in_markdown_cells.py index 7b6203bf14..de7d6301e4 100644 --- a/scripts/notebook_tools/tests/test_detect_code_in_markdown_cells.py +++ b/scripts/notebook_tools/tests/test_detect_code_in_markdown_cells.py @@ -188,6 +188,34 @@ def test_baseline_check_exits_zero_on_main(): ) +def test_check_without_baseline_defaults_to_canonical_rc0(): + """#12585 : ``--check`` SANS ``--baseline`` doit comparer au baseline + canonique du depot (celui que la CI passe), pas a un ensemble vide. + Avant le fix, l'invocation desarmee rendait un FAIL fantome sur un main + vert -- toutes les violations acceptees ressortaient « new ». Le test + existant passait le chemin explicitement, donc ne pouvait pas voir ce + defaut. Exige en outre la ligne d'identite qui nomme la reference.""" + import subprocess + proc = subprocess.run( + [ + sys.executable, str(TOOL), + "MyIA.AI.Notebooks", + "--check", + ], + capture_output=True, + text=True, + cwd=REPO_ROOT, + ) + assert proc.returncode == 0, ( + f"bare --check exited {proc.returncode}\n" + f"stdout: {proc.stdout[:500]}\nstderr: {proc.stderr[:500]}" + ) + assert "baseline:" in proc.stdout and "entries)" in proc.stdout, ( + "l'identite de la reference doit etre affichee " + f"(baseline: ( entries)); stdout: {proc.stdout[:300]}" + ) + + if __name__ == "__main__": import pytest sys.exit(pytest.main([__file__, "-v"]))