Files
cleveractors-core/features/tool_agent_coverage.feature
2026-05-27 21:41:03 +00:00

185 lines
5.9 KiB
Gherkin

Feature: ToolAgent Coverage Enhancement
Additional test scenarios to achieve 90%+ coverage for tool.py
@coverage
Scenario: Tool agent with general exception handling in process_message
Given a ToolAgent is configured with name "exception_agent" and config
"""
{
"tools": ["echo"]
}
"""
When I create the ToolAgent
And I process a malformed message causing general exception
Then tool execution should fail with message containing "Tool execution failed"
@coverage
Scenario: Tool agent JSON parse tool with empty string
Given a ToolAgent is configured with name "json_empty_agent" and config
"""
{
"tools": ["json_parse"]
}
"""
When I create the ToolAgent
And I process a JSON message with the ToolAgent:
"""
{"tool": "json_parse", "args": {"json": ""}}
"""
Then tool execution should fail with message containing "JSON parsing failed"
@coverage
Scenario: Tool agent echo tool with empty text parameter
Given a ToolAgent is configured with name "echo_empty_text_agent" and config
"""
{
"tools": ["echo"]
}
"""
When I create the ToolAgent
And I process a JSON message with the ToolAgent:
"""
{"tool": "echo", "args": {"text": ""}}
"""
Then the result should be ""
@coverage
Scenario: Tool agent math tool with empty args list
Given a ToolAgent is configured with name "math_empty_args_agent" and config
"""
{
"tools": ["math"]
}
"""
When I create the ToolAgent
And I process a JSON message with the ToolAgent:
"""
{"tool": "math", "args": {"args": []}}
"""
Then tool execution should fail with message containing "Math tool requires an expression"
@coverage
Scenario: Tool agent json_parse tool with empty args list
Given a ToolAgent is configured with name "json_empty_args_agent" and config
"""
{
"tools": ["json_parse"]
}
"""
When I create the ToolAgent
And I process a JSON message with the ToolAgent:
"""
{"tool": "json_parse", "args": {"args": []}}
"""
Then tool execution should fail with message containing "JSON parsing failed"
@coverage
Scenario: Tool agent file_read tool with empty args list
Given I am running in unsafe mode
And a ToolAgent is configured with name "file_empty_args_agent" and config
"""
{
"tools": ["file_read"]
}
"""
When I create the ToolAgent
And I process a JSON message with the ToolAgent:
"""
{"tool": "file_read", "args": {"args": []}}
"""
Then tool execution should fail with message containing "File read tool requires a file path"
@coverage
Scenario: Tool agent file_read with directory traversal that gets blocked
Given I am running in unsafe mode
And a ToolAgent is configured with name "file_traversal_agent" and config
"""
{
"tools": ["file_read"],
"safe_mode": true
}
"""
When I create the ToolAgent
And I process a JSON message with the ToolAgent:
"""
{"tool": "file_read", "args": {"args": ["../../../etc/passwd"]}}
"""
Then tool execution should fail with message containing "Unsafe file path blocked in safe mode"
@coverage
Scenario: Tool agent shell command with dangerous command variations
Given I am running in unsafe mode
And a ToolAgent is configured with name "dangerous_shell_agent" and config
"""
{
"tools": ["DEL", "FORMAT", "SHUTDOWN", "REBOOT", "KILL"],
"allow_shell": true,
"safe_mode": true
}
"""
When I create the ToolAgent
And I process a message with the ToolAgent: "DEL important_file"
Then tool execution should fail with message containing "Dangerous command 'DEL' blocked in safe mode"
@coverage
Scenario: Tool agent shell command execution args handling
Given I am running in unsafe mode
And a ToolAgent is configured with name "shell_args_agent" and config
"""
{
"tools": ["echo"],
"allow_shell": true,
"safe_mode": false
}
"""
When I create the ToolAgent
And I process a message with the ToolAgent: "echo hello world test"
Then the result should be "hello world test"
@coverage
Scenario: Tool agent file_write with absolute path and unsafe context
Given I am running in unsafe mode
And a ToolAgent is configured with name "file_write_abs_unsafe_agent" and config
"""
{
"tools": ["file_write"],
"safe_mode": true
}
"""
When I create the ToolAgent
And I process a JSON message with unsafe context with the ToolAgent:
"""
{"tool": "file_write", "args": {"file": "/tmp/test_write_abs.txt", "content": "test content"}}
"""
Then the tool result should contain "Successfully wrote"
@coverage
Scenario: Tool agent file_read with absolute path and unsafe context succeeds
Given I am running in unsafe mode
And a ToolAgent is configured with name "file_read_abs_context_agent" and config
"""
{
"tools": ["file_read"],
"safe_mode": true
}
"""
When I create the ToolAgent
And I create an absolute test file with content "absolute test content"
And I process a JSON message with unsafe context with the ToolAgent:
"""
{"tool": "file_read", "args": {"file": "/tmp/test_abs_file.txt"}}
"""
Then the result should contain "absolute test content"
@coverage
Scenario: Execute tool with no agent available
Given an application with no tool agents
When executing tool "missing_tool" with empty params
Then tool execution returns "No agent available" error
@coverage
Scenario: Process tool command with malformed JSON
Given an application with tool agent
When processing content with invalid tool JSON
Then result contains "Invalid tool parameters" error