fix mcp test

This commit is contained in:
Mery-Sanz 2025-04-11 08:24:26 +02:00
parent 99469a17e2
commit 58985f9d57
8 changed files with 28 additions and 7 deletions

View File

@ -5,7 +5,7 @@ from typing import Any
from mcp import Tool as MCPTool from mcp import Tool as MCPTool
from mcp.types import CallToolResult, TextContent from mcp.types import CallToolResult, TextContent
from agents.mcp import MCPServer from cai.sdk.agents.mcp import MCPServer
tee = shutil.which("tee") or "" tee = shutil.which("tee") or ""
assert tee, "tee not found" assert tee, "tee not found"

21
tests/mcp/helpers.py Normal file
View File

@ -0,0 +1,21 @@
try:
from cai.sdk.agents.voice import StreamedAudioResult
except ImportError:
pass
async def extract_events(result: StreamedAudioResult) -> tuple[list[str], list[bytes]]:
"""Collapse pipeline stream events to simple labels for ordering assertions."""
flattened: list[str] = []
audio_chunks: list[bytes] = []
async for ev in result.stream():
if ev.type == "voice_stream_event_audio":
if ev.data is not None:
audio_chunks.append(ev.data.tobytes())
flattened.append("audio")
elif ev.type == "voice_stream_event_lifecycle":
flattened.append(ev.event)
elif ev.type == "voice_stream_event_error":
flattened.append("error")
return flattened, audio_chunks

View File

@ -5,7 +5,7 @@ from mcp.types import ListToolsResult, Tool as MCPTool
from cai.sdk.agents.mcp import MCPServerStdio from cai.sdk.agents.mcp import MCPServerStdio
from tests.mcp.helpers import DummyStreamsContextManager, tee from tests.helpers import DummyStreamsContextManager, tee
@pytest.mark.asyncio @pytest.mark.asyncio

View File

@ -5,7 +5,7 @@ from mcp.types import ListToolsResult, Tool as MCPTool
from cai.sdk.agents.mcp import MCPServerStdio from cai.sdk.agents.mcp import MCPServerStdio
from .helpers import DummyStreamsContextManager, tee from tests.helpers import DummyStreamsContextManager, tee
@pytest.mark.asyncio @pytest.mark.asyncio

View File

@ -6,7 +6,7 @@ from cai.sdk.agents import Agent, Runner
from tests.fake_model import FakeModel from tests.fake_model import FakeModel
from tests.core.test_responses import get_function_tool, get_function_tool_call, get_text_message from tests.core.test_responses import get_function_tool, get_function_tool_call, get_text_message
from tests.testing_processor import SPAN_PROCESSOR_TESTING, fetch_normalized_spans from tests.testing_processor import SPAN_PROCESSOR_TESTING, fetch_normalized_spans
from .helpers import FakeMCPServer from tests.helpers import FakeMCPServer
@pytest.mark.asyncio @pytest.mark.asyncio

View File

@ -9,7 +9,7 @@ from cai.sdk.agents import FunctionTool, RunContextWrapper
from cai.sdk.agents.exceptions import AgentsException, ModelBehaviorError from cai.sdk.agents.exceptions import AgentsException, ModelBehaviorError
from cai.sdk.agents.mcp import MCPServer, MCPUtil from cai.sdk.agents.mcp import MCPServer, MCPUtil
from .helpers import FakeMCPServer from tests.helpers import FakeMCPServer
class Foo(BaseModel): class Foo(BaseModel):

View File

@ -7,7 +7,7 @@ from cai.sdk.agents import Agent, ModelBehaviorError, Runner, UserError
from tests.fake_model import FakeModel from tests.fake_model import FakeModel
from tests.core.test_responses import get_function_tool_call, get_text_message from tests.core.test_responses import get_function_tool_call, get_text_message
from .helpers import FakeMCPServer from tests.helpers import FakeMCPServer
@pytest.mark.asyncio @pytest.mark.asyncio

View File

@ -1,5 +1,5 @@
try: try:
from agents.voice import StreamedAudioResult from cai.sdk.agents.voice import StreamedAudioResult
except ImportError: except ImportError:
pass pass