@@ -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 ---
3839from src .backend .models .messages import ApprovalRequest as RealApprovalRequest , Plan
40+
41+
3942class 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 )
4751def patch_approval_request (monkeypatch ):
4852 monkeypatch .setattr ("src.backend.agents.human.ApprovalRequest" , DummyApprovalRequest )
4953
5054# Now import the module under test.
5155from autogen_core .base import MessageContext , AgentId
5256from 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.
5661class 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.
6470class 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
97104def 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 -------------------
106113def 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
116124async 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
173182async def test_handle_step_feedback_add_item_exception (human_agent ):
174183 """
0 commit comments