From cb440630813c3c557f450114d68b6a1acbf94299 Mon Sep 17 00:00:00 2001 From: CREDO23 Date: Thu, 4 Jun 2026 10:25:06 +0200 Subject: [PATCH] fix: repair pre-existing agent_task, gateway, and skills tests --- .../new_chat/middleware/skills_backends.py | 2 ++ .../builtin/agent_task/test_dependencies.py | 4 +-- .../tests/unit/gateway/test_webhook_routes.py | 27 ++++++++++++++++++- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/surfsense_backend/app/agents/new_chat/middleware/skills_backends.py b/surfsense_backend/app/agents/new_chat/middleware/skills_backends.py index 072d73401..dad22db50 100644 --- a/surfsense_backend/app/agents/new_chat/middleware/skills_backends.py +++ b/surfsense_backend/app/agents/new_chat/middleware/skills_backends.py @@ -121,6 +121,8 @@ class BuiltinSkillsBackend(BackendProtocol): else ("/" + str(target.relative_to(self.root)).replace("\\", "/")) ) for child in sorted(target.iterdir()): + if child.name == "__pycache__" or child.name.startswith("."): + continue child_virtual = ( target_virtual.rstrip("/") + "/" + child.name if target_virtual != "/" diff --git a/surfsense_backend/tests/unit/automations/actions/builtin/agent_task/test_dependencies.py b/surfsense_backend/tests/unit/automations/actions/builtin/agent_task/test_dependencies.py index ac20b2608..79da12933 100644 --- a/surfsense_backend/tests/unit/automations/actions/builtin/agent_task/test_dependencies.py +++ b/surfsense_backend/tests/unit/automations/actions/builtin/agent_task/test_dependencies.py @@ -14,8 +14,8 @@ from typing import Any import pytest -import app.automations.actions.agent_task.dependencies as deps_mod -from app.automations.actions.agent_task.dependencies import ( +import app.automations.actions.builtin.agent_task.dependencies as deps_mod +from app.automations.actions.builtin.agent_task.dependencies import ( DependencyError, build_dependencies, ) diff --git a/surfsense_backend/tests/unit/gateway/test_webhook_routes.py b/surfsense_backend/tests/unit/gateway/test_webhook_routes.py index 34d0651ab..8ac57cf06 100644 --- a/surfsense_backend/tests/unit/gateway/test_webhook_routes.py +++ b/surfsense_backend/tests/unit/gateway/test_webhook_routes.py @@ -13,6 +13,29 @@ from app.db import ExternalChatAccount, ExternalChatAccountMode, ExternalChatPla from app.routes import gateway_webhook_routes as routes +@pytest.fixture(autouse=True) +def _enable_gateways(monkeypatch): + """Turn on the Telegram/Slack/Discord gateway flags the routes gate on. + + The routes early-return when their integration is unconfigured, so without + this the handlers never reach the logic these tests assert on. + """ + 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, "GATEWAY_SLACK_ENABLED", True) + monkeypatch.setattr(routes.config, "GATEWAY_SLACK_CLIENT_ID", "slack-client") + monkeypatch.setattr(routes.config, "GATEWAY_SLACK_CLIENT_SECRET", "slack-secret") + monkeypatch.setattr(routes.config, "GATEWAY_SLACK_SIGNING_SECRET", "signing-secret") + + monkeypatch.setattr(routes.config, "GATEWAY_DISCORD_ENABLED", True) + monkeypatch.setattr(routes.config, "DISCORD_CLIENT_ID", "discord-client") + monkeypatch.setattr(routes.config, "DISCORD_CLIENT_SECRET", "discord-secret") + monkeypatch.setattr(routes.config, "DISCORD_BOT_TOKEN", "discord-bot-token") + + class RequestStub: def __init__(self, payload=None, *, headers=None, json_exc: Exception | None = None): self.headers = headers or {} @@ -275,7 +298,7 @@ async def test_slack_webhook_ignores_self_event(monkeypatch, mocker): @pytest.mark.asyncio -async def test_discord_gateway_install_returns_oauth_url(monkeypatch): +async def test_discord_gateway_install_returns_oauth_url(monkeypatch, mocker): monkeypatch.setattr(routes.config, "DISCORD_CLIENT_ID", "discord-client") monkeypatch.setattr( routes.config, @@ -283,10 +306,12 @@ async def test_discord_gateway_install_returns_oauth_url(monkeypatch): "http://localhost:8000/api/v1/gateway/discord/callback", ) monkeypatch.setattr(routes.config, "SECRET_KEY", "test-secret") + monkeypatch.setattr(routes, "check_search_space_access", mocker.AsyncMock()) response = await routes.install_discord_gateway( search_space_id=123, user=SimpleNamespace(id="00000000-0000-0000-0000-000000000001"), + session=mocker.AsyncMock(), ) assert response["auth_url"].startswith("https://discord.com/api/oauth2/authorize?")