mirror of
https://github.com/Alishahryar1/free-claude-code.git
synced 2026-04-26 10:31:07 +00:00
Some checks are pending
CI / checks (push) Waiting to run
Consolidates the incremental refactor work into a single change set: modular web tools (api/web_tools), native Anthropic request building and SSE block policy, OpenAI conversion and error handling, provider transports and rate limiting, messaging handler and tree queue, safe logging, smoke tests, and broad test coverage.
70 lines
2.2 KiB
Python
70 lines
2.2 KiB
Python
"""Tests for safe default logging in :mod:`api.runtime`."""
|
|
|
|
import importlib
|
|
import logging
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
import pytest
|
|
|
|
from tests.api.test_app_lifespan_and_errors import _app_settings
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_messaging_start_failure_default_logs_exclude_traceback(caplog):
|
|
api_runtime_mod = importlib.import_module("api.runtime")
|
|
settings = _app_settings(
|
|
messaging_platform="telegram",
|
|
telegram_bot_token="t",
|
|
allowed_telegram_user_id="1",
|
|
discord_bot_token=None,
|
|
allowed_discord_channels=None,
|
|
allowed_dir="",
|
|
claude_workspace="./agent_workspace",
|
|
host="127.0.0.1",
|
|
port=8082,
|
|
log_file="server.log",
|
|
log_api_error_tracebacks=False,
|
|
)
|
|
runtime = api_runtime_mod.AppRuntime(app=MagicMock(), settings=settings)
|
|
|
|
with (
|
|
patch(
|
|
"messaging.platforms.factory.create_messaging_platform",
|
|
side_effect=RuntimeError("SECRET_RUNTIME_DETAIL"),
|
|
),
|
|
caplog.at_level(logging.ERROR),
|
|
):
|
|
await runtime._start_messaging_if_configured()
|
|
|
|
blob = " | ".join(r.getMessage() for r 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):
|
|
api_runtime_mod = importlib.import_module("api.runtime")
|
|
|
|
async def boom():
|
|
raise ValueError("SECRET_SHUTDOWN")
|
|
|
|
with caplog.at_level(logging.WARNING):
|
|
await api_runtime_mod.best_effort("test_step", boom(), log_verbose_errors=False)
|
|
|
|
blob = " | ".join(r.getMessage() for r 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):
|
|
api_runtime_mod = importlib.import_module("api.runtime")
|
|
|
|
async def boom():
|
|
raise ValueError("VISIBLE_SHUTDOWN")
|
|
|
|
with caplog.at_level(logging.WARNING):
|
|
await api_runtime_mod.best_effort("test_step", boom(), log_verbose_errors=True)
|
|
|
|
blob = " | ".join(r.getMessage() for r in caplog.records)
|
|
assert "VISIBLE_SHUTDOWN" in blob
|