"""Tests for TUI-safe logging configuration.""" import logging from app.utils.logging import setup_logging, setup_logging_for_tui class TestTuiLogging: def test_setup_logging_for_tui_removes_rich_handler(self) -> None: """TUI mode should have no RichHandler on root logger.""" from rich.logging import RichHandler # First set up normal logging (adds RichHandler) setup_logging() root = logging.getLogger() assert any(isinstance(h, RichHandler) for h in root.handlers) # Switch to TUI mode setup_logging_for_tui() root = logging.getLogger() assert not any(isinstance(h, RichHandler) for h in root.handlers) def test_setup_logging_for_tui_keeps_file_handler(self, tmp_path) -> None: """TUI mode should preserve file handler if configured.""" log_file = tmp_path / "test.log" setup_logging(log_file=log_file) setup_logging_for_tui() root = logging.getLogger() file_handlers = [h for h in root.handlers if isinstance(h, logging.FileHandler)] assert len(file_handlers) == 1