mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-23 04:01:02 +02:00
Fix the tests
This commit is contained in:
parent
7cb0c916cf
commit
e434e03cfa
1 changed files with 46 additions and 20 deletions
|
|
@ -465,37 +465,63 @@ Args: {args_json}"""
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_agent_manager_malformed_response_handling(self, agent_manager, mock_flow_context):
|
async def test_agent_manager_malformed_response_handling(self, agent_manager, mock_flow_context):
|
||||||
"""Test agent manager handling of malformed text responses"""
|
"""Test agent manager handling of malformed text responses"""
|
||||||
# Test various malformed responses
|
# Test cases with expected error messages
|
||||||
malformed_responses = [
|
test_cases = [
|
||||||
# Missing required fields
|
# Missing action/final answer
|
||||||
"Thought: I need to do something",
|
{
|
||||||
|
"response": "Thought: I need to do something",
|
||||||
|
"error_contains": "Response has thought but no action or final answer"
|
||||||
|
},
|
||||||
# Invalid JSON in Args
|
# Invalid JSON in Args
|
||||||
"""Thought: I need to search
|
{
|
||||||
|
"response": """Thought: I need to search
|
||||||
Action: knowledge_query
|
Action: knowledge_query
|
||||||
Args: {invalid json}""",
|
Args: {invalid json}""",
|
||||||
|
"error_contains": "Invalid JSON in Args"
|
||||||
|
},
|
||||||
# Empty response
|
# Empty response
|
||||||
"",
|
{
|
||||||
|
"response": "",
|
||||||
|
"error_contains": "Could not parse response"
|
||||||
|
},
|
||||||
# Only whitespace
|
# Only whitespace
|
||||||
" \n\t ",
|
{
|
||||||
# Missing Args for action
|
"response": " \n\t ",
|
||||||
"""Thought: I need to search
|
"error_contains": "Could not parse response"
|
||||||
|
},
|
||||||
|
# Missing Args for action (should create empty args dict)
|
||||||
|
{
|
||||||
|
"response": """Thought: I need to search
|
||||||
Action: knowledge_query""",
|
Action: knowledge_query""",
|
||||||
|
"error_contains": None # This should actually succeed with empty args
|
||||||
|
},
|
||||||
# Incomplete JSON
|
# Incomplete JSON
|
||||||
"""Thought: I need to search
|
{
|
||||||
|
"response": """Thought: I need to search
|
||||||
Action: knowledge_query
|
Action: knowledge_query
|
||||||
Args: {
|
Args: {
|
||||||
"question": "test"
|
"question": "test"
|
||||||
""",
|
""",
|
||||||
|
"error_contains": "Invalid JSON in Args"
|
||||||
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
for response in malformed_responses:
|
for test_case in test_cases:
|
||||||
mock_flow_context("prompt-request").agent_react.return_value = response
|
mock_flow_context("prompt-request").agent_react.return_value = test_case["response"]
|
||||||
|
|
||||||
# Act & Assert
|
if test_case["error_contains"]:
|
||||||
with pytest.raises(RuntimeError) as exc_info:
|
# Should raise an error
|
||||||
await agent_manager.reason("test question", [], mock_flow_context)
|
with pytest.raises(RuntimeError) as exc_info:
|
||||||
|
await agent_manager.reason("test question", [], mock_flow_context)
|
||||||
assert "Failed to parse agent response" in str(exc_info.value)
|
|
||||||
|
assert "Failed to parse agent response" in str(exc_info.value)
|
||||||
|
assert test_case["error_contains"] in str(exc_info.value)
|
||||||
|
else:
|
||||||
|
# Should succeed
|
||||||
|
action = await agent_manager.reason("test question", [], mock_flow_context)
|
||||||
|
assert isinstance(action, Action)
|
||||||
|
assert action.name == "knowledge_query"
|
||||||
|
assert action.arguments == {}
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_agent_manager_text_parsing_edge_cases(self, agent_manager, mock_flow_context):
|
async def test_agent_manager_text_parsing_edge_cases(self, agent_manager, mock_flow_context):
|
||||||
|
|
@ -566,11 +592,11 @@ This covers all aspects of the question."""
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_agent_manager_json_args_special_characters(self, agent_manager, mock_flow_context):
|
async def test_agent_manager_json_args_special_characters(self, agent_manager, mock_flow_context):
|
||||||
"""Test JSON arguments with special characters and edge cases"""
|
"""Test JSON arguments with special characters and edge cases"""
|
||||||
# Test with special characters in JSON
|
# Test with special characters in JSON (properly escaped)
|
||||||
mock_flow_context("prompt-request").agent_react.return_value = """Thought: Processing special characters
|
mock_flow_context("prompt-request").agent_react.return_value = """Thought: Processing special characters
|
||||||
Action: knowledge_query
|
Action: knowledge_query
|
||||||
Args: {
|
Args: {
|
||||||
"question": "What about \"quotes\" and 'apostrophes'?",
|
"question": "What about \\"quotes\\" and 'apostrophes'?",
|
||||||
"context": "Line 1\\nLine 2\\tTabbed",
|
"context": "Line 1\\nLine 2\\tTabbed",
|
||||||
"special": "Symbols: @#$%^&*()_+-=[]{}|;':,.<>?"
|
"special": "Symbols: @#$%^&*()_+-=[]{}|;':,.<>?"
|
||||||
}"""
|
}"""
|
||||||
|
|
@ -578,7 +604,7 @@ Args: {
|
||||||
action = await agent_manager.reason("test", [], mock_flow_context)
|
action = await agent_manager.reason("test", [], mock_flow_context)
|
||||||
assert isinstance(action, Action)
|
assert isinstance(action, Action)
|
||||||
assert action.arguments["question"] == 'What about "quotes" and \'apostrophes\'?'
|
assert action.arguments["question"] == 'What about "quotes" and \'apostrophes\'?'
|
||||||
assert "\\n" in action.arguments["context"]
|
assert action.arguments["context"] == "Line 1\nLine 2\tTabbed"
|
||||||
assert "@#$%^&*" in action.arguments["special"]
|
assert "@#$%^&*" in action.arguments["special"]
|
||||||
|
|
||||||
# Test with nested JSON
|
# Test with nested JSON
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue