Skip to content

Commit e9e4adb

Browse files
committed
fix(gui): bloquer la compilation si BCASL echoue (fail-fast)
1 parent db9bf2d commit e9e4adb

2 files changed

Lines changed: 91 additions & 1 deletion

File tree

Core/Compiler/__init__.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,56 @@ def _run_bcasl_before_compile(self, on_done) -> None:
199199
pass
200200

201201

202+
def _bcasl_report_allows_compile(self, report) -> bool:
203+
"""Return True when BCASL pre-compile report allows compilation to continue."""
204+
# Sécurité fail-fast: si BCASL plante/échoue, on bloque la compilation.
205+
try:
206+
if report is None:
207+
log_i18n_level(
208+
self,
209+
"error",
210+
"BCASL a échoué ou n'a pas retourné de rapport. Compilation bloquée.",
211+
"BCASL failed or returned no report. Compilation blocked.",
212+
)
213+
return False
214+
215+
if isinstance(report, dict):
216+
status = str(report.get("status", "")).strip().lower()
217+
if status in {"disabled", "skipped"}:
218+
return True
219+
if "ok" in report:
220+
ok = bool(report.get("ok"))
221+
if not ok:
222+
log_i18n_level(
223+
self,
224+
"error",
225+
"BCASL a signalé un échec. Compilation bloquée.",
226+
"BCASL reported a failure. Compilation blocked.",
227+
)
228+
return ok
229+
return True
230+
231+
if hasattr(report, "ok"):
232+
ok = bool(getattr(report, "ok"))
233+
if not ok:
234+
log_i18n_level(
235+
self,
236+
"error",
237+
"BCASL a signalé des erreurs plugins. Compilation bloquée.",
238+
"BCASL reported plugin errors. Compilation blocked.",
239+
)
240+
return ok
241+
except Exception:
242+
log_i18n_level(
243+
self,
244+
"error",
245+
"Erreur lors de la validation du rapport BCASL. Compilation bloquée.",
246+
"Error while validating BCASL report. Compilation blocked.",
247+
)
248+
return False
249+
return True
250+
251+
202252
def compile_all(self) -> None:
203253
"""
204254
Slot connected to the compile button.
@@ -400,6 +450,9 @@ def _after_bcasl(_report=None) -> None:
400450
"Compilation cancelled before start (BCASL phase).",
401451
)
402452
return
453+
if not _bcasl_report_allows_compile(self, _report):
454+
self.set_controls_enabled(True)
455+
return
403456
try:
404457
log_i18n_level(
405458
self,
@@ -800,6 +853,10 @@ def _after_bcasl(_report=None) -> None:
800853
)
801854
result["value"] = False
802855
return
856+
if not _bcasl_report_allows_compile(self, _report):
857+
self.set_controls_enabled(True)
858+
result["value"] = False
859+
return
803860
ok = False
804861
try:
805862
ok = _do_start()

tests/test_compiler_smoke.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,47 @@ def fake_start(_self, _engine, files):
100100
compiler_module, "_get_main_process", lambda: DummyMainProcess()
101101
)
102102
monkeypatch.setattr(
103-
compiler_module, "_run_bcasl_before_compile", lambda _self, cb: cb(None)
103+
compiler_module,
104+
"_run_bcasl_before_compile",
105+
lambda _self, cb: cb({"status": "disabled"}),
104106
)
105107

106108
compiler_module.compile_all(gui)
107109

108110
assert captured.get("files") == [str(entry)]
109111

110112

113+
def test_compile_all_stops_when_bcasl_report_is_failure(test_workspace, monkeypatch) -> None:
114+
entry = test_workspace / "main.py"
115+
assert set_entrypoint(str(test_workspace), "main.py") is True
116+
117+
gui = DummyGUI()
118+
gui.workspace_dir = str(test_workspace)
119+
gui.python_files = [str(entry)]
120+
gui.selected_files = [str(entry)]
121+
122+
captured = {"started": False}
123+
124+
def fake_start(_self, _engine, _files):
125+
captured["started"] = True
126+
127+
monkeypatch.setattr(compiler_module, "_start_compilation_queue", fake_start)
128+
monkeypatch.setattr(compiler_module, "create", lambda _eid: DummyEngine())
129+
monkeypatch.setattr(
130+
compiler_module, "_get_main_process", lambda: DummyMainProcess()
131+
)
132+
monkeypatch.setattr(
133+
compiler_module,
134+
"_run_bcasl_before_compile",
135+
lambda _self, cb: cb({"ok": False, "error": "bcasl failed"}),
136+
)
137+
138+
compiler_module.compile_all(gui)
139+
140+
assert captured["started"] is False
141+
assert gui._controls_enabled is True
142+
143+
111144
def test_compilation_thread_warns_when_live_streams_are_unavailable() -> None:
112145
thread = CompilationThread(program="python", args=["-V"])
113146
warnings: list[str] = []

0 commit comments

Comments
 (0)