Skip to content

Commit 879caa9

Browse files
moonbox3Copilot
andcommitted
Address PR review feedback for microsoft#4546
- Use safer 'not .get("interrupt")' assertion instead of 'not in' to handle Pydantic v2 model_dump() including keys with None values - Add unit test for mixed function_result and function_approval_response in the same message to TestExtractResponsesFromMessages Co-authored-by: Copilot <[email protected]>
1 parent 193429d commit 879caa9

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

‎python/packages/ag-ui/tests/ag_ui/test_workflow_run.py‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,6 +1249,26 @@ def test_mixed_result_and_approval(self):
12491249
assert "approval-1" in responses
12501250
assert responses["approval-1"]["approved"] is True
12511251

1252+
def test_mixed_result_and_approval_same_message(self):
1253+
"""Both function_result and function_approval_response in the same message are extracted."""
1254+
result = Content.from_function_result(call_id="call-1", result="done")
1255+
func_call = Content.from_function_call(
1256+
call_id="call-2",
1257+
name="submit",
1258+
arguments={},
1259+
)
1260+
approval = Content.from_function_approval_response(
1261+
approved=True,
1262+
id="approval-1",
1263+
function_call=func_call,
1264+
)
1265+
messages = [Message(role="tool", contents=[result, approval])]
1266+
responses = _extract_responses_from_messages(messages)
1267+
assert "call-1" in responses
1268+
assert responses["call-1"] == "done"
1269+
assert "approval-1" in responses
1270+
assert responses["approval-1"]["approved"] is True
1271+
12521272
def test_text_content_skipped(self):
12531273
"""Non-result, non-approval content is ignored."""
12541274
text = Content.from_text(text="hello")
@@ -1329,7 +1349,7 @@ async def handle_approval(self, original_request: Content, response: Content, ct
13291349
text_deltas = [event.delta for event in resumed_events if event.type == "TEXT_MESSAGE_CONTENT"]
13301350
assert any("approved" in delta for delta in text_deltas)
13311351
resumed_finished = [event for event in resumed_events if event.type == "RUN_FINISHED"][0].model_dump()
1332-
assert "interrupt" not in resumed_finished
1352+
assert not resumed_finished.get("interrupt")
13331353

13341354

13351355
async def test_workflow_run_approval_via_messages_denied() -> None:
@@ -1397,7 +1417,7 @@ async def handle_approval(self, original_request: Content, response: Content, ct
13971417
text_deltas = [event.delta for event in resumed_events if event.type == "TEXT_MESSAGE_CONTENT"]
13981418
assert any("rejected" in delta for delta in text_deltas)
13991419
resumed_finished = [event for event in resumed_events if event.type == "RUN_FINISHED"][0].model_dump()
1400-
assert "interrupt" not in resumed_finished
1420+
assert not resumed_finished.get("interrupt")
14011421

14021422

14031423
async def test_workflow_run_available_interrupts_logged():

0 commit comments

Comments
 (0)