Files
cleveractors-core/features/template_renderer_coverage.feature
CoreRasurae 9753b31c7e
CI / quality (push) Successful in 36s
CI / lint (push) Successful in 38s
CI / typecheck (push) Successful in 49s
CI / security (push) Successful in 51s
CI / integration_tests (push) Successful in 55s
CI / unit_tests (push) Successful in 3m35s
CI / build (push) Successful in 33s
CI / coverage (push) Successful in 3m36s
CI / status-check (push) Successful in 3s
test: add coverage gap tests improving coverage from 81.4% to 96.90%
Add 13 BDD scenarios covering previously uncovered code paths:
- SAFE_BUILTINS validation (sandbox.py: 0% → 100%)
- ConfigurationError re-raise path (config.py: 99.3% → 100%)
- CLI hello/main functions (cli.py: 72.7% → 90.9%)
- GraphState message truncation (state.py: 98.7% → 100%)
- ProgressBarManager update/context rendering (progress.py: 0% → 87.7%)
- MessageRouter regex/exact/contains routing (message_router.py: 0% → 59.4%)
- RoutingAdapter parse_routing_command (routing_adapter.py)
- DynamicRouterNode pattern-based routing (dynamic_router.py)
- EnhancedTemplateRegistry unknown template type (enhanced_registry.py: 99.2%)
- CompositeAgent null-graph error path (composite.py: 97.8% → 98.6%)

Cover routing_adapter.py (17% → 100%): all GOTO/ROUTE patterns,
create_routing_node, create_conditional_router, dynamic config conversion.

Cover dynamic_router.py (21% → 87%): execute with empty/dict/string
messages, extract_message with colon parsing, config creation, graph
extension with edge generation.

Cover message_router.py (59% → 78%): regex, exact, contains, prefix,
suffix match types, invalid regex handling, non-string message, set_state.

Exercise Node._prepare_conversation_history with invalid configs,
_runtime error paths, _execute_message_router with rules,
_execute_agent with current_message and metadata propagation,
_execute_function with dynamic_router, and _execute_conditional
with content_contains/content_not_contains/content_starts_with
and custom condition types. Improves nodes.py from 71.3% to 72.5%.

Exercise PureGraphConfig, PureLangGraph init with dict/config,
RxPyLangGraphBridge registration/connection/lookup,
ReactiveStreamRouter operator creation and condition functions,
ReactiveConfigParser config/route/graph parsing,
ToolAgent tool execution with JSON, space-separated, single,
file_read, progress_bar invocations, and
ReactiveCleverAgentsApp init/dispose/visualization.
2026-06-02 20:02:01 +01:00

229 lines
9.6 KiB
Gherkin

