"""Test that TOOLS_REGISTRY loads from registry/tools.json and resolves entry points."""

from agenlang.tools import TOOLS_REGISTRY


def test_registry_loads_both_tools():
    assert "web_search" in TOOLS_REGISTRY
    assert "summarize" in TOOLS_REGISTRY


def test_registry_has_required_fields():
    for name, tool in TOOLS_REGISTRY.items():
        assert "capabilities" in tool, f"{name} missing capabilities"
        assert "entry_point" in tool, f"{name} missing entry_point"


def test_entry_points_resolve():
    for name, tool in TOOLS_REGISTRY.items():
        module_name, func_name = tool["entry_point"].rsplit(".", 1)
        module = __import__(module_name, fromlist=[func_name])
        func = getattr(module, func_name)
        assert callable(func), f"{name} entry_point is not callable"


def test_web_search_executes():
    tool = TOOLS_REGISTRY["web_search"]
    module_name, func_name = tool["entry_point"].rsplit(".", 1)
    module = __import__(module_name, fromlist=[func_name])
    func = getattr(module, func_name)
    result = func({"query": "test"})
    assert isinstance(result, str) and len(result) > 0


def test_summarize_executes():
    tool = TOOLS_REGISTRY["summarize"]
    module_name, func_name = tool["entry_point"].rsplit(".", 1)
    module = __import__(module_name, fromlist=[func_name])
    func = getattr(module, func_name)
    result = func({"text": "hello world"})
    assert "hello world" in result
