refactor(api): reduce compatibility and test noise

Make the fixed-session API surface explicit, document its usage, exclude api/ from core agent line counts, and remove implicit aiohttp pytest fixture dependencies from API tests.
This commit is contained in:
Xubin Ren 2026-03-30 15:05:06 +00:00
parent d9a5080d66
commit 5e99b81c6e

View File

@ -7,6 +7,7 @@ import json
from unittest.mock import AsyncMock, MagicMock
import pytest
import pytest_asyncio
from nanobot.api.server import (
API_CHAT_ID,
@ -18,7 +19,7 @@ from nanobot.api.server import (
)
try:
import aiohttp # noqa: F401
from aiohttp.test_utils import TestClient, TestServer
HAS_AIOHTTP = True
except ImportError:
@ -45,6 +46,23 @@ def app(mock_agent):
return create_app(mock_agent, model_name="test-model", request_timeout=10.0)
@pytest_asyncio.fixture
async def aiohttp_client():
clients: list[TestClient] = []
async def _make_client(app):
client = TestClient(TestServer(app))
await client.start_server()
clients.append(client)
return client
try:
yield _make_client
finally:
for client in clients:
await client.close()
def test_error_json() -> None:
resp = _error_json(400, "bad request")
assert resp.status == 400