Skip to content

Commit 7cedc71

Browse files
Testcases
1 parent 510e5b2 commit 7cedc71

File tree

6 files changed

+79
-28
lines changed

6 files changed

+79
-28
lines changed

src/backend/tests/agents/test_group_chat_manager.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
import os
22
import sys
3-
import re
4-
import asyncio
5-
import json
63
import pytest
7-
import logging
8-
from datetime import datetime, date
94
from unittest.mock import AsyncMock, MagicMock, patch
10-
from pydantic import BaseModel
115

126
# Adjust sys.path so that the project root is found.
137
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../")))
@@ -156,7 +150,7 @@ def group_chat_manager():
156150
class DummyStepMissingAgent(Step):
157151
@property
158152
def agent(self):
159-
return "" # Force missing agent
153+
return ""
160154

161155
# ---------------------- Tests ----------------------
162156

@@ -359,4 +353,4 @@ def agent(self):
359353
human_feedback="",
360354
human_approval_status=HumanFeedbackStatus.requested,
361355
)
362-
356+

src/backend/tests/agents/test_human.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,28 @@ def patch_instantiation_context(monkeypatch):
3434
monkeypatch.setattr(AgentInstantiationContext, "current_runtime", lambda: dummy_runtime)
3535
monkeypatch.setattr(AgentInstantiationContext, "current_agent_id", lambda: dummy_agent_id)
3636

37+
3738
# --- Patch ApprovalRequest so that required fields get default values ---
3839
from src.backend.models.messages import ApprovalRequest as RealApprovalRequest, Plan
40+
41+
3942
class DummyApprovalRequest(RealApprovalRequest):
4043
def __init__(self, **data):
4144
# Provide default values for missing fields.
4245
data.setdefault("action", "dummy_action")
4346
data.setdefault("agent", "dummy_agent")
4447
super().__init__(**data)
4548

49+
4650
@pytest.fixture(autouse=True)
4751
def patch_approval_request(monkeypatch):
4852
monkeypatch.setattr("src.backend.agents.human.ApprovalRequest", DummyApprovalRequest)
4953

5054
# Now import the module under test.
5155
from autogen_core.base import MessageContext, AgentId
5256
from src.backend.agents.human import HumanAgent
53-
from src.backend.models.messages import HumanFeedback, Step, StepStatus, AgentMessage, ApprovalRequest, BAgentType
57+
from src.backend.models.messages import HumanFeedback, Step, StepStatus, BAgentType
58+
5459

5560
# Define a minimal dummy MessageContext implementation.
5661
class DummyMessageContext(MessageContext):
@@ -60,6 +65,7 @@ def __init__(self, sender="dummy_sender", topic_id="dummy_topic", is_rpc=False,
6065
self.is_rpc = is_rpc
6166
self.cancellation_token = cancellation_token
6267

68+
6369
# Define a fake memory implementation.
6470
class FakeMemory:
6571
def __init__(self):
@@ -92,6 +98,7 @@ async def get_plan_by_session(self, session_id: str) -> Plan:
9298
human_clarification_response=None,
9399
)
94100

101+
95102
# Fixture to create a HumanAgent instance with fake memory.
96103
@pytest.fixture
97104
def human_agent():
@@ -101,8 +108,8 @@ def human_agent():
101108
agent = HumanAgent(memory=fake_memory, user_id=user_id, group_chat_manager_id=group_chat_manager_id)
102109
return agent, fake_memory
103110

104-
# ------------------- Existing Tests -------------------
105111

112+
# ------------------- Existing Tests -------------------
106113
def test_human_agent_init():
107114
fake_memory = MagicMock()
108115
user_id = "test_user"
@@ -112,6 +119,7 @@ def test_human_agent_init():
112119
assert agent.group_chat_manager_id == group_chat_manager_id
113120
assert agent._memory == fake_memory
114121

122+
115123
@pytest.mark.asyncio
116124
async def test_handle_step_feedback_no_step_found(human_agent):
117125
"""
@@ -169,6 +177,7 @@ async def test_handle_step_feedback_update_exception(human_agent):
169177
with pytest.raises(Exception, match="Update failed"):
170178
await agent.handle_step_feedback(feedback, ctx)
171179

180+
172181
@pytest.mark.asyncio
173182
async def test_handle_step_feedback_add_item_exception(human_agent):
174183
"""

0 commit comments

Comments
 (0)