feat: added proper settings handling
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
import pytest
|
||||
|
||||
from alfred.agent.registry import Tool, make_tools
|
||||
from alfred.settings import settings
|
||||
|
||||
|
||||
class TestToolEdgeCases:
|
||||
@@ -140,13 +141,13 @@ class TestMakeToolsEdgeCases:
|
||||
|
||||
def test_make_tools_returns_dict(self, memory):
|
||||
"""Should return dictionary of tools."""
|
||||
tools = make_tools()
|
||||
tools = make_tools(settings)
|
||||
|
||||
assert isinstance(tools, dict)
|
||||
|
||||
def test_make_tools_all_tools_have_required_fields(self, memory):
|
||||
"""Should have all required fields for each tool."""
|
||||
tools = make_tools()
|
||||
tools = make_tools(settings)
|
||||
|
||||
for name, tool in tools.items():
|
||||
assert tool.name == name
|
||||
@@ -157,14 +158,14 @@ class TestMakeToolsEdgeCases:
|
||||
|
||||
def test_make_tools_unique_names(self, memory):
|
||||
"""Should have unique tool names."""
|
||||
tools = make_tools()
|
||||
tools = make_tools(settings)
|
||||
|
||||
names = list(tools.keys())
|
||||
assert len(names) == len(set(names))
|
||||
|
||||
def test_make_tools_valid_parameter_schemas(self, memory):
|
||||
"""Should have valid JSON Schema for parameters."""
|
||||
tools = make_tools()
|
||||
tools = make_tools(settings)
|
||||
|
||||
for tool in tools.values():
|
||||
params = tool.parameters
|
||||
@@ -176,7 +177,7 @@ class TestMakeToolsEdgeCases:
|
||||
|
||||
def test_make_tools_required_params_in_properties(self, memory):
|
||||
"""Should have required params defined in properties."""
|
||||
tools = make_tools()
|
||||
tools = make_tools(settings)
|
||||
|
||||
for tool in tools.values():
|
||||
params = tool.parameters
|
||||
@@ -188,21 +189,21 @@ class TestMakeToolsEdgeCases:
|
||||
|
||||
def test_make_tools_descriptions_not_empty(self, memory):
|
||||
"""Should have non-empty descriptions."""
|
||||
tools = make_tools()
|
||||
tools = make_tools(settings)
|
||||
|
||||
for tool in tools.values():
|
||||
assert tool.description.strip() != ""
|
||||
|
||||
def test_make_tools_funcs_callable(self, memory):
|
||||
"""Should have callable functions."""
|
||||
tools = make_tools()
|
||||
tools = make_tools(settings)
|
||||
|
||||
for tool in tools.values():
|
||||
assert callable(tool.func)
|
||||
|
||||
def test_make_tools_expected_tools_present(self, memory):
|
||||
"""Should have expected tools."""
|
||||
tools = make_tools()
|
||||
tools = make_tools(settings)
|
||||
|
||||
expected = [
|
||||
"set_path_for_folder",
|
||||
@@ -220,14 +221,14 @@ class TestMakeToolsEdgeCases:
|
||||
|
||||
def test_make_tools_idempotent(self, memory):
|
||||
"""Should return same tools on multiple calls."""
|
||||
tools1 = make_tools()
|
||||
tools2 = make_tools()
|
||||
tools1 = make_tools(settings)
|
||||
tools2 = make_tools(settings)
|
||||
|
||||
assert set(tools1.keys()) == set(tools2.keys())
|
||||
|
||||
def test_make_tools_parameter_types(self, memory):
|
||||
"""Should have valid parameter types."""
|
||||
tools = make_tools()
|
||||
tools = make_tools(settings)
|
||||
|
||||
valid_types = ["string", "integer", "number", "boolean", "array", "object"]
|
||||
|
||||
@@ -241,7 +242,7 @@ class TestMakeToolsEdgeCases:
|
||||
|
||||
def test_make_tools_enum_values(self, memory):
|
||||
"""Should have valid enum values."""
|
||||
tools = make_tools()
|
||||
tools = make_tools(settings)
|
||||
|
||||
for tool in tools.values():
|
||||
if "properties" in tool.parameters:
|
||||
@@ -256,7 +257,7 @@ class TestToolExecution:
|
||||
|
||||
def test_tool_returns_dict(self, memory, real_folder):
|
||||
"""Should return dict from tool execution."""
|
||||
tools = make_tools()
|
||||
tools = make_tools(settings)
|
||||
memory.ltm.set_config("download_folder", str(real_folder["downloads"]))
|
||||
|
||||
result = tools["list_folder"].func(folder_type="download")
|
||||
@@ -265,7 +266,7 @@ class TestToolExecution:
|
||||
|
||||
def test_tool_returns_status(self, memory, real_folder):
|
||||
"""Should return status in result."""
|
||||
tools = make_tools()
|
||||
tools = make_tools(settings)
|
||||
memory.ltm.set_config("download_folder", str(real_folder["downloads"]))
|
||||
|
||||
result = tools["list_folder"].func(folder_type="download")
|
||||
@@ -274,14 +275,14 @@ class TestToolExecution:
|
||||
|
||||
def test_tool_handles_missing_args(self, memory):
|
||||
"""Should handle missing required arguments."""
|
||||
tools = make_tools()
|
||||
tools = make_tools(settings)
|
||||
|
||||
with pytest.raises(TypeError):
|
||||
tools["set_path_for_folder"].func() # Missing required args
|
||||
|
||||
def test_tool_handles_wrong_type_args(self, memory):
|
||||
"""Should handle wrong type arguments."""
|
||||
tools = make_tools()
|
||||
tools = make_tools(settings)
|
||||
|
||||
# Pass wrong type - should either work or raise
|
||||
try:
|
||||
@@ -293,7 +294,7 @@ class TestToolExecution:
|
||||
|
||||
def test_tool_handles_extra_args(self, memory, real_folder):
|
||||
"""Should handle extra arguments."""
|
||||
tools = make_tools()
|
||||
tools = make_tools(settings)
|
||||
memory.ltm.set_config("download_folder", str(real_folder["downloads"]))
|
||||
|
||||
# Extra args should raise TypeError
|
||||
|
||||
Reference in New Issue
Block a user