updates on the agent
This commit is contained in:
55
tests/test_tool_registry.py
Normal file
55
tests/test_tool_registry.py
Normal file
@@ -0,0 +1,55 @@
|
||||
"""Unit tests for ToolRegistry and Interactive Question Asking."""
|
||||
import pytest
|
||||
import asyncio
|
||||
from core.tool_registry import Tool, ToolParameter, ToolRegistry
|
||||
from core.interactive_question import QuestionManager, QuestionOption, question_manager
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_tool_registry_registration_and_execution():
|
||||
registry = ToolRegistry()
|
||||
|
||||
async def sample_handler(order_id: str, count: int = 1):
|
||||
return {"order": order_id, "items": count}
|
||||
|
||||
tool = Tool(
|
||||
name="test_tool",
|
||||
description="A test tool",
|
||||
handler=sample_handler,
|
||||
parameters=[
|
||||
ToolParameter(name="order_id", type="string", description="Order ID"),
|
||||
ToolParameter(name="count", type="integer", description="Count", required=False, default=1),
|
||||
],
|
||||
)
|
||||
registry.register(tool)
|
||||
|
||||
assert registry.get("test_tool") is not None
|
||||
schemas = registry.get_schemas()
|
||||
assert len(schemas) == 1
|
||||
assert schemas[0]["name"] == "test_tool"
|
||||
assert "order_id" in schemas[0]["parameters"]["properties"]
|
||||
|
||||
result = await registry.execute_tool("test_tool", order_id="ORD-100")
|
||||
assert result == {"order": "ORD-100", "items": 1}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_question_manager_flow():
|
||||
qm = QuestionManager()
|
||||
q = qm.create_question(
|
||||
prompt="Select target batch:",
|
||||
options=[
|
||||
{"id": "morning", "label": "Morning Batch", "badge": "12 AM–9 AM"},
|
||||
{"id": "afternoon", "label": "Afternoon Batch", "badge": "9 AM–4 PM"},
|
||||
],
|
||||
allow_custom_input=False,
|
||||
)
|
||||
|
||||
assert q.question_id.startswith("q-")
|
||||
assert len(q.options) == 2
|
||||
assert q.options[0].badge == "12 AM–9 AM"
|
||||
assert not q.answered
|
||||
|
||||
qm.answer_question(q.question_id, "morning")
|
||||
assert q.answered is True
|
||||
assert q.answer == "morning"
|
||||
Reference in New Issue
Block a user