forked from HAL9000/cleveragents-core
127 lines
3.3 KiB
Python
127 lines
3.3 KiB
Python
"""
|
|
BDD step definitions for routing prefix stripping testing.
|
|
"""
|
|
|
|
import tempfile
|
|
from pathlib import Path
|
|
|
|
from behave import given, then, when
|
|
from behave.runner import Context
|
|
|
|
from cleveragents.core.application import ReactiveCleverAgentsApp
|
|
|
|
|
|
@given("the routing prefix test environment is initialized")
|
|
def step_routing_prefix_test_env_initialized(context: Context):
|
|
"""Initialize the routing prefix test environment."""
|
|
context.scenario_temp = Path(tempfile.mkdtemp())
|
|
context.content = None
|
|
context.result = None
|
|
context.app = None
|
|
|
|
|
|
@given('I have content with prefix "{prefix}" and message "{message}"')
|
|
def step_have_content_with_prefix_and_message(context: Context, prefix: str, message: str):
|
|
"""Set content with a specific prefix and message."""
|
|
context.content = f"{prefix}{message}"
|
|
|
|
|
|
@given('I have content "{content}"')
|
|
def step_have_content(context: Context, content: str):
|
|
"""Set content."""
|
|
context.content = content
|
|
|
|
|
|
@when("I strip routing prefixes from the content")
|
|
def step_strip_routing_prefixes(context: Context):
|
|
"""Strip routing prefixes from content."""
|
|
# Create a minimal app to test the method
|
|
config_file = context.scenario_temp / "test_config.yaml"
|
|
config_file.write_text(
|
|
"""
|
|
agents:
|
|
test_agent:
|
|
type: llm
|
|
config:
|
|
provider: openai
|
|
model: gpt-3.5-turbo
|
|
|
|
routes:
|
|
main:
|
|
type: stream
|
|
stream_type: cold
|
|
operators:
|
|
- type: map
|
|
params:
|
|
agent: test_agent
|
|
publications:
|
|
- __output__
|
|
|
|
merges:
|
|
- sources: [__input__]
|
|
target: main
|
|
"""
|
|
)
|
|
|
|
context.app = ReactiveCleverAgentsApp([config_file], verbose=0, unsafe=False)
|
|
context.result = context.app._strip_routing_prefixes(context.content)
|
|
|
|
|
|
@when("I process tool commands on the content")
|
|
def step_process_tool_commands(context: Context):
|
|
"""Process tool commands on content."""
|
|
# Create a minimal app to test the method
|
|
config_file = context.scenario_temp / "test_config.yaml"
|
|
config_file.write_text(
|
|
"""
|
|
agents:
|
|
test_agent:
|
|
type: llm
|
|
config:
|
|
provider: openai
|
|
model: gpt-3.5-turbo
|
|
|
|
routes:
|
|
main:
|
|
type: stream
|
|
stream_type: cold
|
|
operators:
|
|
- type: map
|
|
params:
|
|
agent: test_agent
|
|
publications:
|
|
- __output__
|
|
|
|
merges:
|
|
- sources: [__input__]
|
|
target: main
|
|
"""
|
|
)
|
|
|
|
context.app = ReactiveCleverAgentsApp([config_file], verbose=0, unsafe=False)
|
|
context.result = context.app._process_tool_commands(context.content)
|
|
|
|
|
|
@then('the stripped result should be "{expected}"')
|
|
def step_routing_prefix_result_should_be(context: Context, expected: str):
|
|
"""Verify the result matches expected value."""
|
|
assert context.result == expected, f"Expected '{expected}', got '{context.result}'"
|
|
|
|
|
|
@given('I have content with prefix "{prefix}" and message ""')
|
|
def step_have_content_with_prefix_and_empty_message(context: Context, prefix: str):
|
|
"""Set content with a specific prefix and empty message."""
|
|
context.content = prefix
|
|
|
|
|
|
@then('the stripped result should be ""')
|
|
def step_result_should_be_empty(context: Context):
|
|
"""Verify the result is empty."""
|
|
assert context.result == "", f"Expected empty string, got '{context.result}'"
|
|
|
|
|
|
@given('I have content ""')
|
|
def step_have_empty_content(context: Context):
|
|
"""Set empty content."""
|
|
context.content = ""
|