284d2a9f00
CI / quality (pull_request) Successful in 37s
CI / lint (pull_request) Successful in 49s
CI / typecheck (pull_request) Successful in 50s
CI / build (pull_request) Successful in 50s
CI / security (pull_request) Successful in 55s
CI / integration_tests (pull_request) Successful in 59s
CI / unit_tests (pull_request) Successful in 3m38s
CI / coverage (pull_request) Successful in 3m35s
CI / status-check (pull_request) Successful in 4s
CI / lint (push) Successful in 33s
CI / quality (push) Successful in 58s
CI / typecheck (push) Successful in 1m1s
CI / security (push) Successful in 1m1s
CI / build (push) Successful in 52s
CI / integration_tests (push) Successful in 1m12s
CI / unit_tests (push) Successful in 3m41s
CI / coverage (push) Successful in 3m35s
CI / status-check (push) Successful in 3s
Extend TemplateType enum with TEMPLATE, SKILL, ACTOR, MCP, LSP. Add optional package_ref field to ComponentReference for registry references. Create ReferenceResolver with multi-server RegistryClient pool and caching. Update InstantiationContext for registry-aware resolution with _original_reference. Extend TemplateRegistry, EnhancedTemplateRegistry, and TemplateStore for 8 types. Add registry reference detection in instantiate_from_config. Add GenericTemplate for new package types without specialized template classes. ISSUES CLOSED: #27
1097 lines
36 KiB
Python
1097 lines
36 KiB
Python
"""
|
|
Step definitions for Template Registry Instantiation from Configuration BDD tests.
|
|
"""
|
|
|
|
from typing import Any, Dict
|
|
from unittest.mock import patch
|
|
|
|
from behave import given, then, when
|
|
|
|
from cleveractors.templates.base import BaseTemplate, InstantiationContext, TemplateType
|
|
from cleveractors.templates.registry import TemplateRegistry
|
|
|
|
|
|
# Mock template classes for testing
|
|
class MockBaseTemplate(BaseTemplate):
|
|
"""Mock base template for testing."""
|
|
|
|
def __init__(
|
|
self, name: str, template_type: TemplateType, definition: Dict[str, Any]
|
|
):
|
|
super().__init__(name, template_type, definition)
|
|
self.instantiate_calls = []
|
|
|
|
def instantiate(
|
|
self, params: Dict[str, Any], registry, context: InstantiationContext
|
|
) -> Any:
|
|
self.instantiate_calls.append((params, registry, context))
|
|
return {
|
|
"instantiated": f"{self.template_type.value}:{self.name}",
|
|
"params": params,
|
|
}
|
|
|
|
|
|
class MockAgentTemplate(MockBaseTemplate):
|
|
"""Mock agent template."""
|
|
|
|
pass
|
|
|
|
|
|
class MockCompositeAgentTemplate(MockBaseTemplate):
|
|
"""Mock composite agent template."""
|
|
|
|
pass
|
|
|
|
|
|
class MockGraphTemplate(MockBaseTemplate):
|
|
"""Mock graph template."""
|
|
|
|
pass
|
|
|
|
|
|
class MockStreamTemplate(MockBaseTemplate):
|
|
"""Mock stream template."""
|
|
|
|
pass
|
|
|
|
|
|
class MockGraphConfig:
|
|
"""Mock GraphConfig for testing."""
|
|
|
|
def __init__(self, **kwargs):
|
|
self.config = kwargs
|
|
|
|
|
|
class MockStreamConfig:
|
|
"""Mock StreamConfig for testing."""
|
|
|
|
def __init__(self, **kwargs):
|
|
self.config = kwargs
|
|
|
|
|
|
@given("I have a clean test environment for registry")
|
|
def step_clean_environment_registry(context):
|
|
"""Set up clean test environment for registry."""
|
|
# Initialize all context attributes
|
|
context.registry = None
|
|
context.template_definitions = {}
|
|
context.templates_config = {}
|
|
context.registry_config = {} # Renamed to avoid conflict
|
|
context.instantiation_context = None
|
|
context.result = None
|
|
context.error = None
|
|
context.template_type = None
|
|
context.template_name = None
|
|
|
|
|
|
@given("I create a new template registry")
|
|
def step_create_new_template_registry(context):
|
|
"""Create a new template registry."""
|
|
context.registry = TemplateRegistry()
|
|
|
|
|
|
@given("I have a template registry for registry testing")
|
|
def step_have_template_registry_testing(context):
|
|
"""Create template registry for testing."""
|
|
context.registry = TemplateRegistry()
|
|
|
|
|
|
@given("I have a normal agent template definition")
|
|
def step_normal_agent_template_definition(context):
|
|
"""Create normal agent template definition."""
|
|
context.template_definitions["normal_agent"] = {
|
|
"type": "llm",
|
|
"config": {"model": "gpt-3.5-turbo", "temperature": 0.7},
|
|
}
|
|
context.template_type = TemplateType.AGENT
|
|
context.template_name = "normal_agent"
|
|
|
|
|
|
@given("I have a composite agent template definition")
|
|
def step_composite_agent_template_definition(context):
|
|
"""Create composite agent template definition."""
|
|
context.template_definitions["composite_agent"] = {
|
|
"type": "composite",
|
|
"agents": ["agent1", "agent2"],
|
|
"coordination": "sequential",
|
|
}
|
|
context.template_type = TemplateType.AGENT
|
|
context.template_name = "composite_agent"
|
|
|
|
|
|
@given("I have a graph template definition")
|
|
def step_graph_template_definition(context):
|
|
"""Create graph template definition."""
|
|
context.template_definitions["test_graph"] = {
|
|
"nodes": ["node1", "node2"],
|
|
"edges": [("node1", "node2")],
|
|
"config": {"timeout": 30},
|
|
}
|
|
context.template_type = TemplateType.GRAPH
|
|
context.template_name = "test_graph"
|
|
|
|
|
|
@given("I have a stream template definition")
|
|
def step_stream_template_definition(context):
|
|
"""Create stream template definition."""
|
|
context.template_definitions["test_stream"] = {
|
|
"type": "stream",
|
|
"operators": [{"type": "map", "params": {"agent": "test_agent"}}],
|
|
"publications": ["output"],
|
|
}
|
|
context.template_type = TemplateType.STREAM
|
|
context.template_name = "test_stream"
|
|
|
|
|
|
@given("I have an invalid template definition")
|
|
def step_invalid_template_definition(context):
|
|
"""Create invalid template definition."""
|
|
context.template_definitions["invalid"] = {"type": "unknown", "config": {}}
|
|
# Create a fake template type for testing invalid case
|
|
context.template_type = "INVALID"
|
|
context.template_name = "invalid"
|
|
|
|
|
|
@given("I have registered templates of all types")
|
|
def step_registered_templates_all_types(context):
|
|
"""Register templates of all types."""
|
|
# Mock the template imports
|
|
with (
|
|
patch(
|
|
"cleveractors.templates.agent_templates.AgentTemplate", MockAgentTemplate
|
|
),
|
|
patch(
|
|
"cleveractors.templates.agent_templates.CompositeAgentTemplate",
|
|
MockCompositeAgentTemplate,
|
|
),
|
|
patch(
|
|
"cleveractors.templates.graph_templates.GraphTemplate", MockGraphTemplate
|
|
),
|
|
patch(
|
|
"cleveractors.templates.stream_templates.StreamTemplate", MockStreamTemplate
|
|
),
|
|
):
|
|
# Register agent template
|
|
context.registry.register_template(
|
|
TemplateType.AGENT, "test_agent", {"type": "llm"}
|
|
)
|
|
|
|
# Register graph template
|
|
context.registry.register_template(
|
|
TemplateType.GRAPH, "test_graph", {"nodes": ["n1"]}
|
|
)
|
|
|
|
# Register stream template
|
|
context.registry.register_template(
|
|
TemplateType.STREAM, "test_stream", {"operators": []}
|
|
)
|
|
|
|
|
|
@given("I have registered a test template")
|
|
def step_registered_test_template(context):
|
|
"""Register a test template."""
|
|
with patch(
|
|
"cleveractors.templates.agent_templates.AgentTemplate", MockAgentTemplate
|
|
):
|
|
context.registry.register_template(
|
|
TemplateType.AGENT, "test_template", {"type": "llm"}
|
|
)
|
|
context.template_type = TemplateType.AGENT
|
|
context.template_name = "test_template"
|
|
|
|
|
|
@given("I have registered a template for instantiation")
|
|
def step_registered_template_for_instantiation(context):
|
|
"""Register template for instantiation testing."""
|
|
with patch(
|
|
"cleveractors.templates.agent_templates.AgentTemplate", MockAgentTemplate
|
|
):
|
|
context.registry.register_template(
|
|
TemplateType.AGENT, "instantiate_test", {"type": "llm"}
|
|
)
|
|
context.template_type = TemplateType.AGENT
|
|
context.template_name = "instantiate_test"
|
|
|
|
|
|
@given("I have an instantiation context for registry")
|
|
def step_instantiation_context_registry(context):
|
|
"""Create instantiation context for registry."""
|
|
context.instantiation_context = InstantiationContext()
|
|
|
|
|
|
@given("I have registered templates for config instantiation")
|
|
def step_registered_templates_config_instantiation(context):
|
|
"""Register templates for config-based instantiation."""
|
|
with (
|
|
patch(
|
|
"cleveractors.templates.agent_templates.AgentTemplate", MockAgentTemplate
|
|
),
|
|
patch(
|
|
"cleveractors.templates.graph_templates.GraphTemplate", MockGraphTemplate
|
|
),
|
|
patch(
|
|
"cleveractors.templates.stream_templates.StreamTemplate", MockStreamTemplate
|
|
),
|
|
):
|
|
context.registry.register_template(
|
|
TemplateType.AGENT, "config_agent", {"type": "llm"}
|
|
)
|
|
context.registry.register_template(
|
|
TemplateType.GRAPH, "config_graph", {"nodes": ["n1"]}
|
|
)
|
|
context.registry.register_template(
|
|
TemplateType.STREAM, "config_stream", {"operators": []}
|
|
)
|
|
|
|
|
|
@given("I have a config with template reference")
|
|
def step_config_template_reference(context):
|
|
"""Create config with template reference."""
|
|
context.registry_config = {
|
|
"template": "config_agent",
|
|
"params": {"model": "gpt-4", "temperature": 0.5},
|
|
}
|
|
|
|
|
|
@given("I have a config with non-existent template reference")
|
|
def step_config_nonexistent_template_reference(context):
|
|
"""Create config with non-existent template reference."""
|
|
context.registry_config = {
|
|
"template": "nonexistent_template",
|
|
"params": {"model": "gpt-4"},
|
|
}
|
|
|
|
|
|
@given("I have registered an agent template")
|
|
def step_registered_agent_template(context):
|
|
"""Register an agent template."""
|
|
with patch(
|
|
"cleveractors.templates.agent_templates.AgentTemplate", MockAgentTemplate
|
|
):
|
|
context.registry.register_template(
|
|
TemplateType.AGENT, "specific_agent", {"type": "llm"}
|
|
)
|
|
|
|
|
|
@given("I have a config with agent_template reference")
|
|
def step_config_agent_template_reference(context):
|
|
"""Create config with agent_template reference."""
|
|
context.registry_config = {
|
|
"agent_template": "specific_agent",
|
|
"params": {"model": "gpt-4"},
|
|
}
|
|
|
|
|
|
@given("I have registered a graph template")
|
|
def step_registered_graph_template(context):
|
|
"""Register a graph template."""
|
|
with patch(
|
|
"cleveractors.templates.graph_templates.GraphTemplate", MockGraphTemplate
|
|
):
|
|
context.registry.register_template(
|
|
TemplateType.GRAPH, "specific_graph", {"nodes": ["n1"]}
|
|
)
|
|
|
|
|
|
@given("I have a config with graph_template reference")
|
|
def step_config_graph_template_reference(context):
|
|
"""Create config with graph_template reference."""
|
|
context.registry_config = {
|
|
"graph_template": "specific_graph",
|
|
"params": {"timeout": 60},
|
|
}
|
|
|
|
|
|
@given("I have registered a stream template")
|
|
def step_registered_stream_template(context):
|
|
"""Register a stream template."""
|
|
with patch(
|
|
"cleveractors.templates.stream_templates.StreamTemplate", MockStreamTemplate
|
|
):
|
|
context.registry.register_template(
|
|
TemplateType.STREAM, "specific_stream", {"operators": []}
|
|
)
|
|
|
|
|
|
@given("I have a config with stream_template reference")
|
|
def step_config_stream_template_reference(context):
|
|
"""Create config with stream_template reference."""
|
|
context.registry_config = {
|
|
"stream_template": "specific_stream",
|
|
"params": {"buffer_size": 100},
|
|
}
|
|
|
|
|
|
@given("I have a config with direct agent definition")
|
|
def step_config_direct_agent_definition(context):
|
|
"""Create config with direct agent definition."""
|
|
context.registry_config = {
|
|
"type": "llm",
|
|
"config": {"model": "gpt-3.5-turbo", "temperature": 0.7},
|
|
}
|
|
|
|
|
|
@given("I have a config with direct graph definition")
|
|
def step_config_direct_graph_definition(context):
|
|
"""Create config with direct graph definition."""
|
|
context.registry_config = {
|
|
"nodes": ["node1", "node2"],
|
|
"edges": [("node1", "node2")],
|
|
}
|
|
|
|
|
|
@given("I have a config with direct stream definition")
|
|
def step_config_direct_stream_definition(context):
|
|
"""Create config with direct stream definition."""
|
|
context.registry_config = {
|
|
"operators": [{"type": "map", "params": {"agent": "test"}}],
|
|
"publications": ["output"],
|
|
}
|
|
|
|
|
|
@given("I have an unrecognizable config")
|
|
def step_unrecognizable_config(context):
|
|
"""Create unrecognizable config."""
|
|
context.registry_config = {"unknown_field": "unknown_value", "random_data": 123}
|
|
|
|
|
|
@given("I have a comprehensive templates configuration")
|
|
def step_comprehensive_templates_configuration(context):
|
|
"""Create comprehensive templates configuration."""
|
|
context.templates_config = {
|
|
"agents": {
|
|
"agent1": {"type": "llm", "config": {"model": "gpt-3.5-turbo"}},
|
|
"agent2": {"type": "composite", "agents": ["sub1", "sub2"]},
|
|
},
|
|
"graphs": {
|
|
"graph1": {"nodes": ["n1", "n2"], "edges": [("n1", "n2")]},
|
|
"graph2": {"nodes": ["n3"], "edges": []},
|
|
},
|
|
"streams": {
|
|
"stream1": {"operators": [{"type": "map"}]},
|
|
"stream2": {"operators": [{"type": "filter"}]},
|
|
},
|
|
}
|
|
|
|
|
|
@given("I have an empty templates configuration")
|
|
def step_empty_templates_configuration(context):
|
|
"""Create empty templates configuration."""
|
|
context.templates_config = {"agents": {}, "graphs": {}, "streams": {}}
|
|
|
|
|
|
@when("I register the agent template")
|
|
def step_register_agent_template(context):
|
|
"""Register the agent template."""
|
|
try:
|
|
with patch(
|
|
"cleveractors.templates.agent_templates.AgentTemplate", MockAgentTemplate
|
|
):
|
|
context.registry.register_template(
|
|
context.template_type,
|
|
context.template_name,
|
|
context.template_definitions[context.template_name],
|
|
)
|
|
except Exception as e:
|
|
context.error = e
|
|
|
|
|
|
@when("I register the composite agent template")
|
|
def step_register_composite_agent_template(context):
|
|
"""Register the composite agent template."""
|
|
try:
|
|
with patch(
|
|
"cleveractors.templates.agent_templates.CompositeAgentTemplate",
|
|
MockCompositeAgentTemplate,
|
|
):
|
|
context.registry.register_template(
|
|
context.template_type,
|
|
context.template_name,
|
|
context.template_definitions[context.template_name],
|
|
)
|
|
except Exception as e:
|
|
context.error = e
|
|
|
|
|
|
@when("I register the graph template")
|
|
def step_register_graph_template(context):
|
|
"""Register the graph template."""
|
|
try:
|
|
with patch(
|
|
"cleveractors.templates.graph_templates.GraphTemplate", MockGraphTemplate
|
|
):
|
|
context.registry.register_template(
|
|
context.template_type,
|
|
context.template_name,
|
|
context.template_definitions[context.template_name],
|
|
)
|
|
except Exception as e:
|
|
context.error = e
|
|
|
|
|
|
@when("I register the stream template")
|
|
def step_register_stream_template(context):
|
|
"""Register the stream template."""
|
|
try:
|
|
with patch(
|
|
"cleveractors.templates.stream_templates.StreamTemplate", MockStreamTemplate
|
|
):
|
|
context.registry.register_template(
|
|
context.template_type,
|
|
context.template_name,
|
|
context.template_definitions[context.template_name],
|
|
)
|
|
except Exception as e:
|
|
context.error = e
|
|
|
|
|
|
@when("I try to register the invalid template")
|
|
def step_try_register_invalid_template(context):
|
|
"""Try to register invalid template."""
|
|
try:
|
|
context.registry.register_template(
|
|
context.template_type,
|
|
context.template_name,
|
|
context.template_definitions[context.template_name],
|
|
)
|
|
except Exception as e:
|
|
context.error = e
|
|
|
|
|
|
@when("I retrieve a template by type and name")
|
|
def step_retrieve_template_by_type_and_name(context):
|
|
"""Retrieve template by type and name."""
|
|
try:
|
|
context.result = context.registry.get_template(TemplateType.AGENT, "test_agent")
|
|
except Exception as e:
|
|
context.error = e
|
|
|
|
|
|
@when("I try to retrieve a non-existent template")
|
|
def step_try_retrieve_nonexistent_template(context):
|
|
"""Try to retrieve non-existent template."""
|
|
try:
|
|
context.result = context.registry.get_template(
|
|
TemplateType.AGENT, "nonexistent"
|
|
)
|
|
except Exception as e:
|
|
context.error = e
|
|
|
|
|
|
@when("I check if the template exists")
|
|
def step_check_template_exists(context):
|
|
"""Check if template exists."""
|
|
context.result = context.registry.has_template(
|
|
context.template_type, context.template_name
|
|
)
|
|
|
|
|
|
@when("I check if a non-existent template exists")
|
|
def step_check_nonexistent_template_exists(context):
|
|
"""Check if non-existent template exists."""
|
|
context.result = context.registry.has_template(TemplateType.AGENT, "nonexistent")
|
|
|
|
|
|
@when("I instantiate the template with context")
|
|
def step_instantiate_template_with_context(context):
|
|
"""Instantiate template with context."""
|
|
try:
|
|
context.result = context.registry.instantiate(
|
|
context.template_type,
|
|
context.template_name,
|
|
{"test_param": "test_value"},
|
|
context.instantiation_context,
|
|
)
|
|
except Exception as e:
|
|
context.error = e
|
|
|
|
|
|
@when("I instantiate the template without context")
|
|
def step_instantiate_template_without_context(context):
|
|
"""Instantiate template without context."""
|
|
try:
|
|
context.result = context.registry.instantiate(
|
|
context.template_type, context.template_name, {"test_param": "test_value"}
|
|
)
|
|
except Exception as e:
|
|
context.error = e
|
|
|
|
|
|
@when("I try to instantiate from None config")
|
|
def step_try_instantiate_from_none_config(context):
|
|
"""Try to instantiate from None config."""
|
|
try:
|
|
context.result = context.registry.instantiate_from_config(None)
|
|
except Exception as e:
|
|
context.error = e
|
|
|
|
|
|
@when("I instantiate from the template config")
|
|
def step_instantiate_from_template_config(context):
|
|
"""Instantiate from template config."""
|
|
try:
|
|
context.result = context.registry.instantiate_from_config(
|
|
context.registry_config
|
|
)
|
|
except Exception as e:
|
|
context.error = e
|
|
|
|
|
|
@when("I try to instantiate from the invalid template config")
|
|
def step_try_instantiate_from_invalid_template_config(context):
|
|
"""Try to instantiate from invalid template config."""
|
|
try:
|
|
context.result = context.registry.instantiate_from_config(
|
|
context.registry_config
|
|
)
|
|
except Exception as e:
|
|
context.error = e
|
|
|
|
|
|
@when("I instantiate from the agent template config")
|
|
def step_instantiate_from_agent_template_config(context):
|
|
"""Instantiate from agent template config."""
|
|
try:
|
|
context.result = context.registry.instantiate_from_config(
|
|
context.registry_config
|
|
)
|
|
except Exception as e:
|
|
context.error = e
|
|
|
|
|
|
@when("I instantiate from the graph template config")
|
|
def step_instantiate_from_graph_template_config(context):
|
|
"""Instantiate from graph template config."""
|
|
try:
|
|
context.result = context.registry.instantiate_from_config(
|
|
context.registry_config
|
|
)
|
|
except Exception as e:
|
|
context.error = e
|
|
|
|
|
|
@when("I instantiate from the stream template config")
|
|
def step_instantiate_from_stream_template_config(context):
|
|
"""Instantiate from stream template config."""
|
|
try:
|
|
context.result = context.registry.instantiate_from_config(
|
|
context.registry_config
|
|
)
|
|
except Exception as e:
|
|
context.error = e
|
|
|
|
|
|
@when("I instantiate from the direct agent config")
|
|
def step_instantiate_from_direct_agent_config(context):
|
|
"""Instantiate from direct agent config."""
|
|
try:
|
|
with patch("cleveractors.agents.factory.AgentFactory"):
|
|
context.result = context.registry.instantiate_from_config(
|
|
context.registry_config
|
|
)
|
|
except Exception as e:
|
|
context.error = e
|
|
|
|
|
|
@when("I instantiate from the direct graph config")
|
|
def step_instantiate_from_direct_graph_config(context):
|
|
"""Instantiate from direct graph config."""
|
|
try:
|
|
with patch("cleveractors.langgraph.graph.GraphConfig", MockGraphConfig):
|
|
context.result = context.registry.instantiate_from_config(
|
|
context.registry_config
|
|
)
|
|
except Exception as e:
|
|
context.error = e
|
|
|
|
|
|
@when("I instantiate from the direct stream config")
|
|
def step_instantiate_from_direct_stream_config(context):
|
|
"""Instantiate from direct stream config."""
|
|
try:
|
|
with patch(
|
|
"cleveractors.reactive.stream_router.StreamConfig", MockStreamConfig
|
|
):
|
|
context.result = context.registry.instantiate_from_config(
|
|
context.registry_config
|
|
)
|
|
except Exception as e:
|
|
context.error = e
|
|
|
|
|
|
@when("I try to instantiate from the unrecognizable config")
|
|
def step_try_instantiate_from_unrecognizable_config(context):
|
|
"""Try to instantiate from unrecognizable config."""
|
|
try:
|
|
context.result = context.registry.instantiate_from_config(
|
|
context.registry_config
|
|
)
|
|
except Exception as e:
|
|
context.error = e
|
|
|
|
|
|
@when("I instantiate from config without context")
|
|
def step_instantiate_from_config_without_context(context):
|
|
"""Instantiate from config without context."""
|
|
try:
|
|
context.result = context.registry.instantiate_from_config(
|
|
context.registry_config
|
|
)
|
|
except Exception as e:
|
|
context.error = e
|
|
|
|
|
|
@when("I register all templates from the configuration")
|
|
def step_register_all_templates_from_configuration(context):
|
|
"""Register all templates from configuration."""
|
|
try:
|
|
with (
|
|
patch(
|
|
"cleveractors.templates.agent_templates.AgentTemplate",
|
|
MockAgentTemplate,
|
|
),
|
|
patch(
|
|
"cleveractors.templates.agent_templates.CompositeAgentTemplate",
|
|
MockCompositeAgentTemplate,
|
|
),
|
|
patch(
|
|
"cleveractors.templates.graph_templates.GraphTemplate",
|
|
MockGraphTemplate,
|
|
),
|
|
patch(
|
|
"cleveractors.templates.stream_templates.StreamTemplate",
|
|
MockStreamTemplate,
|
|
),
|
|
):
|
|
context.registry.register_all_templates(context.templates_config)
|
|
except Exception as e:
|
|
context.error = e
|
|
|
|
|
|
@when("I register all templates from the empty configuration")
|
|
def step_register_all_templates_from_empty_configuration(context):
|
|
"""Register all templates from empty configuration."""
|
|
try:
|
|
context.registry.register_all_templates(context.templates_config)
|
|
except Exception as e:
|
|
context.error = e
|
|
|
|
|
|
@when("I list all templates")
|
|
def step_list_all_templates(context):
|
|
"""List all templates."""
|
|
try:
|
|
context.result = context.registry.list_templates()
|
|
except Exception as e:
|
|
context.error = e
|
|
|
|
|
|
@when("I list templates for a specific type")
|
|
def step_list_templates_specific_type(context):
|
|
"""List templates for specific type."""
|
|
try:
|
|
context.result = context.registry.list_templates(TemplateType.AGENT)
|
|
except Exception as e:
|
|
context.error = e
|
|
|
|
|
|
@when("I list all templates from empty registry")
|
|
def step_list_all_templates_empty_registry(context):
|
|
"""List all templates from empty registry."""
|
|
try:
|
|
context.result = context.registry.list_templates()
|
|
except Exception as e:
|
|
context.error = e
|
|
|
|
|
|
@then("the registry should be initialized correctly")
|
|
def step_verify_registry_initialized_correctly(context):
|
|
"""Verify registry initialized correctly."""
|
|
assert context.registry is not None
|
|
assert hasattr(context.registry, "templates")
|
|
assert len(context.registry.templates) == 8 # all 8 template types
|
|
|
|
|
|
@then("all template type collections should be empty")
|
|
def step_verify_template_collections_empty(context):
|
|
"""Verify all template type collections are empty."""
|
|
for template_type in TemplateType:
|
|
assert len(context.registry.templates[template_type]) == 0
|
|
|
|
|
|
@then("the agent template should be stored correctly")
|
|
def step_verify_agent_template_stored(context):
|
|
"""Verify agent template stored correctly."""
|
|
assert context.error is None
|
|
assert context.template_name in context.registry.templates[TemplateType.AGENT]
|
|
template = context.registry.templates[TemplateType.AGENT][context.template_name]
|
|
assert isinstance(template, MockAgentTemplate)
|
|
|
|
|
|
@then("the composite agent template should be stored correctly")
|
|
def step_verify_composite_agent_template_stored(context):
|
|
"""Verify composite agent template stored correctly."""
|
|
assert context.error is None
|
|
assert context.template_name in context.registry.templates[TemplateType.AGENT]
|
|
template = context.registry.templates[TemplateType.AGENT][context.template_name]
|
|
assert isinstance(template, MockCompositeAgentTemplate)
|
|
|
|
|
|
@then("the graph template should be stored correctly")
|
|
def step_verify_graph_template_stored(context):
|
|
"""Verify graph template stored correctly."""
|
|
assert context.error is None
|
|
assert context.template_name in context.registry.templates[TemplateType.GRAPH]
|
|
template = context.registry.templates[TemplateType.GRAPH][context.template_name]
|
|
assert isinstance(template, MockGraphTemplate)
|
|
|
|
|
|
@then("the stream template should be stored correctly")
|
|
def step_verify_stream_template_stored(context):
|
|
"""Verify stream template stored correctly."""
|
|
assert context.error is None
|
|
assert context.template_name in context.registry.templates[TemplateType.STREAM]
|
|
template = context.registry.templates[TemplateType.STREAM][context.template_name]
|
|
assert isinstance(template, MockStreamTemplate)
|
|
|
|
|
|
@then("logging should record the registration")
|
|
def step_verify_logging_records_registration(context):
|
|
"""Verify logging records the registration."""
|
|
# This verifies that the logging line was executed
|
|
assert context.error is None
|
|
|
|
|
|
@then("a ValueError should be raised for registry")
|
|
def step_verify_value_error_raised_registry(context):
|
|
"""Verify ValueError was raised for registry."""
|
|
assert context.error is not None
|
|
assert isinstance(context.error, ValueError)
|
|
|
|
|
|
@then("the error message should mention unknown template type")
|
|
def step_verify_error_message_unknown_template_type(context):
|
|
"""Verify error message mentions unknown template type."""
|
|
assert "Unknown template type" in str(context.error)
|
|
|
|
|
|
@then("the correct template should be returned")
|
|
def step_verify_correct_template_returned(context):
|
|
"""Verify correct template returned."""
|
|
assert context.error is None
|
|
assert context.result is not None
|
|
assert isinstance(context.result, MockAgentTemplate)
|
|
|
|
|
|
@then("the error message should mention template not found")
|
|
def step_verify_error_message_template_not_found(context):
|
|
"""Verify error message mentions template not found."""
|
|
assert "not found" in str(context.error)
|
|
|
|
|
|
@then("the result should be true for registry")
|
|
def step_verify_result_true_registry(context):
|
|
"""Verify result is true for registry."""
|
|
assert context.result is True
|
|
|
|
|
|
@then("the result should be false for registry")
|
|
def step_verify_result_false_registry(context):
|
|
"""Verify result is false for registry."""
|
|
assert context.result is False
|
|
|
|
|
|
@then("the template should be instantiated correctly")
|
|
def step_verify_template_instantiated_correctly(context):
|
|
"""Verify template instantiated correctly."""
|
|
assert context.error is None
|
|
assert context.result is not None
|
|
assert "instantiated" in context.result
|
|
assert "params" in context.result
|
|
|
|
|
|
@then("the provided context should be used")
|
|
def step_verify_provided_context_used(context):
|
|
"""Verify provided context was used."""
|
|
# Check that the template's instantiate method was called with our context
|
|
template = context.registry.templates[context.template_type][context.template_name]
|
|
assert len(template.instantiate_calls) > 0
|
|
_, _, used_context = template.instantiate_calls[-1]
|
|
assert used_context is context.instantiation_context
|
|
|
|
|
|
@then("a new context should be created automatically")
|
|
def step_verify_new_context_created_automatically(context):
|
|
"""Verify new context was created automatically."""
|
|
assert context.error is None
|
|
# The instantiation should succeed even without providing context
|
|
assert context.result is not None
|
|
|
|
|
|
@then("the error message should mention None configuration")
|
|
def step_verify_error_message_none_configuration(context):
|
|
"""Verify error message mentions None configuration."""
|
|
assert "None configuration" in str(context.error)
|
|
|
|
|
|
@then("the correct template should be instantiated")
|
|
def step_verify_correct_template_instantiated(context):
|
|
"""Verify correct template was instantiated."""
|
|
assert context.error is None
|
|
assert context.result is not None
|
|
assert "instantiated" in context.result
|
|
|
|
|
|
@then("the template parameters should be applied")
|
|
def step_verify_template_parameters_applied(context):
|
|
"""Verify template parameters were applied."""
|
|
assert "params" in context.result
|
|
assert context.result["params"]["model"] == "gpt-4"
|
|
assert context.result["params"]["temperature"] == 0.5
|
|
|
|
|
|
@then("the error message should mention template not found in config")
|
|
def step_verify_error_message_template_not_found_config(context):
|
|
"""Verify error message mentions template not found in config."""
|
|
assert "not found" in str(context.error)
|
|
|
|
|
|
@then("the agent template should be instantiated correctly")
|
|
def step_verify_agent_template_instantiated_correctly(context):
|
|
"""Verify agent template instantiated correctly."""
|
|
assert context.error is None
|
|
assert context.result is not None
|
|
assert "agent:specific_agent" in context.result["instantiated"]
|
|
|
|
|
|
@then("the graph template should be instantiated correctly")
|
|
def step_verify_graph_template_instantiated_correctly(context):
|
|
"""Verify graph template instantiated correctly."""
|
|
assert context.error is None
|
|
assert context.result is not None
|
|
assert "graph:specific_graph" in context.result["instantiated"]
|
|
|
|
|
|
@then("the stream template should be instantiated correctly")
|
|
def step_verify_stream_template_instantiated_correctly(context):
|
|
"""Verify stream template instantiated correctly."""
|
|
assert context.error is None
|
|
assert context.result is not None
|
|
assert "stream:specific_stream" in context.result["instantiated"]
|
|
|
|
|
|
@then("None should be returned for agent factory handling")
|
|
def step_verify_none_returned_agent_factory(context):
|
|
"""Verify None returned for agent factory handling."""
|
|
assert context.error is None
|
|
assert context.result is None
|
|
|
|
|
|
@then("a GraphConfig should be returned")
|
|
def step_verify_graph_config_returned(context):
|
|
"""Verify GraphConfig returned."""
|
|
assert context.error is None
|
|
assert context.result is not None
|
|
assert isinstance(context.result, MockGraphConfig)
|
|
|
|
|
|
@then("a StreamConfig should be returned")
|
|
def step_verify_stream_config_returned(context):
|
|
"""Verify StreamConfig returned."""
|
|
assert context.error is None
|
|
assert context.result is not None
|
|
assert isinstance(context.result, MockStreamConfig)
|
|
|
|
|
|
@then("the error message should mention cannot determine instance type")
|
|
def step_verify_error_message_cannot_determine_instance_type(context):
|
|
"""Verify error message mentions cannot determine instance type."""
|
|
assert "Cannot determine instance type" in str(context.error)
|
|
|
|
|
|
@then("the instantiation should succeed")
|
|
def step_verify_instantiation_succeeds(context):
|
|
"""Verify instantiation succeeds."""
|
|
assert context.error is None
|
|
assert context.result is not None
|
|
|
|
|
|
@then("all agent templates should be registered correctly")
|
|
def step_verify_all_agent_templates_registered(context):
|
|
"""Verify all agent templates registered correctly."""
|
|
assert context.error is None
|
|
agent_templates = context.registry.templates[TemplateType.AGENT]
|
|
assert "agent1" in agent_templates
|
|
assert "agent2" in agent_templates
|
|
assert len(agent_templates) == 2
|
|
|
|
|
|
@then("all graph templates should be registered correctly")
|
|
def step_verify_all_graph_templates_registered(context):
|
|
"""Verify all graph templates registered correctly."""
|
|
graph_templates = context.registry.templates[TemplateType.GRAPH]
|
|
assert "graph1" in graph_templates
|
|
assert "graph2" in graph_templates
|
|
assert len(graph_templates) == 2
|
|
|
|
|
|
@then("all stream templates should be registered correctly")
|
|
def step_verify_all_stream_templates_registered(context):
|
|
"""Verify all stream templates registered correctly."""
|
|
stream_templates = context.registry.templates[TemplateType.STREAM]
|
|
assert "stream1" in stream_templates
|
|
assert "stream2" in stream_templates
|
|
assert len(stream_templates) == 2
|
|
|
|
|
|
@then("no templates should be registered")
|
|
def step_verify_no_templates_registered(context):
|
|
"""Verify no templates were registered."""
|
|
assert context.error is None
|
|
for template_type in TemplateType:
|
|
assert len(context.registry.templates[template_type]) == 0
|
|
|
|
|
|
@then("the registry should remain empty")
|
|
def step_verify_registry_remains_empty(context):
|
|
"""Verify registry remains empty."""
|
|
for template_type in TemplateType:
|
|
assert len(context.registry.templates[template_type]) == 0
|
|
|
|
|
|
@then("all template types should be included in the result")
|
|
def step_verify_all_template_types_included(context):
|
|
"""Verify all template types included in result."""
|
|
assert context.error is None
|
|
assert context.result is not None
|
|
assert "agent" in context.result
|
|
assert "graph" in context.result
|
|
assert "stream" in context.result
|
|
|
|
|
|
@then("each type should show its registered templates")
|
|
def step_verify_each_type_shows_registered_templates(context):
|
|
"""Verify each type shows its registered templates."""
|
|
assert "test_agent" in context.result["agent"]
|
|
assert "test_graph" in context.result["graph"]
|
|
assert "test_stream" in context.result["stream"]
|
|
|
|
|
|
@then("only that template type should be included in the result")
|
|
def step_verify_only_specific_template_type_included(context):
|
|
"""Verify only specific template type included."""
|
|
assert context.error is None
|
|
assert context.result is not None
|
|
assert len(context.result) == 1
|
|
assert "agent" in context.result
|
|
|
|
|
|
@then("it should show the correct registered templates")
|
|
def step_verify_shows_correct_registered_templates(context):
|
|
"""Verify shows correct registered templates."""
|
|
assert "test_agent" in context.result["agent"]
|
|
|
|
|
|
@then("all template types should be present but empty")
|
|
def step_verify_all_template_types_present_but_empty(context):
|
|
"""Verify all template types present but empty."""
|
|
assert context.error is None
|
|
assert context.result is not None
|
|
assert len(context.result) == 8
|
|
for template_type in [
|
|
"agent",
|
|
"graph",
|
|
"stream",
|
|
"template",
|
|
"skill",
|
|
"actor",
|
|
"mcp",
|
|
"lsp",
|
|
]:
|
|
assert template_type in context.result
|
|
assert len(context.result[template_type]) == 0
|
|
|
|
|
|
@then("no templates should be listed")
|
|
def step_verify_no_templates_listed(context):
|
|
"""Verify no templates are listed."""
|
|
for template_list in context.result.values():
|
|
assert len(template_list) == 0
|
|
|
|
|
|
# Additional steps for application integration testing
|
|
|
|
|
|
@given("a config that forces None registry")
|
|
def step_config_force_none_registry_app(context):
|
|
"""Create config that will force None registry."""
|
|
import tempfile
|
|
from pathlib import Path
|
|
|
|
if not hasattr(context, "temp_dir"):
|
|
context.temp_dir = Path(tempfile.mkdtemp())
|
|
|
|
config = """
|
|
agents:
|
|
test_agent:
|
|
type: llm
|
|
config:
|
|
provider: openai
|
|
model: gpt-3.5-turbo
|
|
|
|
templates:
|
|
agents: "string_value"
|
|
graphs: "another_string"
|
|
|
|
routes:
|
|
main:
|
|
type: stream
|
|
stream_type: cold
|
|
operators:
|
|
- type: map
|
|
params:
|
|
agent: test_agent
|
|
publications:
|
|
- __output__
|
|
|
|
merges:
|
|
- sources: [__input__]
|
|
target: main
|
|
"""
|
|
config_file = context.temp_dir / "config.yaml"
|
|
config_file.write_text(config)
|
|
context.config_file = config_file
|
|
context.force_none_registry = True
|
|
|
|
|
|
@when("attempting template registration with None registry")
|
|
def step_attempt_template_registration_app(context):
|
|
"""Attempt template registration."""
|
|
from cleveractors.core.application import ReactiveCleverAgentsApp
|
|
from cleveractors.core.exceptions import CleverAgentsException
|
|
|
|
try:
|
|
# Patch TemplateRegistry to return None to simulate initialization failure
|
|
with patch("cleveractors.core.application.TemplateRegistry", return_value=None):
|
|
context.app = ReactiveCleverAgentsApp([context.config_file])
|
|
except CleverAgentsException as e:
|
|
context.error = e
|
|
|
|
|
|
@then("CleverAgentsException is raised about template registry")
|
|
def step_exception_about_registry_app(context):
|
|
"""Verify exception about registry."""
|
|
from cleveractors.core.exceptions import CleverAgentsException
|
|
|
|
# The error must be raised when registry is None
|
|
assert hasattr(context, "error") and context.error is not None, (
|
|
"Expected CleverAgentsException to be raised but no error was caught"
|
|
)
|
|
assert isinstance(context.error, CleverAgentsException), (
|
|
f"Expected CleverAgentsException but got {type(context.error)}"
|
|
)
|
|
error_message = str(context.error).lower()
|
|
assert "registry" in error_message or "template" in error_message, (
|
|
f"Expected error message to mention 'registry' or 'template' but got: {context.error}"
|
|
)
|