fix: improve maintenance and synchronize live conversations

This commit is contained in:
WangShen007 committed 2026-10-29 09:46:21 +08:00
1 parent bb541bd212
commit ef86a5d3af
297 files changed
+2983 -1274

No files matched your search

+2 -9
View File
@@ -16,7 +16,6 @@ limitations under the License.
import asyncio
import pytest
from fastapi.testclient import TestClient
from app.core.config import settings
from app.models.user import User
from app.models.role import Role
@@ -27,9 +26,7 @@ from app.models.customer import Customer
from app.models.agent import Agent, AgentType
from app.models.schemas.jira import AgentWithJiraConfig
from app.agents.chat_agent import ChatAgent, ChatResponse, TransferReasonType
from app.repositories.ai_config import AIConfigRepository
from uuid import uuid4
from datetime import datetime, timezone
from unittest.mock import patch, MagicMock
from agno.storage.base import Storage
from fastapi import HTTPException
@@ -182,11 +179,7 @@ def test_session(db, test_organization_id, test_customer, test_agent) -> Session
@pytest.fixture
def mock_db_session(db):
"""Mock database session for ChatAgent"""
def get_mock_db():
yield db
with patch('app.agents.chat_agent.get_db', get_mock_db), \
patch('app.tools.knowledge_search_byagent.SessionLocal') as mock_knowledge_session_local, \
with patch('app.tools.knowledge_search_byagent.SessionLocal') as mock_knowledge_session_local, \
patch('app.agents.chat_agent.SessionLocal') as mock_chat_agent_session_local:
# Setup SessionLocal to return our test db when used as context manager
mock_knowledge_session_local.return_value.__enter__.return_value = db
@@ -452,4 +445,4 @@ async def test_chat_agent_run_timeout(test_organization_id, test_agent, test_use
assert isinstance(response, ChatResponse)
assert "error" in response.message.lower()
assert not response.transfer_to_human
assert not response.transfer_to_human
@@ -31,7 +31,6 @@ from app.agents.guardrail_policy import (
)
from app.models.agent import Agent, AgentType
from app.models.chat_history import ChatHistory
from app.models.schemas.chat import ChatResponse
from app.models.schemas.jira import AgentWithJiraConfig
from app.utils.guardrail_runtime import BLOCK_REPLY, LEAK_REPLY
+3 -8
View File
@@ -17,9 +17,7 @@ limitations under the License.
import asyncio
import pytest
import pytz
from datetime import datetime, timedelta
from unittest.mock import patch, MagicMock, AsyncMock
import sys
from app.agents.transfer_agent import (
FOLLOW_UP_TIMEOUT_MESSAGE,
TRANSFER_TIMEOUT_MESSAGE,
@@ -32,8 +30,6 @@ from app.models.agent import Agent, AgentType
from app.models.organization import Organization
from app.models.user import User, UserGroup
from uuid import uuid4
import app.utils.agno_utils
from fastapi import HTTPException
# Mock for agno.agent.Agent
class MockPhiAgent:
@@ -132,7 +128,6 @@ async def test_transfer_response_agent_initialization():
# Create a spy to track calls to create_model
create_model_calls = []
original_create_model = app.utils.agno_utils.create_model
def spy_create_model(*args, **kwargs):
create_model_calls.append((args, kwargs))
@@ -533,7 +528,7 @@ async def test_timezone_handling(test_agent):
mock_pytz.UTC = pytz.UTC
mock_pytz.UnknownTimeZoneError = pytz.exceptions.UnknownTimeZoneError
response = await get_agent_availability_response(
await get_agent_availability_response(
agent=test_agent,
customer_id="customer123",
chat_history=[],
@@ -552,7 +547,7 @@ async def test_timezone_handling(test_agent):
mock_pytz.timezone.side_effect = pytz.exceptions.UnknownTimeZoneError("Invalid/Timezone")
test_agent.organization.timezone = "Invalid/Timezone"
response = await get_agent_availability_response(
await get_agent_availability_response(
agent=test_agent,
customer_id="customer123",
chat_history=[],
@@ -564,4 +559,4 @@ async def test_timezone_handling(test_agent):
)
# Verify that timezone was called with the invalid timezone
mock_pytz.timezone.assert_called_with("Invalid/Timezone")
mock_pytz.timezone.assert_called_with("Invalid/Timezone")