feat: migrate agent core to pydantic-ai framework
This commit is contained in:
+19
-21
@@ -4,7 +4,6 @@ import pytest
|
||||
from unittest.mock import MagicMock, AsyncMock, patch
|
||||
|
||||
from core.orchestrator import AgentOrchestrator
|
||||
from gitea.client import GiteaClient
|
||||
from gitea.models import IssueModel, PullRequestModel, RepositoryModel
|
||||
|
||||
pytestmark = pytest.mark.anyio
|
||||
@@ -29,16 +28,17 @@ async def test_poll_and_dispatch_no_notifications(
|
||||
temp_state_file: Path
|
||||
) -> None:
|
||||
mock_get_path.return_value = temp_state_file
|
||||
mock_client = MagicMock(spec=GiteaClient)
|
||||
mock_tools = MagicMock()
|
||||
mock_client = MagicMock()
|
||||
|
||||
# Return no notifications
|
||||
mock_client.list_unread_notifications.return_value = []
|
||||
mock_client.notifications.list_unread_notifications.return_value = []
|
||||
|
||||
orchestrator = AgentOrchestrator(mock_client, mock_tools)
|
||||
orchestrator = AgentOrchestrator(
|
||||
mock_client, MagicMock(), MagicMock(), MagicMock(), MagicMock()
|
||||
)
|
||||
await orchestrator.poll_and_dispatch()
|
||||
|
||||
mock_client.list_unread_notifications.assert_called_once_with(since=None)
|
||||
mock_client.notifications.list_unread_notifications.assert_called_once_with(since=None)
|
||||
assert not temp_state_file.exists()
|
||||
|
||||
|
||||
@@ -66,8 +66,7 @@ async def test_poll_and_dispatch_with_notifications(
|
||||
return "Decided"
|
||||
mock_reader.decide_notification = AsyncMock(side_effect=mock_decide_notification)
|
||||
mock_notification_reader_class.return_value = mock_reader
|
||||
mock_client = MagicMock(spec=GiteaClient)
|
||||
mock_tools = MagicMock()
|
||||
mock_client = MagicMock()
|
||||
|
||||
# Set up mock Gitea notifications
|
||||
notifications = [
|
||||
@@ -98,13 +97,14 @@ async def test_poll_and_dispatch_with_notifications(
|
||||
}
|
||||
}
|
||||
]
|
||||
mock_client.list_unread_notifications.return_value = notifications
|
||||
mock_client.notifications.list_unread_notifications.return_value = notifications
|
||||
|
||||
# Mock issue and PR get methods
|
||||
# Mock issue and PR get methods on client
|
||||
issue_model = IssueModel(number=42, title="Bug issue", repository=RepositoryModel(name="repo1", full_name="meeks/repo1"))
|
||||
pr_model = PullRequestModel(number=10, title="Fix PR", repository=RepositoryModel(name="repo1", full_name="meeks/repo1"))
|
||||
mock_client.get_issue.return_value = issue_model
|
||||
mock_client.get_pull_request.return_value = pr_model
|
||||
|
||||
mock_client.issues.get_issue.return_value = issue_model
|
||||
mock_client.prs.get_pull_request.return_value = pr_model
|
||||
|
||||
# Mock dispatcher and workspace path
|
||||
mock_dispatcher_instance = MagicMock()
|
||||
@@ -116,15 +116,13 @@ async def test_poll_and_dispatch_with_notifications(
|
||||
mock_workspace_class.return_value = mock_workspace_instance
|
||||
|
||||
# Create orchestrator and poll
|
||||
orchestrator = AgentOrchestrator(mock_client, mock_tools)
|
||||
orchestrator = AgentOrchestrator(
|
||||
mock_client, MagicMock(), MagicMock(), MagicMock(), MagicMock()
|
||||
)
|
||||
await orchestrator.poll_and_dispatch()
|
||||
|
||||
# Assert notifications were checked with None (first execution)
|
||||
mock_client.list_unread_notifications.assert_called_once_with(since=None)
|
||||
|
||||
# Assert issue and PR details were fetched
|
||||
mock_client.get_issue.assert_called_once_with("meeks", "repo1", 42)
|
||||
mock_client.get_pull_request.assert_called_once_with("meeks", "repo1", 10)
|
||||
mock_client.notifications.list_unread_notifications.assert_called_once_with(since=None)
|
||||
|
||||
# Assert work was processed by dispatcher
|
||||
mock_dispatcher_instance.dispatch.assert_called_once()
|
||||
@@ -136,9 +134,9 @@ async def test_poll_and_dispatch_with_notifications(
|
||||
assert work_items[1].notification_id == 102
|
||||
|
||||
# Assert notifications were marked as read
|
||||
mock_client.mark_notification_as_read.assert_any_call(101)
|
||||
mock_client.mark_notification_as_read.assert_any_call(102)
|
||||
assert mock_client.mark_notification_as_read.call_count == 2
|
||||
mock_client.notifications.mark_notification_as_read.assert_any_call(101)
|
||||
mock_client.notifications.mark_notification_as_read.assert_any_call(102)
|
||||
assert mock_client.notifications.mark_notification_as_read.call_count == 2
|
||||
|
||||
# Assert checkpoint date was persisted
|
||||
assert temp_state_file.exists()
|
||||
|
||||
Reference in New Issue
Block a user