"""
Test async function implementation for FastMCP tools.

This module verifies that the search_web function is properly
implemented as an async coroutine function.
"""

import inspect
import pytest
import os
import sys

# Add parent directory to path for imports
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))


def test_search_web_is_async():
    """Verify that search_web is a coroutine function (uses async def)."""
    try:
        from server import search_web

        assert inspect.iscoroutinefunction(search_web), \
            "search_web should be defined with async def"

    except ImportError:
        pytest.skip("server.py not yet created")
    except AttributeError:
        pytest.skip("search_web function not yet defined in server.py")


def test_search_web_is_awaitable():
    """Verify that search_web can be awaited."""
    try:
        from server import search_web

        assert inspect.iscoroutinefunction(search_web), \
            "search_web should be a coroutine function"

    except ImportError:
        pytest.skip("server.py not yet created")
    except AttributeError:
        pytest.skip("search_web function not yet defined in server.py")


def test_search_web_can_be_called():
    """Verify that search_web can be called (with mocked environment)."""
    try:
        from server import search_web

        # This test doesn't actually call the function (would need env vars)
        # It just verifies the signature is correct
        sig = inspect.signature(search_web)

        # Check that it has the expected parameters
        params = list(sig.parameters.keys())
        assert len(params) >= 1, "search_web should have at least one parameter"

    except ImportError:
        pytest.skip("server.py not yet created")
    except AttributeError:
        pytest.skip("search_web function not yet defined in server.py")
