Files
cleveragents-core/features/context_analysis_agent_coverage.feature
T

416 lines
16 KiB
Gherkin

Feature: Context Analysis Agent Coverage
As a developer
I want comprehensive test coverage for the ContextAnalysisAgent
So that I can ensure the context analysis workflow works correctly
Background:
Given the context analysis agent module is importable
And I have a mock LLM provider configured for context analysis
Scenario: ContextAnalysisAgent can be instantiated with default parameters
When I create a ContextAnalysisAgent with default parameters
Then the context analysis agent should be initialized successfully
And the agent should have a max_files_per_batch attribute set to 10
And the context analysis agent should have an llm provider configured
Scenario: ContextAnalysisAgent can be instantiated with custom parameters
When I create a ContextAnalysisAgent with parameters:
| parameter | value |
| provider | openai |
| model | gpt-4 |
| temperature | 0.3 |
| max_files_per_batch | 5 |
Then the context analysis agent should be initialized successfully
And the agent max_files_per_batch should be 5
And the agent temperature should be 0.3
And the context analysis agent provider should be "openai"
Scenario: ContextAnalysisAgent builds a valid workflow graph
Given I have a ContextAnalysisAgent instance
When I build the workflow graph
Then the graph should contain node "identify_files"
And the graph should contain node "analyze_files"
And the graph should contain node "extract_dependencies"
And the graph should contain node "build_structure"
And the graph should contain node "select_contexts"
And the graph should contain node "finalize"
And the entry point should be "identify_files"
Scenario: Identify files step initializes files_to_analyze
Given I have a ContextAnalysisAgent instance
And I have a basic state
When I execute the identify_files step
Then the state should contain files_to_analyze
And the files_to_analyze should be an empty list
And the context analysis log should contain "Identifying files for analysis"
Scenario: Identify files step preserves existing state
Given I have a ContextAnalysisAgent instance
And I have a state with existing context:
"""
{
"context": {"project": "test"},
"messages": [{"role": "user", "content": "analyze"}]
}
"""
When I execute the identify_files step
Then the state should contain files_to_analyze
And the state context should still contain project data
Scenario: Analyze files step processes file list
Given I have a ContextAnalysisAgent instance
And I have a state with files to analyze:
"""
["src/main.py", "src/utils.py", "tests/test_main.py"]
"""
When I execute the analyze_files step
Then the state should contain analyzed_files
And the analyzed_files should be a dictionary
And the context analysis log should contain "Analyzing 3 files"
Scenario: Analyze files step handles empty file list
Given I have a ContextAnalysisAgent instance
And I have a state with empty files to analyze
When I execute the analyze_files step
Then the state should contain analyzed_files
And the analyzed_files should be empty
And the context analysis log should contain "Analyzing 0 files"
Scenario: Analyze files step handles missing files_to_analyze key
Given I have a ContextAnalysisAgent instance
And I have a basic state without files_to_analyze
When I execute the analyze_files step
Then the state should contain analyzed_files
And the context analysis log should contain "Analyzing 0 files"
Scenario: Extract dependencies step creates dependency graph
Given I have a ContextAnalysisAgent instance
And I have a state with analyzed files:
"""
{
"src/main.py": {"imports": ["src.utils", "os"]},
"src/utils.py": {"imports": ["sys"]}
}
"""
When I execute the extract_dependencies step
Then the state should contain dependencies
And the dependencies should be a dictionary
And the context analysis log should contain "Extracting dependencies"
Scenario: Extract dependencies step initializes empty dependencies
Given I have a ContextAnalysisAgent instance
And I have a basic state
When I execute the extract_dependencies step
Then the state should contain dependencies
And the dependencies should be empty
Scenario: Build structure step creates project structure
Given I have a ContextAnalysisAgent instance
And I have a state with dependencies
When I execute the build_structure step
Then the state should contain project_structure
And the project_structure should have directories field
And the project_structure should have modules field
And the project_structure should have entry_points field
And the context analysis log should contain "Building project structure"
Scenario: Build structure step initializes with correct default structure
Given I have a ContextAnalysisAgent instance
And I have a basic state
When I execute the build_structure step
Then the project_structure directories should be an empty list
And the project_structure modules should be an empty list
And the project_structure entry_points should be an empty list
Scenario: Select contexts step identifies relevant contexts
Given I have a ContextAnalysisAgent instance
And I have a state with project structure:
"""
{
"directories": ["src", "tests"],
"modules": ["main", "utils"],
"entry_points": ["main.py"]
}
"""
When I execute the select_contexts step
Then the state should contain relevant_contexts
And the relevant_contexts should be a list
And the context analysis log should contain "Selecting relevant contexts"
Scenario: Select contexts step initializes empty contexts
Given I have a ContextAnalysisAgent instance
And I have a basic state
When I execute the select_contexts step
Then the state should contain relevant_contexts
And the relevant_contexts should be empty
Scenario: Finalize step creates comprehensive result structure
Given I have a ContextAnalysisAgent instance
And I have a complete analysis state:
"""
{
"analyzed_files": {
"main.py": {"lines": 100},
"utils.py": {"lines": 50}
},
"dependencies": {
"main.py": ["utils"]
},
"project_structure": {
"directories": ["src"],
"modules": ["main", "utils"],
"entry_points": ["main.py"]
},
"relevant_contexts": [
{"file": "main.py", "relevance": "high"}
]
}
"""
When I execute the finalize step
Then the state should contain a result field
And the result should have analyzed_files field
And the result should have dependencies field
And the result should have project_structure field
And the result should have relevant_contexts field
And the result should have file_count field
And the result file_count should be 2
And the context analysis log should contain "Finalizing context analysis"
Scenario: Finalize step handles missing optional fields
Given I have a ContextAnalysisAgent instance
And I have a basic state
When I execute the finalize step
Then the state should contain a result field
And the result analyzed_files should be empty
And the result dependencies should be empty
And the result file_count should be 0
Scenario: Full workflow with empty initial state
Given I have a ContextAnalysisAgent instance
And I have initial state:
"""
{
"messages": [],
"context": {},
"metadata": {}
}
"""
When I run the complete workflow
Then the workflow should complete successfully
And the final result should contain all required fields
Scenario: Full workflow with populated file list
Given I have a ContextAnalysisAgent instance
And I have initial state with files:
"""
{
"messages": [],
"context": {"files": ["main.py", "utils.py"]},
"metadata": {}
}
"""
When I run the complete workflow
Then the workflow should complete successfully
And the final result should have analyzed_files
Scenario: Workflow graph edges connect nodes correctly
Given I have a ContextAnalysisAgent instance
When I build the workflow graph
Then "identify_files" should connect to "analyze_files"
And "analyze_files" should connect to "extract_dependencies"
And "extract_dependencies" should connect to "build_structure"
And "build_structure" should connect to "select_contexts"
And "select_contexts" should connect to "finalize"
And "finalize" should connect to END
Scenario: ContextAnalysisState holds required workflow data
Given I can create a ContextAnalysisState
When I initialize it with all required fields:
| field | type |
| files_to_analyze | list |
| analyzed_files | dict |
| dependencies | dict |
| project_structure | dict |
| relevant_contexts | list |
Then the state should store all fields correctly for context analysis
Scenario: Max files per batch parameter is stored correctly
Given I have a ContextAnalysisAgent instance with max_files_per_batch of 20
Then the agent max_files_per_batch should be 20
Scenario: Identify files logs with INFO level
Given I have a ContextAnalysisAgent instance
And logging is enabled at INFO level for context analysis
And I have a basic state
When I execute the identify_files step
Then the context analysis log should contain "Identifying files for analysis"
Scenario: Analyze files logs file count
Given I have a ContextAnalysisAgent instance
And logging is enabled at INFO level for context analysis
And I have a state with 5 files to analyze
When I execute the analyze_files step
Then the context analysis log should contain "Analyzing 5 files"
Scenario: Extract dependencies logs extraction message
Given I have a ContextAnalysisAgent instance
And logging is enabled at INFO level for context analysis
And I have a basic state
When I execute the extract_dependencies step
Then the context analysis log should contain "Extracting dependencies"
Scenario: Build structure logs building message
Given I have a ContextAnalysisAgent instance
And logging is enabled at INFO level for context analysis
And I have a basic state
When I execute the build_structure step
Then the context analysis log should contain "Building project structure"
Scenario: Select contexts logs selection message
Given I have a ContextAnalysisAgent instance
And logging is enabled at INFO level for context analysis
And I have a basic state
When I execute the select_contexts step
Then the context analysis log should contain "Selecting relevant contexts"
Scenario: Finalize logs completion message
Given I have a ContextAnalysisAgent instance
And logging is enabled at INFO level for context analysis
And I have a basic state
When I execute the finalize step
Then the context analysis log should contain "Finalizing context analysis"
Scenario: Agent inherits from BaseAgent
Given I have a ContextAnalysisAgent instance
Then the agent should be an instance of BaseAgent
Scenario: Agent can switch providers
Given I have a ContextAnalysisAgent instance with provider "openai"
When I switch context analysis to provider "anthropic" with model "claude-3"
Then the context analysis agent provider should be "anthropic"
And the context analysis agent model should be "claude-3"
Scenario: State preserves messages across steps
Given I have a ContextAnalysisAgent instance
And I have a state with messages:
"""
[
{"role": "user", "content": "analyze project"},
{"role": "assistant", "content": "analyzing"}
]
"""
When I execute the identify_files step
And I execute the analyze_files step
Then the state should still contain 2 messages
Scenario: State preserves context across steps
Given I have a ContextAnalysisAgent instance
And I have a state with context:
"""
{
"project_name": "test_project",
"language": "python"
}
"""
When I execute all workflow steps
Then the state context should contain project_name
And the state context should contain language
Scenario: State preserves metadata across steps
Given I have a ContextAnalysisAgent instance
And I have a state with metadata:
"""
{
"timestamp": "2024-01-01T00:00:00",
"user": "test_user"
}
"""
When I execute all workflow steps
Then the state metadata should contain timestamp
And the state metadata should contain user
Scenario: Analyzed files dictionary is properly initialized
Given I have a ContextAnalysisAgent instance
And I have a state with 3 files to analyze
When I execute the analyze_files step
Then the analyzed_files should be a dictionary
And the analyzed_files should not be None
Scenario: Dependencies dictionary is properly initialized
Given I have a ContextAnalysisAgent instance
And I have a basic state
When I execute the extract_dependencies step
Then the dependencies should be a dictionary
And the dependencies should not be None
Scenario: Project structure has all required keys
Given I have a ContextAnalysisAgent instance
And I have a basic state
When I execute the build_structure step
Then the project_structure should contain key "directories"
And the project_structure should contain key "modules"
And the project_structure should contain key "entry_points"
Scenario: Relevant contexts list is properly initialized
Given I have a ContextAnalysisAgent instance
And I have a basic state
When I execute the select_contexts step
Then the relevant_contexts should be a list
And the relevant_contexts should not be None
Scenario: Result contains all analysis outputs
Given I have a ContextAnalysisAgent instance
And I have a state with full analysis data
When I execute the finalize step
Then the result should include analyzed_files
And the result should include dependencies
And the result should include project_structure
And the result should include relevant_contexts
And the result should include file_count
Scenario: File count is calculated correctly with multiple files
Given I have a ContextAnalysisAgent instance
And I have a state with 10 analyzed files
When I execute the finalize step
Then the result file_count should be 10
Scenario: File count is zero when no files analyzed
Given I have a ContextAnalysisAgent instance
And I have a state with no analyzed files
When I execute the finalize step
Then the result file_count should be 0
Scenario: Temperature parameter affects agent configuration
Given I have a ContextAnalysisAgent instance with temperature 0.1
Then the agent temperature should be 0.1 for context analysis
Scenario: Temperature parameter can be set to 0.0
Given I have a ContextAnalysisAgent instance with temperature 0.0
Then the agent temperature should be 0.0 for context analysis
Scenario: Model parameter is stored correctly
Given I have a ContextAnalysisAgent instance with model "gpt-4-turbo"
Then the context analysis agent model should be "gpt-4-turbo"
Scenario: Multiple workflow executions maintain independence
Given I have a ContextAnalysisAgent instance
And I have initial state with files:
"""
{
"messages": [],
"context": {"files": ["file1.py"]},
"metadata": {}
}
"""
When I run the complete workflow
And I reset the state with different files
And I run the complete workflow again
Then both workflow results should be independent
Scenario: Empty state does not cause errors
Given I have a ContextAnalysisAgent instance
And I have an empty state
When I execute all workflow steps
Then no errors should occur
And the final result should be valid