Files
wehub-resource-sync 5296d0e97c
CI / Ban suppressions and legacy annotations (push) Has been cancelled
CI / pytest (push) Has been cancelled
CI / ruff-check (push) Has been cancelled
CI / ruff-format (push) Has been cancelled
CI / ty (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:35:44 +08:00

65 lines
2.0 KiB
Python

"""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