forked from HAL9000/cleveragents-core
269 lines
8.8 KiB
Gherkin
269 lines
8.8 KiB
Gherkin
Feature: YAML Template Engine Missing Coverage
|
|
As a developer using CleverAgents
|
|
I want to test the missing code paths in the YAML template engine
|
|
So that I can achieve 90%+ coverage
|
|
|
|
Background:
|
|
Given the YAML template engine is initialized
|
|
|
|
@missing_coverage
|
|
Scenario: Load file without template markers
|
|
Given I have a test YAML file "plain.yaml" with content:
|
|
"""
|
|
config:
|
|
name: PlainConfig
|
|
version: 1.0
|
|
agents:
|
|
simple:
|
|
type: basic
|
|
"""
|
|
When I load the YAML file without context
|
|
Then the result should be parsed normally
|
|
And should contain config name "PlainConfig"
|
|
|
|
@missing_coverage
|
|
Scenario: Load string without template markers
|
|
Given I have a YAML string without templates:
|
|
"""
|
|
simple:
|
|
key: value
|
|
list:
|
|
- item1
|
|
- item2
|
|
"""
|
|
When I load the string directly
|
|
Then it should parse without template processing
|
|
And should contain key "value"
|
|
|
|
@missing_coverage
|
|
Scenario: YAML parsing error handling
|
|
Given I have a YAML string that causes parsing errors:
|
|
"""
|
|
broken:
|
|
{% for item in items %}
|
|
key: value: bad: structure
|
|
{% endfor %}
|
|
"""
|
|
And I have template context:
|
|
| key | value |
|
|
| items | [a, b, c] |
|
|
When I process YAML with error handling
|
|
Then YAML errors should be caught and handled
|
|
And fallback parsing should be attempted
|
|
|
|
@missing_coverage
|
|
Scenario: Complex structure analysis with nested blocks
|
|
Given I have deeply nested template structure:
|
|
"""
|
|
root:
|
|
{% for outer in outer_list %}
|
|
{{ outer.name }}:
|
|
{% for middle in outer.children %}
|
|
{{ middle.name }}:
|
|
{% for inner in middle.items %}
|
|
item_{{ loop.index }}: {{ inner.value }}
|
|
{% endfor %}
|
|
{% if middle.enabled %}
|
|
enabled: true
|
|
metadata:
|
|
{% for key, val in middle.metadata.items() %}
|
|
{{ key }}: {{ val }}
|
|
{% endfor %}
|
|
{% endif %}
|
|
{% endfor %}
|
|
{% endfor %}
|
|
"""
|
|
When I analyze this complex structure
|
|
Then multiple template blocks should be found
|
|
And nested hierarchy should be mapped
|
|
And block boundaries should be correctly identified
|
|
|
|
@missing_coverage
|
|
Scenario: Template extraction with complex blocks
|
|
Given I have template with complex nested structure requiring extraction:
|
|
"""
|
|
workflows:
|
|
{% for workflow in workflows %}
|
|
{{ workflow.name }}:
|
|
type: {{ workflow.type }}
|
|
{% if workflow.parallel %}
|
|
parallel_steps:
|
|
{% for step in workflow.steps %}
|
|
- name: {{ step.name }}
|
|
{% if step.conditional %}
|
|
condition: {{ step.condition }}
|
|
{% endif %}
|
|
actions:
|
|
{% for action in step.actions %}
|
|
- {{ action.type }}: {{ action.params | yaml }}
|
|
{% endfor %}
|
|
{% endfor %}
|
|
{% else %}
|
|
sequential_steps:
|
|
{% for step in workflow.steps %}
|
|
{{ step.order }}: {{ step.name }}
|
|
{% endfor %}
|
|
{% endif %}
|
|
{% endfor %}
|
|
"""
|
|
When I extract templates for deferred rendering
|
|
Then template sections should be properly extracted
|
|
And structure should be preserved for later rendering
|
|
And complex nested blocks should be handled correctly
|
|
|
|
@missing_coverage
|
|
Scenario: Block end finding with nested structures
|
|
Given I have nested blocks requiring end detection:
|
|
"""
|
|
container:
|
|
{% for level1 in data %}
|
|
{{ level1.name }}:
|
|
{% for level2 in level1.children %}
|
|
sub_{{ level2.id }}:
|
|
{% for level3 in level2.items %}
|
|
item: {{ level3.value }}
|
|
{% endfor %}
|
|
{% endfor %}
|
|
{% endfor %}
|
|
"""
|
|
When I find block end positions
|
|
Then all block boundaries should be correctly identified
|
|
And nested blocks should have proper end positions
|
|
And block hierarchy should be maintained
|
|
|
|
@missing_coverage
|
|
Scenario: Template reconstruction from complex structure
|
|
Given I have stored template with mixed block types:
|
|
"""
|
|
{
|
|
"workflows": {
|
|
"_template_content": "{% for wf in workflows %}\n{{ wf.name }}:\n type: {{ wf.type }}\n{% endfor %}",
|
|
"_template_type": "block"
|
|
},
|
|
"config": {
|
|
"name": {
|
|
"_template_value": "{{ config_name }}",
|
|
"_template_type": "inline"
|
|
},
|
|
"version": "1.0"
|
|
}
|
|
}
|
|
"""
|
|
When I reconstruct YAML from this structure
|
|
Then the original template format should be restored
|
|
And block templates should be properly placed
|
|
And inline templates should be correctly positioned
|
|
|
|
@missing_coverage
|
|
Scenario: Error handling in template rendering
|
|
Given I have template that will cause rendering errors:
|
|
"""
|
|
problematic:
|
|
{% for item in undefined_var %}
|
|
key: {{ item.missing_attr }}
|
|
{% endfor %}
|
|
fallback: present
|
|
"""
|
|
When I process with missing variables
|
|
Then rendering errors should be handled gracefully
|
|
And partial results should be available where possible
|
|
|
|
@missing_coverage
|
|
Scenario: Custom filters with edge cases
|
|
Given I have YAML using custom filters with edge cases:
|
|
"""
|
|
tests:
|
|
empty_sum: {{ [] | sum }}
|
|
none_sum: {{ [None, None] | sum }}
|
|
mixed_sum: {{ [1, None, 3] | sum }}
|
|
attr_sum_empty: {{ [] | sum(attribute='value') }}
|
|
selectattr_none: {{ data | selectattr('missing_attr', '>', 0) | list | length }}
|
|
yaml_filter_complex: {{ complex_obj | yaml }}
|
|
indent_empty: "{{ '' | indent(4) }}"
|
|
"""
|
|
And I have edge case filter context
|
|
When I process with custom filters
|
|
Then edge cases should be handled properly
|
|
And filters should not raise exceptions
|
|
|
|
@missing_coverage
|
|
Scenario: Preprocessing with complex indentation scenarios
|
|
Given I have template requiring complex preprocessing:
|
|
"""
|
|
services:
|
|
{% for service in services %}
|
|
{{ service.name }}:
|
|
{% if service.replicas > 1 %}
|
|
replicas: {{ service.replicas }}
|
|
{% endif %}
|
|
ports:
|
|
{% for port in service.ports %}
|
|
- {{ port.number }}:{{ port.target }}
|
|
{% endfor %}
|
|
{% endfor %}
|
|
"""
|
|
When I preprocess for complex indentation handling
|
|
Then indentation hints should be added correctly
|
|
And block structure should be preserved
|
|
And nested indentation should be handled properly
|
|
|
|
@missing_coverage
|
|
Scenario: Postprocessing with multiple structural fixes
|
|
Given I have YAML that generates multiple structural issues:
|
|
"""
|
|
items:
|
|
{% for item in items %}
|
|
{{ item.key }}:
|
|
val1: {{ item.val1 }}
|
|
val2: {{ item.val2 }}
|
|
val3: {{ item.val3 }}
|
|
{% endfor %}
|
|
"""
|
|
And I have context generating structural problems:
|
|
| key | val1 | val2 | val3 |
|
|
| item1 | a | b | c |
|
|
| item2 | x | y | z |
|
|
When I process with postprocessing fixes
|
|
Then multiple key-value pairs should be separated
|
|
And structural issues should be resolved
|
|
And result should be valid YAML
|
|
|
|
@missing_coverage
|
|
Scenario: File loading with error handling
|
|
Given I have a YAML file that will cause reading errors
|
|
When I try to load the problematic file
|
|
Then file reading errors should be handled
|
|
And appropriate error messages should be provided
|
|
|
|
@missing_coverage
|
|
Scenario: Complete render context with all utilities
|
|
Given I have template using all available utilities:
|
|
"""
|
|
utilities:
|
|
range_test: {{ range(5) | list }}
|
|
abs_test: {{ abs(-42) }}
|
|
round_test: {{ round(3.14159, 2) }}
|
|
builtin_functions:
|
|
len: {{ [1, 2, 3] | length }}
|
|
min: {{ [3, 1, 4] | min }}
|
|
max: {{ [3, 1, 4] | max }}
|
|
sum: {{ [1, 2, 3] | sum }}
|
|
"""
|
|
When I process with complete render context
|
|
Then all Python built-ins should work
|
|
And utility functions should be available
|
|
And complex expressions should be evaluated correctly
|
|
|
|
@missing_coverage
|
|
Scenario: Template engine initialization and filter setup
|
|
When I initialize a new YAML template engine
|
|
Then Jinja2 environment should be properly configured
|
|
And custom filters should be registered
|
|
And environment settings should be YAML-friendly
|
|
|
|
@missing_coverage
|
|
Scenario: Direct method calls for missing coverage
|
|
Given I have various YAML content for direct testing
|
|
When I call template engine methods directly
|
|
Then all code paths should be exercised
|
|
And missing coverage areas should be hit |