Skip to content

Commit c1230b7

Browse files
committed
fix(cli): garantir une sortie JSON sans bruit pour les commandes engine
1 parent 7804e6e commit c1230b7

3 files changed

Lines changed: 29 additions & 6 deletions

File tree

OnlyMod/EngineOnlyMod/app.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ class MockGUI:
7272
en mode standalone sans l'application complète.
7373
"""
7474

75-
def __init__(self, workspace_dir: Optional[str] = None):
75+
def __init__(self, workspace_dir: Optional[str] = None, log_echo: bool = True):
7676
self.workspace_dir = (
7777
os.path.abspath(str(workspace_dir)) if workspace_dir else workspace_dir
7878
)
79-
self.log = MockLog()
79+
self.log = MockLog(echo=log_echo)
8080
self._tr = {}
8181
self.venv_path_manuel = None
8282
self.venv_path = None
@@ -120,13 +120,15 @@ def _init_venv_context(self) -> None:
120120
class MockLog:
121121
"""Mock log object qui collecte les messages pour affichage."""
122122

123-
def __init__(self):
123+
def __init__(self, echo: bool = True):
124124
self.messages: List[str] = []
125+
self._echo = bool(echo)
125126

126127
def append(self, message: str) -> None:
127128
"""Ajoute un message au log."""
128129
self.messages.append(message)
129-
print(message)
130+
if self._echo:
131+
print(message)
130132

131133
def clear(self) -> None:
132134
"""Efface le log."""
@@ -385,6 +387,7 @@ def __init__(
385387
theme: str = "dark",
386388
dry_run: bool = False,
387389
headless: bool = False,
390+
quiet_logs: bool = False,
388391
):
389392
"""
390393
Initialise l'application standalone engines.
@@ -397,8 +400,9 @@ def __init__(
397400
theme: Nom du thème ('light' ou 'dark')
398401
dry_run: Si True, affiche uniquement la commande sans exécuter
399402
headless: Si True, fonctionne sans interface GUI (mode CLI)
403+
quiet_logs: Disable stdout log echo (used for strict JSON payload mode)
400404
"""
401-
self.gui = MockGUI(workspace_dir)
405+
self.gui = MockGUI(workspace_dir, log_echo=not bool(quiet_logs))
402406
self.language_manager = LanguageManager()
403407
self.theme_manager = ThemeManager()
404408

cli/click_app.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,7 @@ def engine_dry_run(engine_id, file_path, workspace, as_json):
590590
theme="dark",
591591
headless=True,
592592
dry_run=True,
593+
quiet_logs=bool(as_json),
593594
)
594595
result = app.run_compilation(engine_id, str(Path(file_path)), dry_run=True)
595596
if as_json:
@@ -617,6 +618,7 @@ def engine_compile(engine_id, file_path, workspace, as_json):
617618
language="en",
618619
theme="dark",
619620
headless=True,
621+
quiet_logs=bool(as_json),
620622
)
621623
result = app.run_compilation(engine_id, str(Path(file_path)), dry_run=False)
622624
if as_json:

tests/test_engine_standalone_required_tools.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from pathlib import Path
77

8-
from OnlyMod.EngineOnlyMod.app import EnginesStandaloneApp
8+
from OnlyMod.EngineOnlyMod.app import EnginesStandaloneApp, MockLog
99

1010

1111
class _DummyEngine:
@@ -78,3 +78,20 @@ def test_run_compilation_headless_returns_preflight_error(monkeypatch) -> None:
7878
assert result["success"] is False
7979
assert result["return_code"] == -1
8080
assert "preflight failed" in result["error"]
81+
82+
83+
def test_mock_log_can_disable_stdout_echo(monkeypatch) -> None:
84+
called = {"n": 0}
85+
86+
def _fake_print(*_args, **_kwargs):
87+
called["n"] += 1
88+
89+
monkeypatch.setattr("builtins.print", _fake_print)
90+
91+
silent_log = MockLog(echo=False)
92+
silent_log.append("hello")
93+
94+
loud_log = MockLog(echo=True)
95+
loud_log.append("world")
96+
97+
assert called["n"] == 1

0 commit comments

Comments
 (0)