|
| 1 | +"""Tests for OpenAI Agents SDK integration""" |
| 2 | + |
| 3 | +from collections.abc import Callable |
| 4 | + |
| 5 | +import pytest |
| 6 | + |
| 7 | +from stackone_ai import StackOneToolSet |
| 8 | + |
| 9 | + |
| 10 | +@pytest.fixture |
| 11 | +def toolset() -> StackOneToolSet: |
| 12 | + """Create a toolset for testing""" |
| 13 | + return StackOneToolSet(api_key="test-key") |
| 14 | + |
| 15 | + |
| 16 | +def test_single_tool_openai_agents_conversion(toolset: StackOneToolSet) -> None: |
| 17 | + """Test converting a single tool to OpenAI Agents format""" |
| 18 | + tools = toolset.get_tools("hris_get_employee") |
| 19 | + |
| 20 | + if not tools.tools: |
| 21 | + pytest.skip("No tools found for testing") |
| 22 | + |
| 23 | + tool = tools.tools[0] |
| 24 | + openai_agents_tool = tool.to_openai_agents() |
| 25 | + |
| 26 | + # Verify it's a callable function tool |
| 27 | + assert callable(openai_agents_tool) |
| 28 | + assert isinstance(openai_agents_tool, Callable) |
| 29 | + |
| 30 | + |
| 31 | +def test_tools_openai_agents_conversion(toolset: StackOneToolSet) -> None: |
| 32 | + """Test converting all tools to OpenAI Agents format""" |
| 33 | + tools = toolset.get_tools("hris_*") |
| 34 | + |
| 35 | + if not tools.tools: |
| 36 | + pytest.skip("No tools found for testing") |
| 37 | + |
| 38 | + openai_agents_tools = tools.to_openai_agents() |
| 39 | + |
| 40 | + # Verify conversion |
| 41 | + assert len(openai_agents_tools) == len(tools.tools) |
| 42 | + assert all(callable(tool) for tool in openai_agents_tools) |
| 43 | + assert all(isinstance(tool, Callable) for tool in openai_agents_tools) |
| 44 | + |
| 45 | + |
| 46 | +@pytest.mark.asyncio |
| 47 | +async def test_openai_agents_tool_execution(toolset: StackOneToolSet) -> None: |
| 48 | + """Test that OpenAI Agents tools can be executed""" |
| 49 | + tools = toolset.get_tools("hris_get_employee") |
| 50 | + |
| 51 | + if not tools.tools: |
| 52 | + pytest.skip("No tools found for testing") |
| 53 | + |
| 54 | + tool = tools.tools[0] |
| 55 | + openai_agents_tool = tool.to_openai_agents() |
| 56 | + |
| 57 | + # Test that the tool function exists and is callable |
| 58 | + assert callable(openai_agents_tool) |
| 59 | + assert callable(openai_agents_tool) |
| 60 | + |
| 61 | + |
| 62 | +def test_openai_agents_tool_attributes(toolset: StackOneToolSet) -> None: |
| 63 | + """Test that OpenAI Agents tools have proper attributes""" |
| 64 | + tools = toolset.get_tools("hris_get_employee") |
| 65 | + |
| 66 | + if not tools.tools: |
| 67 | + pytest.skip("No tools found for testing") |
| 68 | + |
| 69 | + tool = tools.tools[0] |
| 70 | + openai_agents_tool = tool.to_openai_agents() |
| 71 | + |
| 72 | + # Verify the tool has required attributes for function_tool |
| 73 | + assert callable(openai_agents_tool) |
| 74 | + # The function_tool decorator should preserve the original function properties |
| 75 | + assert hasattr(openai_agents_tool, "__name__") or hasattr(openai_agents_tool, "__qualname__") |
| 76 | + |
| 77 | + |
| 78 | +def test_openai_agents_tool_naming(toolset: StackOneToolSet) -> None: |
| 79 | + """Test that OpenAI Agents tools preserve naming""" |
| 80 | + tools = toolset.get_tools("hris_get_employee") |
| 81 | + |
| 82 | + if not tools.tools: |
| 83 | + pytest.skip("No tools found for testing") |
| 84 | + |
| 85 | + tool = tools.tools[0] |
| 86 | + openai_agents_tool = tool.to_openai_agents() |
| 87 | + |
| 88 | + # Verify function tool exists and is properly named |
| 89 | + assert callable(openai_agents_tool) |
| 90 | + # The function should be a decorated function with proper metadata |
| 91 | + original_name = tool.name |
| 92 | + assert original_name is not None |
| 93 | + assert len(original_name) > 0 |
0 commit comments