Skip to content

Commit 94a3695

Browse files
committed
test(openai-agents): fix some tests
1 parent 3012e3a commit 94a3695

File tree

1 file changed

+35
-23
lines changed

1 file changed

+35
-23
lines changed

tests/integrations/openai_agents/test_openai_agents.py

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
ModelSettings,
1616
)
1717
from agents.items import (
18+
McpCall,
1819
ResponseOutputMessage,
1920
ResponseOutputText,
2021
ResponseFunctionToolCall,
@@ -452,6 +453,8 @@ def simple_test_tool(message: str) -> str:
452453
"on_invoke_tool": "<function agents.tool.function_tool.<locals>._create_function_tool.<locals>._on_invoke_tool>",
453454
"strict_json_schema": True,
454455
"is_enabled": True,
456+
"tool_input_guardrails": None,
457+
"tool_output_guardrails": None,
455458
}
456459
]
457460
)
@@ -694,13 +697,16 @@ async def test_mcp_tool_execution_spans(sentry_init, capture_events, test_agent)
694697
with patch(
695698
"agents.models.openai_responses.OpenAIResponsesModel.get_response"
696699
) as mock_get_response:
697-
# Create a mock McpCall object
698-
mcp_call = MagicMock()
699-
mcp_call.__class__.__name__ = "McpCall"
700-
mcp_call.name = "test_mcp_tool"
701-
mcp_call.arguments = '{"query": "search term"}'
702-
mcp_call.output = "MCP tool executed successfully"
703-
mcp_call.error = None
700+
# Create a McpCall object
701+
mcp_call = McpCall(
702+
id="mcp_call_123",
703+
name="test_mcp_tool",
704+
arguments='{"query": "search term"}',
705+
output="MCP tool executed successfully",
706+
error=None,
707+
type="mcp_call",
708+
server_label="test_server",
709+
)
704710

705711
# Create a ModelResponse with an McpCall in the output
706712
mcp_response = ModelResponse(
@@ -780,7 +786,7 @@ async def test_mcp_tool_execution_spans(sentry_init, capture_events, test_agent)
780786
)
781787

782788
# Verify no error status since error was None
783-
assert mcp_tool_span.get("status") != "error"
789+
assert mcp_tool_span.get("tags", {}).get("status") != "error"
784790

785791

786792
@pytest.mark.asyncio
@@ -793,13 +799,16 @@ async def test_mcp_tool_execution_with_error(sentry_init, capture_events, test_a
793799
with patch(
794800
"agents.models.openai_responses.OpenAIResponsesModel.get_response"
795801
) as mock_get_response:
796-
# Create a mock McpCall object with an error
797-
mcp_call_with_error = MagicMock()
798-
mcp_call_with_error.__class__.__name__ = "McpCall"
799-
mcp_call_with_error.name = "failing_mcp_tool"
800-
mcp_call_with_error.arguments = '{"query": "test"}'
801-
mcp_call_with_error.output = None
802-
mcp_call_with_error.error = "MCP tool execution failed"
802+
# Create a McpCall object with an error
803+
mcp_call_with_error = McpCall(
804+
id="mcp_call_error_123",
805+
name="failing_mcp_tool",
806+
arguments='{"query": "test"}',
807+
output=None,
808+
error="MCP tool execution failed",
809+
type="mcp_call",
810+
server_label="test_server",
811+
)
803812

804813
# Create a ModelResponse with a failing McpCall
805814
mcp_response = ModelResponse(
@@ -877,7 +886,7 @@ async def test_mcp_tool_execution_with_error(sentry_init, capture_events, test_a
877886
assert mcp_tool_span["data"]["gen_ai.tool.output"] is None
878887

879888
# Verify error status was set
880-
assert mcp_tool_span["status"] == "error"
889+
assert mcp_tool_span["tags"]["status"] == "error"
881890

882891

883892
@pytest.mark.asyncio
@@ -890,13 +899,16 @@ async def test_mcp_tool_execution_without_pii(sentry_init, capture_events, test_
890899
with patch(
891900
"agents.models.openai_responses.OpenAIResponsesModel.get_response"
892901
) as mock_get_response:
893-
# Create a mock McpCall object
894-
mcp_call = MagicMock()
895-
mcp_call.__class__.__name__ = "McpCall"
896-
mcp_call.name = "test_mcp_tool"
897-
mcp_call.arguments = '{"query": "sensitive data"}'
898-
mcp_call.output = "Result with sensitive info"
899-
mcp_call.error = None
902+
# Create a McpCall object
903+
mcp_call = McpCall(
904+
id="mcp_call_pii_123",
905+
name="test_mcp_tool",
906+
arguments='{"query": "sensitive data"}',
907+
output="Result with sensitive info",
908+
error=None,
909+
type="mcp_call",
910+
server_label="test_server",
911+
)
900912

901913
# Create a ModelResponse with an McpCall
902914
mcp_response = ModelResponse(

0 commit comments

Comments
 (0)