mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-20 21:18:13 +02:00
chore: linting
This commit is contained in:
parent
0a012dbc79
commit
ce952d2ad1
127 changed files with 821 additions and 517 deletions
|
|
@ -140,7 +140,10 @@ def install(active_patches: list[Any]) -> None:
|
|||
"app.agents.chat.multi_agent_chat.shared.tools.mcp.tool.streamablehttp_client",
|
||||
_fake_streamablehttp_client,
|
||||
),
|
||||
("app.agents.chat.multi_agent_chat.shared.tools.mcp.tool.ClientSession", _FakeClientSession),
|
||||
(
|
||||
"app.agents.chat.multi_agent_chat.shared.tools.mcp.tool.ClientSession",
|
||||
_FakeClientSession,
|
||||
),
|
||||
]
|
||||
for target, replacement in targets:
|
||||
p = patch(target, replacement)
|
||||
|
|
|
|||
|
|
@ -135,8 +135,6 @@ async def test_agent_checkpoint_round_trips_across_turns(
|
|||
{"messages": [HumanMessage(content="second turn")]}, config
|
||||
)
|
||||
|
||||
texts = [
|
||||
m.content for m in second["messages"] if isinstance(m, HumanMessage)
|
||||
]
|
||||
texts = [m.content for m in second["messages"] if isinstance(m, HumanMessage)]
|
||||
assert "remember apple" in texts, "turn 1 history not reloaded from checkpoint"
|
||||
assert len(second["messages"]) > len(first["messages"])
|
||||
|
|
|
|||
|
|
@ -45,9 +45,7 @@ def _build_desktop_fs_mw(root: Path):
|
|||
"""Build the production filesystem middleware bound to a real local folder."""
|
||||
selection = FilesystemSelection(
|
||||
mode=FilesystemMode.DESKTOP_LOCAL_FOLDER,
|
||||
local_mounts=(
|
||||
LocalFilesystemMount(mount_id=_MOUNT_ID, root_path=str(root)),
|
||||
),
|
||||
local_mounts=(LocalFilesystemMount(mount_id=_MOUNT_ID, root_path=str(root)),),
|
||||
)
|
||||
resolver = build_backend_resolver(selection)
|
||||
return build_filesystem_mw(
|
||||
|
|
@ -157,7 +155,7 @@ async def test_write_then_ls_lists_file(tmp_path: Path):
|
|||
|
||||
async def test_edit_file_rewrites_on_disk(tmp_path: Path):
|
||||
"""edit_file applies a real string replacement to the on-disk file."""
|
||||
result = await _run(
|
||||
await _run(
|
||||
tmp_path,
|
||||
[
|
||||
ScriptedTurn(
|
||||
|
|
|
|||
|
|
@ -7,9 +7,7 @@ from app.indexing_pipeline.adapters.file_upload_adapter import UploadDocumentAda
|
|||
pytestmark = pytest.mark.integration
|
||||
|
||||
|
||||
@pytest.mark.usefixtures(
|
||||
"patched_embed_texts", "patched_chunk_text"
|
||||
)
|
||||
@pytest.mark.usefixtures("patched_embed_texts", "patched_chunk_text")
|
||||
async def test_sets_status_ready(db_session, db_search_space, db_user, mocker):
|
||||
"""Document status is READY after successful indexing."""
|
||||
adapter = UploadDocumentAdapter(db_session)
|
||||
|
|
@ -29,9 +27,7 @@ async def test_sets_status_ready(db_session, db_search_space, db_user, mocker):
|
|||
assert DocumentStatus.is_state(document.status, DocumentStatus.READY)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures(
|
||||
"patched_embed_texts", "patched_chunk_text"
|
||||
)
|
||||
@pytest.mark.usefixtures("patched_embed_texts", "patched_chunk_text")
|
||||
async def test_content_is_source_markdown(db_session, db_search_space, db_user, mocker):
|
||||
"""Document content is set to the extracted source markdown."""
|
||||
adapter = UploadDocumentAdapter(db_session)
|
||||
|
|
@ -51,9 +47,7 @@ async def test_content_is_source_markdown(db_session, db_search_space, db_user,
|
|||
assert document.content == "## Hello\n\nSome content."
|
||||
|
||||
|
||||
@pytest.mark.usefixtures(
|
||||
"patched_embed_texts", "patched_chunk_text"
|
||||
)
|
||||
@pytest.mark.usefixtures("patched_embed_texts", "patched_chunk_text")
|
||||
async def test_chunks_written_to_db(db_session, db_search_space, db_user, mocker):
|
||||
"""Chunks derived from the source markdown are persisted in the DB."""
|
||||
adapter = UploadDocumentAdapter(db_session)
|
||||
|
|
@ -98,9 +92,7 @@ async def test_raises_on_indexing_failure(db_session, db_search_space, db_user,
|
|||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
@pytest.mark.usefixtures(
|
||||
"patched_embed_texts", "patched_chunk_text"
|
||||
)
|
||||
@pytest.mark.usefixtures("patched_embed_texts", "patched_chunk_text")
|
||||
async def test_reindex_updates_content(db_session, db_search_space, db_user, mocker):
|
||||
"""Document content is updated to the new source markdown after reindexing."""
|
||||
adapter = UploadDocumentAdapter(db_session)
|
||||
|
|
@ -126,9 +118,7 @@ async def test_reindex_updates_content(db_session, db_search_space, db_user, moc
|
|||
assert document.content == "## Edited\n\nNew content after user edit."
|
||||
|
||||
|
||||
@pytest.mark.usefixtures(
|
||||
"patched_embed_texts", "patched_chunk_text"
|
||||
)
|
||||
@pytest.mark.usefixtures("patched_embed_texts", "patched_chunk_text")
|
||||
async def test_reindex_updates_content_hash(
|
||||
db_session, db_search_space, db_user, mocker
|
||||
):
|
||||
|
|
@ -157,9 +147,7 @@ async def test_reindex_updates_content_hash(
|
|||
assert document.content_hash != original_hash
|
||||
|
||||
|
||||
@pytest.mark.usefixtures(
|
||||
"patched_embed_texts", "patched_chunk_text"
|
||||
)
|
||||
@pytest.mark.usefixtures("patched_embed_texts", "patched_chunk_text")
|
||||
async def test_reindex_sets_status_ready(db_session, db_search_space, db_user, mocker):
|
||||
"""Document status is READY after successful reindexing."""
|
||||
adapter = UploadDocumentAdapter(db_session)
|
||||
|
|
@ -222,9 +210,7 @@ async def test_reindex_replaces_chunks(db_session, db_search_space, db_user, moc
|
|||
assert chunks[0].content == "Updated chunk."
|
||||
|
||||
|
||||
@pytest.mark.usefixtures(
|
||||
"patched_embed_texts", "patched_chunk_text"
|
||||
)
|
||||
@pytest.mark.usefixtures("patched_embed_texts", "patched_chunk_text")
|
||||
async def test_reindex_clears_reindexing_flag(
|
||||
db_session, db_search_space, db_user, mocker
|
||||
):
|
||||
|
|
|
|||
|
|
@ -34,9 +34,7 @@ def _cal_doc(
|
|||
)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures(
|
||||
"patched_embed_texts", "patched_chunk_text"
|
||||
)
|
||||
@pytest.mark.usefixtures("patched_embed_texts", "patched_chunk_text")
|
||||
async def test_calendar_pipeline_creates_ready_document(
|
||||
db_session, db_search_space, db_connector, db_user, mocker
|
||||
):
|
||||
|
|
@ -65,9 +63,7 @@ async def test_calendar_pipeline_creates_ready_document(
|
|||
assert DocumentStatus.is_state(row.status, DocumentStatus.READY)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures(
|
||||
"patched_embed_texts", "patched_chunk_text"
|
||||
)
|
||||
@pytest.mark.usefixtures("patched_embed_texts", "patched_chunk_text")
|
||||
async def test_calendar_legacy_doc_migrated(
|
||||
db_session, db_search_space, db_connector, db_user, mocker
|
||||
):
|
||||
|
|
|
|||
|
|
@ -33,9 +33,7 @@ def _drive_doc(
|
|||
)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures(
|
||||
"patched_embed_texts", "patched_chunk_text"
|
||||
)
|
||||
@pytest.mark.usefixtures("patched_embed_texts", "patched_chunk_text")
|
||||
async def test_drive_pipeline_creates_ready_document(
|
||||
db_session, db_search_space, db_connector, db_user, mocker
|
||||
):
|
||||
|
|
@ -64,9 +62,7 @@ async def test_drive_pipeline_creates_ready_document(
|
|||
assert DocumentStatus.is_state(row.status, DocumentStatus.READY)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures(
|
||||
"patched_embed_texts", "patched_chunk_text"
|
||||
)
|
||||
@pytest.mark.usefixtures("patched_embed_texts", "patched_chunk_text")
|
||||
async def test_drive_legacy_doc_migrated(
|
||||
db_session, db_search_space, db_connector, db_user, mocker
|
||||
):
|
||||
|
|
|
|||
|
|
@ -32,9 +32,7 @@ def _dropbox_doc(
|
|||
)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures(
|
||||
"patched_embed_texts", "patched_chunk_text"
|
||||
)
|
||||
@pytest.mark.usefixtures("patched_embed_texts", "patched_chunk_text")
|
||||
async def test_dropbox_pipeline_creates_ready_document(
|
||||
db_session, db_search_space, db_connector, db_user, mocker
|
||||
):
|
||||
|
|
@ -63,9 +61,7 @@ async def test_dropbox_pipeline_creates_ready_document(
|
|||
assert DocumentStatus.is_state(row.status, DocumentStatus.READY)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures(
|
||||
"patched_embed_texts", "patched_chunk_text"
|
||||
)
|
||||
@pytest.mark.usefixtures("patched_embed_texts", "patched_chunk_text")
|
||||
async def test_dropbox_duplicate_content_skipped(
|
||||
db_session, db_search_space, db_connector, db_user, mocker
|
||||
):
|
||||
|
|
|
|||
|
|
@ -36,9 +36,7 @@ def _gmail_doc(
|
|||
)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures(
|
||||
"patched_embed_texts", "patched_chunk_text"
|
||||
)
|
||||
@pytest.mark.usefixtures("patched_embed_texts", "patched_chunk_text")
|
||||
async def test_gmail_pipeline_creates_ready_document(
|
||||
db_session, db_search_space, db_connector, db_user, mocker
|
||||
):
|
||||
|
|
@ -68,9 +66,7 @@ async def test_gmail_pipeline_creates_ready_document(
|
|||
assert row.source_markdown == doc.source_markdown
|
||||
|
||||
|
||||
@pytest.mark.usefixtures(
|
||||
"patched_embed_texts", "patched_chunk_text"
|
||||
)
|
||||
@pytest.mark.usefixtures("patched_embed_texts", "patched_chunk_text")
|
||||
async def test_gmail_legacy_doc_migrated_then_reused(
|
||||
db_session, db_search_space, db_connector, db_user, mocker
|
||||
):
|
||||
|
|
|
|||
|
|
@ -9,9 +9,7 @@ from app.indexing_pipeline.indexing_pipeline_service import IndexingPipelineServ
|
|||
pytestmark = pytest.mark.integration
|
||||
|
||||
|
||||
@pytest.mark.usefixtures(
|
||||
"patched_embed_texts", "patched_chunk_text"
|
||||
)
|
||||
@pytest.mark.usefixtures("patched_embed_texts", "patched_chunk_text")
|
||||
async def test_index_batch_creates_ready_documents(
|
||||
db_session, db_search_space, make_connector_document, mocker
|
||||
):
|
||||
|
|
@ -49,9 +47,7 @@ async def test_index_batch_creates_ready_documents(
|
|||
assert row.embedding is not None
|
||||
|
||||
|
||||
@pytest.mark.usefixtures(
|
||||
"patched_embed_texts", "patched_chunk_text"
|
||||
)
|
||||
@pytest.mark.usefixtures("patched_embed_texts", "patched_chunk_text")
|
||||
async def test_index_batch_empty_returns_empty(db_session, mocker):
|
||||
"""index_batch with empty input returns an empty list."""
|
||||
service = IndexingPipelineService(session=db_session)
|
||||
|
|
|
|||
|
|
@ -32,9 +32,7 @@ def _onedrive_doc(
|
|||
)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures(
|
||||
"patched_embed_texts", "patched_chunk_text"
|
||||
)
|
||||
@pytest.mark.usefixtures("patched_embed_texts", "patched_chunk_text")
|
||||
async def test_onedrive_pipeline_creates_ready_document(
|
||||
db_session, db_search_space, db_connector, db_user, mocker
|
||||
):
|
||||
|
|
@ -63,9 +61,7 @@ async def test_onedrive_pipeline_creates_ready_document(
|
|||
assert DocumentStatus.is_state(row.status, DocumentStatus.READY)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures(
|
||||
"patched_embed_texts", "patched_chunk_text"
|
||||
)
|
||||
@pytest.mark.usefixtures("patched_embed_texts", "patched_chunk_text")
|
||||
async def test_onedrive_duplicate_content_skipped(
|
||||
db_session, db_search_space, db_connector, db_user, mocker
|
||||
):
|
||||
|
|
|
|||
|
|
@ -32,9 +32,7 @@ async def test_new_document_is_persisted_with_pending_status(
|
|||
assert reloaded.source_markdown == doc.source_markdown
|
||||
|
||||
|
||||
@pytest.mark.usefixtures(
|
||||
"patched_embed_texts", "patched_chunk_text"
|
||||
)
|
||||
@pytest.mark.usefixtures("patched_embed_texts", "patched_chunk_text")
|
||||
async def test_unchanged_ready_document_is_skipped(
|
||||
db_session,
|
||||
db_search_space,
|
||||
|
|
@ -55,9 +53,7 @@ async def test_unchanged_ready_document_is_skipped(
|
|||
assert results == []
|
||||
|
||||
|
||||
@pytest.mark.usefixtures(
|
||||
"patched_embed_texts", "patched_chunk_text"
|
||||
)
|
||||
@pytest.mark.usefixtures("patched_embed_texts", "patched_chunk_text")
|
||||
async def test_title_only_change_updates_title_in_db(
|
||||
db_session,
|
||||
db_search_space,
|
||||
|
|
|
|||
|
|
@ -47,7 +47,9 @@ async def test_comment_reply_truncates_long_preview(
|
|||
db_session: AsyncSession, db_user: User, db_search_space: SearchSpace
|
||||
):
|
||||
"""A long comment preview is truncated in the reply message."""
|
||||
notification = await _notify(db_session, db_user, db_search_space, preview="y" * 150)
|
||||
notification = await _notify(
|
||||
db_session, db_user, db_search_space, preview="y" * 150
|
||||
)
|
||||
|
||||
assert notification.message == "y" * 100 + "..."
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ from datetime import UTC, datetime, timedelta
|
|||
import pytest
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.db import SearchSpace, User
|
||||
from app.db import User
|
||||
from app.notifications.persistence import Notification
|
||||
|
||||
pytestmark = pytest.mark.integration
|
||||
|
|
|
|||
|
|
@ -47,7 +47,9 @@ async def test_new_mention_truncates_long_preview(
|
|||
db_session: AsyncSession, db_user: User, db_search_space: SearchSpace
|
||||
):
|
||||
"""A long comment preview is truncated in the mention message."""
|
||||
notification = await _notify(db_session, db_user, db_search_space, preview="x" * 150)
|
||||
notification = await _notify(
|
||||
db_session, db_user, db_search_space, preview="x" * 150
|
||||
)
|
||||
|
||||
assert notification.message == "x" * 100 + "..."
|
||||
|
||||
|
|
|
|||
|
|
@ -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"}
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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_")
|
||||
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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"]
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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. "
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue