fix(d1): Calendar-Suite + ai_proactive repariert — conftest CalendarPlugin-Import wiederhergestellt (abbe7a1-Regression), CalendarContract-Zugriffe snake_case→PascalCase (context_tools, services ×2, mail/routes), 2 stale Rate-Limit-Tests auf zentrale check_rate_limit-Grenze umgestellt; test_calendar 34/34, ai_proactive-Failures behoben; Mail-Vorbestand dokumentiert
Check Cross-Plugin Imports / check (push) Has been cancelled

This commit is contained in:
Agent Zero
2026-08-24 07:57:27 +02:00
parent 9d8da99026
commit f6e117b1c3
5 changed files with 25 additions and 21 deletions
+1
View File
@@ -53,6 +53,7 @@ from app.models.tenant import Tenant
from app.models.user import User, UserTenant
from app.models.user_preference import UserPreference # noqa: F401
from app.models.workflow import Workflow, WorkflowInstance, WorkflowStepHistory # noqa: F401
from app.plugins.builtins.calendar import CalendarPlugin # noqa: F401
from app.models.outbox import EventOutbox # noqa: F401
from app.models.consumer_inbox import ConsumerInbox # noqa: F401
from app.models.saved_filter import SavedFilter # noqa: F401
+16 -13
View File
@@ -15,6 +15,7 @@ from unittest.mock import AsyncMock, MagicMock, patch
import pytest
import pytest_asyncio
from fastapi import HTTPException
from httpx import ASGITransport, AsyncClient
from sqlalchemy import text
from sqlalchemy.ext.asyncio import AsyncEngine, AsyncSession, async_sessionmaker
@@ -1104,14 +1105,11 @@ async def test_generate_suggestion_llm_failure():
@pytest.mark.asyncio
@patch("app.plugins.builtins.ai_proactive.services.create_db_session")
async def test_handle_context_change_rate_limited(mock_create_session, redis_client):
async def test_handle_context_change_rate_limited(mock_create_session):
"""Rate-limit prevents suggestion generation."""
tenant_id = uuid.uuid4()
user_id = uuid.uuid4()
# Pre-set rate limit key in Redis
await redis_client.setex(f"ai_proactive:rate:{user_id}", 10, "1")
mock_session = AsyncMock()
mock_session.__aenter__ = AsyncMock(return_value=mock_session)
mock_session.__aexit__ = AsyncMock(return_value=None)
@@ -1127,8 +1125,14 @@ async def test_handle_context_change_rate_limited(mock_create_session, redis_cli
rate_limit_seconds=10,
model="ollama/deepseek-v4",
)
# Since bb36378 the rate limit goes through app.core.rate_limit.check_rate_limit;
# simulate an exceeded limit instead of patching the removed services.get_cache.
with (
patch("app.plugins.builtins.ai_proactive.services.get_cache", return_value=redis_client),
patch(
"app.core.rate_limit.check_rate_limit",
new_callable=AsyncMock,
side_effect=HTTPException(status_code=429),
),
patch(
"app.plugins.builtins.ai_proactive.services.get_user_settings",
new_callable=AsyncMock,
@@ -1147,7 +1151,7 @@ async def test_handle_context_change_rate_limited(mock_create_session, redis_cli
@pytest.mark.asyncio
@patch("app.plugins.builtins.ai_proactive.services.create_db_session")
async def test_handle_context_change_disabled(mock_create_session, redis_client):
async def test_handle_context_change_disabled(mock_create_session):
"""Settings disabled → no suggestion."""
tenant_id = uuid.uuid4()
user_id = uuid.uuid4()
@@ -1167,13 +1171,12 @@ async def test_handle_context_change_disabled(mock_create_session, redis_client)
rate_limit_seconds=10,
model="ollama/deepseek-v4",
)
with (
patch("app.plugins.builtins.ai_proactive.services.get_cache", return_value=redis_client),
patch(
"app.plugins.builtins.ai_proactive.services.get_user_settings",
new_callable=AsyncMock,
return_value=disabled_settings,
),
# Disabled settings cause an early return before any Redis access;
# no cache/rate-limit patch needed since bb36378.
with patch(
"app.plugins.builtins.ai_proactive.services.get_user_settings",
new_callable=AsyncMock,
return_value=disabled_settings,
):
await handle_context_change({
"user_id": str(user_id),