feat: added proper settings handling
This commit is contained in:
@@ -6,6 +6,8 @@ import pytest
|
||||
|
||||
from alfred.agent.agent import Agent
|
||||
from alfred.infrastructure.persistence import get_memory
|
||||
from alfred.settings import settings
|
||||
from conftest import mock_llm
|
||||
|
||||
|
||||
class TestExecuteToolCallEdgeCases:
|
||||
@@ -13,7 +15,7 @@ class TestExecuteToolCallEdgeCases:
|
||||
|
||||
def test_tool_returns_none(self, memory, mock_llm):
|
||||
"""Should handle tool returning None."""
|
||||
agent = Agent(llm=mock_llm)
|
||||
agent = Agent(settings=settings, llm=mock_llm)
|
||||
|
||||
# Mock a tool that returns None
|
||||
from alfred.agent.registry import Tool
|
||||
@@ -32,7 +34,7 @@ class TestExecuteToolCallEdgeCases:
|
||||
|
||||
def test_tool_raises_keyboard_interrupt(self, memory, mock_llm):
|
||||
"""Should propagate KeyboardInterrupt."""
|
||||
agent = Agent(llm=mock_llm)
|
||||
agent = Agent(settings=settings, llm=mock_llm)
|
||||
|
||||
from alfred.agent.registry import Tool
|
||||
|
||||
@@ -53,7 +55,7 @@ class TestExecuteToolCallEdgeCases:
|
||||
|
||||
def test_tool_with_extra_args(self, memory, mock_llm, real_folder):
|
||||
"""Should handle extra arguments gracefully."""
|
||||
agent = Agent(llm=mock_llm)
|
||||
agent = Agent(settings=settings, llm=mock_llm)
|
||||
memory.ltm.set_config("download_folder", str(real_folder["downloads"]))
|
||||
|
||||
tool_call = {
|
||||
@@ -70,7 +72,7 @@ class TestExecuteToolCallEdgeCases:
|
||||
|
||||
def test_tool_with_wrong_type_args(self, memory, mock_llm):
|
||||
"""Should handle wrong argument types."""
|
||||
agent = Agent(llm=mock_llm)
|
||||
agent = Agent(settings=settings, llm=mock_llm)
|
||||
|
||||
tool_call = {
|
||||
"id": "call_123",
|
||||
@@ -90,7 +92,7 @@ class TestStepEdgeCases:
|
||||
|
||||
def test_step_with_empty_input(self, memory, mock_llm):
|
||||
"""Should handle empty user input."""
|
||||
agent = Agent(llm=mock_llm)
|
||||
agent = Agent(settings=settings, llm=mock_llm)
|
||||
|
||||
response = agent.step("")
|
||||
|
||||
@@ -98,7 +100,7 @@ class TestStepEdgeCases:
|
||||
|
||||
def test_step_with_very_long_input(self, memory, mock_llm):
|
||||
"""Should handle very long user input."""
|
||||
agent = Agent(llm=mock_llm)
|
||||
agent = Agent(settings=settings, llm=mock_llm)
|
||||
|
||||
long_input = "x" * 100000
|
||||
response = agent.step(long_input)
|
||||
@@ -112,7 +114,7 @@ class TestStepEdgeCases:
|
||||
return {"role": "assistant", "content": "日本語の応答"}
|
||||
|
||||
mock_llm.complete = Mock(side_effect=mock_complete)
|
||||
agent = Agent(llm=mock_llm)
|
||||
agent = Agent(settings=settings, llm=mock_llm)
|
||||
|
||||
response = agent.step("日本語の質問")
|
||||
|
||||
@@ -125,7 +127,7 @@ class TestStepEdgeCases:
|
||||
return {"role": "assistant", "content": ""}
|
||||
|
||||
mock_llm.complete = Mock(side_effect=mock_complete)
|
||||
agent = Agent(llm=mock_llm)
|
||||
agent = Agent(settings=settings, llm=mock_llm)
|
||||
|
||||
response = agent.step("Hello")
|
||||
|
||||
@@ -134,7 +136,7 @@ class TestStepEdgeCases:
|
||||
def test_step_llm_raises_exception(self, memory, mock_llm):
|
||||
"""Should propagate LLM exceptions."""
|
||||
mock_llm.complete.side_effect = Exception("LLM Error")
|
||||
agent = Agent(llm=mock_llm)
|
||||
agent = Agent(settings=settings, llm=mock_llm)
|
||||
|
||||
with pytest.raises(Exception, match="LLM Error"):
|
||||
agent.step("Hello")
|
||||
@@ -162,7 +164,7 @@ class TestStepEdgeCases:
|
||||
return {"role": "assistant", "content": "Done looping"}
|
||||
|
||||
mock_llm.complete = Mock(side_effect=mock_complete)
|
||||
agent = Agent(llm=mock_llm, max_tool_iterations=3)
|
||||
agent = Agent(settings=settings, llm=mock_llm, max_tool_iterations=3)
|
||||
|
||||
agent.step("Loop test")
|
||||
|
||||
@@ -170,7 +172,7 @@ class TestStepEdgeCases:
|
||||
|
||||
def test_step_preserves_history_order(self, memory, mock_llm):
|
||||
"""Should preserve message order in history."""
|
||||
agent = Agent(llm=mock_llm)
|
||||
agent = Agent(settings=settings, llm=mock_llm)
|
||||
|
||||
agent.step("First")
|
||||
agent.step("Second")
|
||||
@@ -189,7 +191,7 @@ class TestStepEdgeCases:
|
||||
[{"index": 1, "label": "Option 1"}],
|
||||
{},
|
||||
)
|
||||
agent = Agent(llm=mock_llm)
|
||||
agent = Agent(settings=settings, llm=mock_llm)
|
||||
|
||||
agent.step("Hello")
|
||||
|
||||
@@ -206,7 +208,7 @@ class TestStepEdgeCases:
|
||||
"progress": 50,
|
||||
}
|
||||
)
|
||||
agent = Agent(llm=mock_llm)
|
||||
agent = Agent(settings=settings, llm=mock_llm)
|
||||
|
||||
agent.step("Hello")
|
||||
|
||||
@@ -217,7 +219,7 @@ class TestStepEdgeCases:
|
||||
def test_step_clears_events_after_notification(self, memory, mock_llm):
|
||||
"""Should mark events as read after notification."""
|
||||
memory.episodic.add_background_event("test_event", {"data": "test"})
|
||||
agent = Agent(llm=mock_llm)
|
||||
agent = Agent(settings=settings, llm=mock_llm)
|
||||
|
||||
agent.step("Hello")
|
||||
|
||||
@@ -230,8 +232,8 @@ class TestAgentConcurrencyEdgeCases:
|
||||
|
||||
def test_multiple_agents_same_memory(self, memory, mock_llm):
|
||||
"""Should handle multiple agents with same memory."""
|
||||
agent1 = Agent(llm=mock_llm)
|
||||
agent2 = Agent(llm=mock_llm)
|
||||
agent1 = Agent(settings=settings, llm=mock_llm)
|
||||
agent2 = Agent(settings=settings, llm=mock_llm)
|
||||
|
||||
agent1.step("From agent 1")
|
||||
agent2.step("From agent 2")
|
||||
@@ -266,7 +268,7 @@ class TestAgentConcurrencyEdgeCases:
|
||||
return {"role": "assistant", "content": "Path set successfully."}
|
||||
|
||||
mock_llm.complete = Mock(side_effect=mock_complete)
|
||||
agent = Agent(llm=mock_llm)
|
||||
agent = Agent(settings=settings, llm=mock_llm)
|
||||
|
||||
agent.step("Set movie folder")
|
||||
|
||||
@@ -300,7 +302,7 @@ class TestAgentErrorRecovery:
|
||||
return {"role": "assistant", "content": "The folder is not configured."}
|
||||
|
||||
mock_llm.complete = Mock(side_effect=mock_complete)
|
||||
agent = Agent(llm=mock_llm)
|
||||
agent = Agent(settings=settings, llm=mock_llm)
|
||||
|
||||
response = agent.step("List downloads")
|
||||
|
||||
@@ -329,7 +331,7 @@ class TestAgentErrorRecovery:
|
||||
return {"role": "assistant", "content": "Error occurred."}
|
||||
|
||||
mock_llm.complete = Mock(side_effect=mock_complete)
|
||||
agent = Agent(llm=mock_llm)
|
||||
agent = Agent(settings=settings, llm=mock_llm)
|
||||
|
||||
agent.step("Set folder")
|
||||
|
||||
@@ -359,7 +361,7 @@ class TestAgentErrorRecovery:
|
||||
return {"role": "assistant", "content": "All attempts failed."}
|
||||
|
||||
mock_llm.complete = Mock(side_effect=mock_complete)
|
||||
agent = Agent(llm=mock_llm, max_tool_iterations=3)
|
||||
agent = Agent(settings=settings, llm=mock_llm, max_tool_iterations=3)
|
||||
|
||||
agent.step("Try multiple times")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user