chore: linting

This commit is contained in:
DESKTOP-RTLN3BA\$punk 2026-06-09 00:42:26 -07:00
parent 0a012dbc79
commit ce952d2ad1
127 changed files with 821 additions and 517 deletions

View file

@ -137,7 +137,10 @@ class TestPluginLoaderIsolation:
_FakeEntryPoint("crashing", crashing_factory),
_FakeEntryPoint("ok", year_substituter_factory),
]
with patch("app.agents.chat.multi_agent_chat.main_agent.plugins.loader.entry_points", return_value=eps):
with patch(
"app.agents.chat.multi_agent_chat.main_agent.plugins.loader.entry_points",
return_value=eps,
):
result = load_plugin_middlewares(
_ctx(), allowed_plugin_names={"crashing", "ok"}
)

View file

@ -5,8 +5,7 @@ import asyncio
import pytest
import pytest_asyncio
from app.gateway import byo_long_poll
from app.gateway import runner
from app.gateway import byo_long_poll, runner
class ScalarResult:
@ -48,7 +47,9 @@ async def test_start_byo_long_poll_noops_when_mode_is_webhook(monkeypatch):
@pytest.mark.asyncio
async def test_start_byo_long_poll_noops_when_no_byo_accounts(mocker, monkeypatch):
monkeypatch.setattr(byo_long_poll.config, "GATEWAY_TELEGRAM_INTAKE_MODE", "longpoll")
monkeypatch.setattr(
byo_long_poll.config, "GATEWAY_TELEGRAM_INTAKE_MODE", "longpoll"
)
session = mocker.AsyncMock()
session.execute.return_value = ScalarResult([])
monkeypatch.setattr(
@ -63,8 +64,12 @@ async def test_start_byo_long_poll_noops_when_no_byo_accounts(mocker, monkeypatc
@pytest.mark.asyncio
async def test_start_byo_long_poll_spawns_one_supervisor_per_account(mocker, monkeypatch):
monkeypatch.setattr(byo_long_poll.config, "GATEWAY_TELEGRAM_INTAKE_MODE", "longpoll")
async def test_start_byo_long_poll_spawns_one_supervisor_per_account(
mocker, monkeypatch
):
monkeypatch.setattr(
byo_long_poll.config, "GATEWAY_TELEGRAM_INTAKE_MODE", "longpoll"
)
accounts = [mocker.Mock(id=1), mocker.Mock(id=2)]
session = mocker.AsyncMock()
session.execute.return_value = ScalarResult(accounts)
@ -73,7 +78,9 @@ async def test_start_byo_long_poll_spawns_one_supervisor_per_account(mocker, mon
"async_session_maker",
lambda: SessionContext(session),
)
monkeypatch.setattr(byo_long_poll, "account_token", lambda account: f"token-{account.id}")
monkeypatch.setattr(
byo_long_poll, "account_token", lambda account: f"token-{account.id}"
)
async def forever(_account_id: int, _token: str) -> None:
await asyncio.Event().wait()
@ -108,7 +115,9 @@ async def test_supervisor_retries_after_run_returns(mocker, monkeypatch):
@pytest.mark.asyncio
async def test_shutdown_cancels_running_supervisors(mocker, monkeypatch):
monkeypatch.setattr(byo_long_poll.config, "GATEWAY_TELEGRAM_INTAKE_MODE", "longpoll")
monkeypatch.setattr(
byo_long_poll.config, "GATEWAY_TELEGRAM_INTAKE_MODE", "longpoll"
)
session = mocker.AsyncMock()
session.execute.return_value = ScalarResult([mocker.Mock(id=1)])
monkeypatch.setattr(
@ -130,7 +139,9 @@ async def test_shutdown_cancels_running_supervisors(mocker, monkeypatch):
@pytest.mark.asyncio
async def test_run_telegram_account_persists_for_fastapi_inbox_worker(mocker, monkeypatch):
async def test_run_telegram_account_persists_for_fastapi_inbox_worker(
mocker, monkeypatch
):
class ConnectionContext:
async def __aenter__(self):
conn = mocker.AsyncMock()
@ -169,4 +180,3 @@ async def test_run_telegram_account_persists_for_fastapi_inbox_worker(mocker, mo
second_session.commit.assert_awaited_once()
persist.assert_awaited_once()
assert persist.await_args.kwargs["request_id"].startswith("gateway_")

View file

@ -5,7 +5,9 @@ from app.tasks.celery_tasks import gateway_tasks
def test_enqueue_received_sweep_is_noop_guard(mocker):
apply_async = mocker.Mock()
mocker.patch.object(gateway_tasks.process_inbound_event_task, "apply_async", apply_async)
mocker.patch.object(
gateway_tasks.process_inbound_event_task, "apply_async", apply_async
)
info = mocker.patch.object(gateway_tasks.logger, "info")
replayed = gateway_tasks.enqueue_received_sweep_task.run()
@ -13,4 +15,3 @@ def test_enqueue_received_sweep_is_noop_guard(mocker):
apply_async.assert_not_called()
assert replayed == 0
info.assert_called_once()

View file

@ -15,4 +15,3 @@ def test_chunk_message_preserves_content_and_limits_size():
assert "".join(chunks) == text
assert len(chunks) > 1
assert all(len(chunk.encode("utf-16-le")) // 2 <= 4096 for chunk in chunks)

View file

@ -12,4 +12,3 @@ def test_filter_hitl_tools_removes_known_approval_tools():
filtered = filter_hitl_tools(tools)
assert [getattr(tool, "name", tool) for tool in filtered] == ["search", "summarize"]

View file

@ -8,7 +8,9 @@ from app.gateway import inbox_worker
@pytest.mark.asyncio
async def test_inbox_worker_claims_and_processes_in_fastapi_process(mocker, monkeypatch):
async def test_inbox_worker_claims_and_processes_in_fastapi_process(
mocker, monkeypatch
):
claim = mocker.AsyncMock(return_value=7)
process = mocker.AsyncMock(side_effect=asyncio.CancelledError)
monkeypatch.setattr(inbox_worker, "claim_next_inbound_event", claim)
@ -42,4 +44,3 @@ async def test_start_stop_gateway_inbox_worker(mocker, monkeypatch):
assert stopped.is_set()
assert inbox_worker._task is None

View file

@ -38,4 +38,3 @@ async def test_redeem_pairing_code_binds_pending_row(mocker):
assert binding.state == ExternalChatBindingState.BOUND
assert binding.external_peer_id == "telegram:123"
assert binding.pairing_code is None

View file

@ -9,5 +9,6 @@ def test_process_inbound_event_task_is_noop_guard(mocker):
assert gateway_tasks.process_inbound_event_task.run(123) is None
warning.assert_called_once()
assert "FastAPI owns external chat agent turn processing" in warning.call_args.args[0]
assert (
"FastAPI owns external chat agent turn processing" in warning.call_args.args[0]
)

View file

@ -23,7 +23,9 @@ def _enable_gateways(monkeypatch):
monkeypatch.setattr(routes.config, "GATEWAY_TELEGRAM_INTAKE_MODE", "webhook")
monkeypatch.setattr(routes.config, "TELEGRAM_SHARED_BOT_TOKEN", "telegram-token")
monkeypatch.setattr(routes.config, "TELEGRAM_SHARED_BOT_USERNAME", "surf_bot")
monkeypatch.setattr(routes.config, "TELEGRAM_WEBHOOK_SECRET", "telegram-webhook-secret")
monkeypatch.setattr(
routes.config, "TELEGRAM_WEBHOOK_SECRET", "telegram-webhook-secret"
)
monkeypatch.setattr(routes.config, "GATEWAY_SLACK_ENABLED", True)
monkeypatch.setattr(routes.config, "GATEWAY_SLACK_CLIENT_ID", "slack-client")
@ -37,7 +39,9 @@ def _enable_gateways(monkeypatch):
class RequestStub:
def __init__(self, payload=None, *, headers=None, json_exc: Exception | None = None):
def __init__(
self, payload=None, *, headers=None, json_exc: Exception | None = None
):
self.headers = headers or {}
self._payload = payload
self._json_exc = json_exc
@ -70,7 +74,9 @@ def _slack_account() -> ExternalChatAccount:
)
def _signed_slack_request(payload: dict, *, secret: str = "signing-secret") -> RequestStub:
def _signed_slack_request(
payload: dict, *, secret: str = "signing-secret"
) -> RequestStub:
body = json.dumps(payload).encode()
timestamp = str(int(time.time()))
digest = hmac.new(
@ -195,7 +201,9 @@ async def test_telegram_webhook_persists_for_fastapi_inbox_worker(mocker, monkey
async def test_telegram_webhook_commits_dedup_without_enqueue(mocker, monkeypatch):
session = mocker.AsyncMock()
session.get.return_value = _account()
monkeypatch.setattr(routes, "persist_inbound_event", mocker.AsyncMock(return_value=None))
monkeypatch.setattr(
routes, "persist_inbound_event", mocker.AsyncMock(return_value=None)
)
request = RequestStub(
{"update_id": 10, "message": {"message_id": 7}},
@ -250,7 +258,11 @@ async def test_slack_webhook_url_verification(monkeypatch, mocker):
async def test_slack_webhook_persists_event(monkeypatch, mocker):
_enable_slack_gateway(monkeypatch)
session = mocker.AsyncMock()
monkeypatch.setattr(routes, "get_slack_account_by_team", mocker.AsyncMock(return_value=_slack_account()))
monkeypatch.setattr(
routes,
"get_slack_account_by_team",
mocker.AsyncMock(return_value=_slack_account()),
)
persist = mocker.AsyncMock(return_value=100)
monkeypatch.setattr(routes, "persist_inbound_event", persist)
payload = {
@ -280,7 +292,11 @@ async def test_slack_webhook_persists_event(monkeypatch, mocker):
async def test_slack_webhook_ignores_self_event(monkeypatch, mocker):
_enable_slack_gateway(monkeypatch)
session = mocker.AsyncMock()
monkeypatch.setattr(routes, "get_slack_account_by_team", mocker.AsyncMock(return_value=_slack_account()))
monkeypatch.setattr(
routes,
"get_slack_account_by_team",
mocker.AsyncMock(return_value=_slack_account()),
)
persist = mocker.AsyncMock(return_value=100)
monkeypatch.setattr(routes, "persist_inbound_event", persist)
request = _signed_slack_request(
@ -331,4 +347,3 @@ def test_discord_gateway_callback_does_not_create_search_source_connector():
callback_source = inspect.getsource(routes.discord_gateway_callback)
assert "SearchSourceConnector" not in callback_source

View file

@ -81,7 +81,9 @@ class TestCwdDefaults:
class TestRelativePathResolution:
def test_relative_path_resolves_against_cwd(self):
assert (
resolve_relative(_mw(), "notes.md", _runtime({"cwd": "/documents/projects"}))
resolve_relative(
_mw(), "notes.md", _runtime({"cwd": "/documents/projects"})
)
== "/documents/projects/notes.md"
)
@ -281,7 +283,11 @@ class TestNormalizeLocalMountPath:
_desktop_mw(backend),
"/brand-new-note.md",
_runtime(
{"file_operation_contract": {"suggested_path": "/root_b/notes/context.md"}}
{
"file_operation_contract": {
"suggested_path": "/root_b/notes/context.md"
}
}
),
)
assert resolved == "/root_b/brand-new-note.md"

View file

@ -15,7 +15,9 @@ from unittest.mock import AsyncMock
import numpy as np
import pytest
from app.agents.chat.multi_agent_chat.main_agent.middleware.kb_persistence import middleware as kb_persistence
from app.agents.chat.multi_agent_chat.main_agent.middleware.kb_persistence import (
middleware as kb_persistence,
)
from app.db import Document

View file

@ -21,7 +21,9 @@ from unittest.mock import AsyncMock, MagicMock
import pytest
from app.agents.chat.multi_agent_chat.main_agent.middleware.kb_persistence import middleware as kb_persistence
from app.agents.chat.multi_agent_chat.main_agent.middleware.kb_persistence import (
middleware as kb_persistence,
)
pytestmark = pytest.mark.unit

View file

@ -261,7 +261,8 @@ class TestKnowledgePriorityMiddlewarePlanner:
return []
monkeypatch.setattr(
ks, "search_knowledge_base",
ks,
"search_knowledge_base",
fake_search_knowledge_base,
)
@ -304,7 +305,8 @@ class TestKnowledgePriorityMiddlewarePlanner:
return []
monkeypatch.setattr(
ks, "search_knowledge_base",
ks,
"search_knowledge_base",
fake_search_knowledge_base,
)
@ -333,7 +335,8 @@ class TestKnowledgePriorityMiddlewarePlanner:
return []
monkeypatch.setattr(
ks, "search_knowledge_base",
ks,
"search_knowledge_base",
fake_search_knowledge_base,
)
@ -378,11 +381,13 @@ class TestKnowledgePriorityMiddlewarePlanner:
return []
monkeypatch.setattr(
ks, "browse_recent_documents",
ks,
"browse_recent_documents",
fake_browse_recent_documents,
)
monkeypatch.setattr(
ks, "search_knowledge_base",
ks,
"search_knowledge_base",
fake_search_knowledge_base,
)
@ -425,11 +430,13 @@ class TestKnowledgePriorityMiddlewarePlanner:
return []
monkeypatch.setattr(
ks, "browse_recent_documents",
ks,
"browse_recent_documents",
fake_browse_recent_documents,
)
monkeypatch.setattr(
ks, "search_knowledge_base",
ks,
"search_knowledge_base",
fake_search_knowledge_base,
)
@ -552,11 +559,13 @@ class TestKnowledgePriorityMentionDrain:
return []
monkeypatch.setattr(
ks, "fetch_mentioned_documents",
ks,
"fetch_mentioned_documents",
fake_fetch_mentioned_documents,
)
monkeypatch.setattr(
ks, "search_knowledge_base",
ks,
"search_knowledge_base",
fake_search_knowledge_base,
)
@ -600,11 +609,13 @@ class TestKnowledgePriorityMentionDrain:
return []
monkeypatch.setattr(
ks, "fetch_mentioned_documents",
ks,
"fetch_mentioned_documents",
fake_fetch_mentioned_documents,
)
monkeypatch.setattr(
ks, "search_knowledge_base",
ks,
"search_knowledge_base",
fake_search_knowledge_base,
)
@ -645,11 +656,13 @@ class TestKnowledgePriorityMentionDrain:
return []
monkeypatch.setattr(
ks, "fetch_mentioned_documents",
ks,
"fetch_mentioned_documents",
fake_fetch_mentioned_documents,
)
monkeypatch.setattr(
ks, "search_knowledge_base",
ks,
"search_knowledge_base",
fake_search_knowledge_base,
)

View file

@ -50,18 +50,18 @@ class TestParseBeforeDate:
def _notification(**overrides) -> Notification:
defaults = dict(
id=1,
user_id=uuid.uuid4(),
search_space_id=3,
type="document_processing",
title="Title",
message="Message",
read=False,
notification_metadata={"k": "v"},
created_at=datetime(2024, 1, 1, tzinfo=UTC),
updated_at=datetime(2024, 1, 2, tzinfo=UTC),
)
defaults = {
"id": 1,
"user_id": uuid.uuid4(),
"search_space_id": 3,
"type": "document_processing",
"title": "Title",
"message": "Message",
"read": False,
"notification_metadata": {"k": "v"},
"created_at": datetime(2024, 1, 1, tzinfo=UTC),
"updated_at": datetime(2024, 1, 2, tzinfo=UTC),
}
defaults.update(overrides)
return Notification(**defaults)

View file

@ -16,7 +16,9 @@ def test_operation_id_encodes_search_space():
def test_summary_title_and_message():
"""The summary states the document and the used/limit page counts."""
title, message = msg.summary("short.pdf", pages_used=95, pages_limit=100, pages_to_add=10)
title, message = msg.summary(
"short.pdf", pages_used=95, pages_limit=100, pages_to_add=10
)
assert title == "Page limit exceeded: short.pdf"
assert message == (
"This document has ~10 page(s) but you've used 95/100 pages. "