forked from HAL9000/cleveragents-core
105 lines
3.4 KiB
Python
105 lines
3.4 KiB
Python
import asyncio
|
|
import os
|
|
import tempfile
|
|
from pathlib import Path
|
|
from unittest.mock import MagicMock
|
|
from unittest.mock import patch
|
|
|
|
from behave import given
|
|
from behave import then
|
|
from behave import when
|
|
from click.testing import CliRunner
|
|
|
|
from cleveragents.cli import main
|
|
|
|
|
|
@given("the CleverAgents CLI")
|
|
def step_impl(context):
|
|
context.runner = CliRunner()
|
|
# Create a temporary directory for output files
|
|
context.temp_dir = tempfile.TemporaryDirectory()
|
|
context.output_dir = Path(context.temp_dir.name)
|
|
|
|
|
|
@when("I run the CLI with a prompt")
|
|
def step_impl(context):
|
|
# Mock the CleverAgentsApp to avoid actual processing
|
|
with patch("cleveragents.core.application.CleverAgentsApp") as MockApp:
|
|
# Configure the mock
|
|
mock_app_instance = MockApp.return_value
|
|
|
|
async def mock_run_single_shot(prompt):
|
|
return f"Response to: {prompt}"
|
|
|
|
mock_app_instance.run_single_shot = mock_run_single_shot
|
|
|
|
# Run the CLI command
|
|
context.result = context.runner.invoke(
|
|
main, ["run", "--prompt", "Hello, agent!"]
|
|
)
|
|
|
|
|
|
@then("the prompt should be processed")
|
|
def step_impl(context):
|
|
# Check that the command executed successfully
|
|
assert context.result.exit_code == 0
|
|
|
|
|
|
@then("I should receive a response")
|
|
def step_impl(context):
|
|
# Check that the output contains the expected response
|
|
assert "Response to: Hello, agent!" in context.result.output
|
|
|
|
|
|
@when("I run the CLI in interactive mode")
|
|
def step_impl(context):
|
|
# Mock the interactive session
|
|
with patch("cleveragents.core.application.CleverAgentsApp") as MockApp:
|
|
mock_app_instance = MockApp.return_value
|
|
mock_app_instance.start_interactive_session = MagicMock()
|
|
# Run the CLI command
|
|
context.result = context.runner.invoke(main, ["interactive"], input="\n")
|
|
|
|
|
|
@then("an interactive session should be started")
|
|
def step_impl(context):
|
|
assert context.result.exit_code == 0
|
|
|
|
|
|
@when("I run the CLI with the generate-examples command")
|
|
def step_impl(context):
|
|
with patch("cleveragents.core.application.CleverAgentsApp") as MockApp:
|
|
mock_app_instance = MockApp.return_value
|
|
mock_app_instance.generate_example_configurations = MagicMock()
|
|
output_path = context.output_dir / "examples"
|
|
context.result = context.runner.invoke(
|
|
main, ["generate-examples", "--output", str(output_path)]
|
|
)
|
|
|
|
|
|
@then("example configurations should be generated")
|
|
def step_impl(context):
|
|
assert context.result.exit_code == 0
|
|
with patch("cleveragents.core.application.CleverAgentsApp") as MockApp:
|
|
mock_app_instance = MockApp.return_value
|
|
assert mock_app_instance.generate_example_configurations.called
|
|
|
|
|
|
@when("I run the CLI with the visualize command")
|
|
def step_impl(context):
|
|
with patch("cleveragents.core.application.CleverAgentsApp") as MockApp:
|
|
mock_app_instance = MockApp.return_value
|
|
mock_app_instance.visualize_network = MagicMock()
|
|
output_path = context.output_dir / "network.svg"
|
|
context.result = context.runner.invoke(
|
|
main, ["visualize", "--output", str(output_path)]
|
|
)
|
|
|
|
|
|
@then("a network visualization should be generated")
|
|
def step_impl(context):
|
|
assert context.result.exit_code == 0
|
|
with patch("cleveragents.core.application.CleverAgentsApp") as MockApp:
|
|
mock_app_instance = MockApp.return_value
|
|
assert mock_app_instance.visualize_network.called
|