Feature: Template Rendering Across SIMPLE, JINJA2, and MUSTACHE Engines
As a developer
I want template rendering to work correctly with all three engines, handling path resolution, registration, and error conditions
So that renderer engine selection and template variable substitution produce correct output
Background:
Given I have a clean test environment for template renderer
# Test TemplateEngine enum and basic initialization
Scenario: Test TemplateEngine enum values
Given I import the TemplateEngine enum
When I access the enum values
Then I should have SIMPLE, JINJA2, and MUSTACHE engines
# Test _resolve_path function
Scenario: Test _resolve_path with nested dictionary paths
Given I have a context dictionary with nested values
When I resolve a dotted path in the context
Then I should get the correct nested value
Scenario: Test _resolve_path with object attributes
Given I have an object with attributes
When I resolve a dotted path on the object
Then I should get the correct attribute value
Scenario: Test _resolve_path with missing keys
Given I have a context dictionary
When I resolve a path that doesn't exist
Then I should get an empty string
# Test TemplateRenderer initialization
Scenario: Test TemplateRenderer initialization with SIMPLE engine
Given I initialize a TemplateRenderer with SIMPLE engine
Then the engine should be str.format
Scenario: Test TemplateRenderer initialization with JINJA2 engine
Given I initialize a TemplateRenderer with JINJA2 engine
Then the engine should be a Jinja2 Environment
Scenario: Test TemplateRenderer initialization with MUSTACHE engine
Given I initialize a TemplateRenderer with MUSTACHE engine
Then the engine should be a Pystache Renderer
Scenario: Test TemplateRenderer initialization with unsupported engine
When I try to initialize TemplateRenderer with an invalid engine
Then I should get a TemplateError about unsupported engine
# Skip Jinja2/Pystache availability tests for now - they're complex to mock
# Focus on actual functionality testing
# Test _render_simple_with_jinja_like function
Scenario: Test simple Jinja-like rendering with basic placeholders
Given I have a template with simple placeholders
When I render the template with Jinja-like syntax
Then the placeholders should be replaced correctly
Scenario: Test simple Jinja-like rendering with expressions
Given I have a template with expression placeholders
And I have a context dictionary
When I render the template with Jinja-like syntax
Then the expressions should be evaluated correctly
Scenario: Test simple Jinja-like rendering with None values
Given I have a template with placeholders
And I have a context with None values
When I render the template with Jinja-like syntax
Then None values should become empty strings
# Test register_template functionality
Scenario: Test register_template with empty name
Given I have a TemplateRenderer
When I try to register a template with empty name
Then I should get a TemplateError about empty name
Scenario: Test register_template with SIMPLE engine
Given I have a TemplateRenderer with SIMPLE engine
When I register a template with a name and content
Then the template should be stored as a string
Scenario: Test register_template with JINJA2 engine
Given I have a TemplateRenderer with JINJA2 engine
When I register a template with a name and content
Then the template should be compiled and stored
Scenario: Test register_template with invalid Jinja2 template
Given I have a TemplateRenderer with JINJA2 engine
When I try to register an invalid Jinja2 template
Then I should get a TemplateError about registration failure
Scenario: Test register_template with MUSTACHE engine
Given I have a TemplateRenderer with MUSTACHE engine
When I register a template with a name and content
Then the template should be stored as a string
# Test render functionality
Scenario: Test render with nonexistent template
Given I have a TemplateRenderer
When I try to render a template that doesn't exist
Then I should get a TemplateError about template not found
Scenario: Test render with SIMPLE engine and valid template
Given I have a TemplateRenderer with SIMPLE engine
And I have registered a simple template
When I render the template with context data
Then I should get the rendered result
Scenario: Test render with SIMPLE engine and missing variables
Given I have a TemplateRenderer with SIMPLE engine
And I have registered a template with placeholders
When I render the template with incomplete context
Then I should get a TemplateError about missing variables
Scenario: Test render with JINJA2 engine and valid template
Given I have a TemplateRenderer with JINJA2 engine
And I have registered a Jinja2 template
When I render the template with context data
Then I should get the rendered result
Scenario: Test render with JINJA2 engine and invalid template object
Given I have a TemplateRenderer with JINJA2 engine
And I have a template object without render method
When I try to render the template
Then I should get a TemplateError about missing render method
Scenario: Test render with MUSTACHE engine and valid template
Given I have a TemplateRenderer with MUSTACHE engine
And I have registered a Mustache template
When I render the template with context data
Then I should get the rendered result
Scenario: Test render with MUSTACHE engine and invalid renderer
Given I have a TemplateRenderer with MUSTACHE engine
And I have a renderer without render method
When I try to render a template
Then I should get a TemplateError about missing render method
Scenario: Test render with unknown engine type
Given I have a TemplateRenderer with modified engine type
When I try to render a template
Then I should get a TemplateError about unsupported engine
Scenario: Test render with exception during rendering
Given I have a TemplateRenderer
And I have a template that causes rendering exceptions
When I try to render the template
Then I should get a TemplateError about rendering failure
# Test render_string functionality
Scenario: Test render_string with SIMPLE engine
Given I have a TemplateRenderer with SIMPLE engine
When I render a template string with context data
Then I should get the rendered result
Scenario: Test render_string with SIMPLE engine and missing variables
Given I have a TemplateRenderer with SIMPLE engine
When I render a template string with incomplete context
Then I should get a TemplateError about missing variables
# Skip JINJA2 and MUSTACHE render_string tests for now since they may not be available
Scenario: Test render_string with unknown engine type
Given I have a TemplateRenderer with modified engine type
When I try to render a template string
Then I should get a TemplateError about unsupported engine
Scenario: Test render_string with source description
Given I have a TemplateRenderer
When I render a template string with source description and it fails
Then the error should include the source description
Scenario: Test render_string with exception during rendering
Given I have a TemplateRenderer
When I render a template string that causes exceptions
Then I should get a TemplateError about rendering failure
# Test get_template functionality
Scenario: Test get_template with existing template
Given I have a TemplateRenderer
And I have registered a template
When I get the template by name
Then I should receive the template content
Scenario: Test get_template with nonexistent template
Given I have a TemplateRenderer
When I try to get a template that doesn't exist
Then I should get a TemplateError about template not found
# Test list_templates functionality
Scenario: Test list_templates with empty registry
Given I have a TemplateRenderer
When I list all templates from renderer
Then I should get an empty list
Scenario: Test list_templates with multiple templates
Given I have a TemplateRenderer
And I have registered multiple templates
When I list all templates from renderer
Then I should get all template names
# Additional scenarios to reach 90% coverage
Scenario: Test _resolve_path with object attribute access
Given I have an object with nested attributes
When I resolve a path with object attribute access
Then I should get the correct object attribute value
Scenario: Test render with JINJA2 template compilation
Given I have a TemplateRenderer with JINJA2 engine
And I have a valid Jinja2 template content
When I register and render the Jinja2 template
Then the Jinja2 template should render correctly
Scenario: Test render with MUSTACHE template processing
Given I have a TemplateRenderer with MUSTACHE engine
And I have a valid Mustache template content
When I register and render the Mustache template
Then the Mustache template should render correctly
Scenario: Test render_string with JINJA2 engine functionality
Given I have a TemplateRenderer with JINJA2 engine
When I render a Jinja2 template string
Then I should get correct Jinja2 rendered output
Scenario: Test render_string with MUSTACHE engine functionality
Given I have a TemplateRenderer with MUSTACHE engine
When I render a Mustache template string
Then I should get correct Mustache rendered output
# Skip import error tests for now - they're complex to mock correctly