File size: 2,093 Bytes
0602b26 11c0f3a 0602b26 11c0f3a 0602b26 11c0f3a 0602b26 11c0f3a 4294178 11c0f3a 0602b26 11c0f3a 0602b26 11c0f3a 0602b26 11c0f3a 0602b26 11c0f3a 0602b26 11c0f3a 0602b26 11c0f3a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | """Safe default logging tests for the application runtime owner."""
import logging
from unittest.mock import patch
import pytest
from free_claude_code.config.settings import Settings
from free_claude_code.runtime.application import ApplicationRuntime, best_effort
from free_claude_code.runtime.provider_manager import ProviderRuntimeManager
@pytest.mark.asyncio
async def test_messaging_start_failure_default_logs_exclude_traceback(caplog):
settings = Settings().model_copy(
update={
"messaging_platform": "telegram",
"telegram_bot_token": "t",
"allowed_telegram_user_id": "1",
"log_api_error_tracebacks": False,
}
)
runtime = ApplicationRuntime(
ProviderRuntimeManager(settings),
transcriber=None,
)
with (
patch(
"free_claude_code.runtime.application.messaging_platform_factory.create_messaging_components",
side_effect=RuntimeError("SECRET_RUNTIME_DETAIL"),
),
caplog.at_level(logging.ERROR),
):
await runtime._start_messaging_if_configured()
blob = " | ".join(record.getMessage() for record in caplog.records)
assert "SECRET_RUNTIME_DETAIL" not in blob
assert "exc_type=RuntimeError" in blob
@pytest.mark.asyncio
async def test_best_effort_default_logs_exclude_exception_text(caplog):
async def boom():
raise ValueError("SECRET_SHUTDOWN")
with caplog.at_level(logging.WARNING):
await best_effort("test_step", boom(), log_verbose_errors=False)
blob = " | ".join(record.getMessage() for record in caplog.records)
assert "SECRET_SHUTDOWN" not in blob
assert "exc_type=ValueError" in blob
@pytest.mark.asyncio
async def test_best_effort_verbose_includes_exception_text(caplog):
async def boom():
raise ValueError("VISIBLE_SHUTDOWN")
with caplog.at_level(logging.WARNING):
await best_effort("test_step", boom(), log_verbose_errors=True)
blob = " | ".join(record.getMessage() for record in caplog.records)
assert "VISIBLE_SHUTDOWN" in blob
|