Major refactor: API, providers, messaging, and Anthropic protocol
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.
This commit is contained in:
Alishahryar1 2026-04-26 02:55:10 -07:00
parent b9ed704095
commit f3a7528d49
139 changed files with 7460 additions and 2422 deletions

View file

@ -0,0 +1,70 @@
"""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