From 0d8df3e8b84a0648b32a8f998ff02111c4dccd5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A9=E6=B5=B7=20=E5=8E=9F=20/=20Thaddeus=20Jiang?= Date: Tue, 25 Aug 2026 22:29:29 +0900 Subject: [PATCH] fix(logging): redact exception locals Closes: #292 --- src/bub/__main__.py | 4 ++-- tests/test_cli_help.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/bub/__main__.py b/src/bub/__main__.py index 8ee17b49..22fe9520 100644 --- a/src/bub/__main__.py +++ b/src/bub/__main__.py @@ -13,14 +13,14 @@ def _instrument_bub() -> None: from loguru import logger logger.remove() - logger.add(sys.stderr, colorize=True) + logger.add(sys.stderr, colorize=True, diagnose=False) try: import logfire from logfire.integrations.loguru import LogfireHandler logfire.configure() - logger.add(LogfireHandler(), format="{message}") + logger.add(LogfireHandler(), format="{message}", diagnose=False) except Exception as exc: logger.debug("logfire instrumentation disabled: {}", exc) diff --git a/tests/test_cli_help.py b/tests/test_cli_help.py index 79732a4b..acbf9b6e 100644 --- a/tests/test_cli_help.py +++ b/tests/test_cli_help.py @@ -1,6 +1,7 @@ from __future__ import annotations import pytest +from loguru import logger from bub.builtin.tools import show_help @@ -14,3 +15,16 @@ async def test_help_lists_correct_tool_names() -> None: assert ",bash_output" not in help_text assert ",kill_bash" not in help_text + + +def test_cli_instrumentation_disables_local_variable_diagnostics(monkeypatch: pytest.MonkeyPatch) -> None: + from bub.__main__ import _instrument_bub + + sink_options: list[dict[str, object]] = [] + monkeypatch.setattr(logger, "remove", lambda: None) + monkeypatch.setattr(logger, "add", lambda _sink, **options: sink_options.append(options)) + + _instrument_bub() + + assert sink_options + assert all(options.get("diagnose") is False for options in sink_options)