feat: consolidate and optimize Claude Code agent ecosystem

- Create comprehensive datamodel optimization specialist agent
- Migrate testing efficiency and requirements engineering agents from docs to .claude/agents
- Rename kaizen-optimizer to agent-optimizer for clarity
- Remove duplicate documentation following DRY principle
- Create docs/agents symlink for easy agent visibility
- Add issue datamodel optimization gameplan with 4-week implementation strategy

Agent improvements:
- Enhanced requirements engineering agent with Issue #59 lessons learned
- Added practical toolkit commands and enhanced TDD8 workflow integration
- Consolidated agent configurations as single source of truth

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-10-05 20:50:52 +02:00
parent a98e2fa329
commit d68eac3275
9 changed files with 770 additions and 1201 deletions

1
docs/agents Symbolic link
View File

@@ -0,0 +1 @@
/home/worsch/markitect_project/.claude/agents

View File

@@ -1,216 +0,0 @@
# Requirements Engineering and Incremental Development Planning Sub-Agent
## Executive Summary
This specialized sub-agent was designed to prevent the interface compatibility issues and mock object mismatches encountered during Issue #59 debugging session. It provides a systematic approach to requirements engineering that ensures solid foundations before implementation.
## Problem Analysis: What Went Wrong in Issue #59
During the Issue #59 debugging session, several critical problems were identified:
### 1. Mock Object Mismatches
- Tests created `Mock()` objects without `spec=` parameter
- Mock attributes didn't match actual domain model attributes
- Used strings instead of enums (e.g., `state = "open"` instead of `IssueState.OPEN`)
- Missing required attributes like `created_at`, `updated_at`
### 2. Interface Compatibility Issues
- Tests assumed interface methods that didn't exist in actual implementation
- Async/sync mismatch between repository (async) and expected interface (sync)
- Parameter type mismatches (string vs int for issue IDs)
### 3. Bottom-Up Structure Problems
- Tests written without understanding existing domain model structure
- Assumptions made about interface contracts without verification
- No analysis of existing infrastructure before adding new layers
### 4. Integration Planning Failures
- No clear plan for how new CLI would integrate with existing infrastructure
- Missing adapter layers between async repositories and sync interfaces
- No backward compatibility strategy
## Solution: Requirements Engineering Agent
### Core Components
1. **[Requirements Engineering Agent Documentation](requirements_engineering_agent.md)**
- Complete agent specification
- Methodologies and frameworks
- Tool recommendations
- Example workflows
2. **[Practical Toolkit](../tools/requirements_engineering_toolkit.py)**
- Domain model analyzer
- Mock validator
- Interface compatibility checker
- Development planning tools
3. **[Prevention Demonstration](../examples/issue_59_prevention_demo.py)**
- Shows exactly how Issue #59 problems would be prevented
- Demonstrates correct vs incorrect patterns
- Provides practical examples
4. **[Integration Guide](../docs/integration/requirements_engineering_integration.md)**
- How to integrate with existing workflow
- Enhanced TDD8 process
- Makefile targets and CLI commands
### Key Features
#### Domain Model First (DMF) Approach
```bash
# Before writing any tests, analyze existing domain models
python tools/requirements_engineering_toolkit.py analyze
```
#### Interface Contract Verification
```python
# Ensure mocks match actual domain models
mock_issue = Mock(spec=Issue) # ✅ Use spec=
mock_issue.state = IssueState.OPEN # ✅ Use actual enum
```
#### Incremental Architecture Validation
- Checkpoint-based development
- Interface compatibility checking
- Mock validation at each step
#### Foundation Assessment
- Map existing interfaces before adding new ones
- Understand dependency relationships
- Plan integration points
## Practical Usage
### Quick Start Commands
```bash
# 1. Before starting any new feature
make validate-requirements
# 2. Plan interface evolution
python tools/requirements_engineering_toolkit.py plan-interface --interface YourInterface
# 3. Generate development checklist
python tools/requirements_engineering_toolkit.py checklist --feature "Your Feature"
# 4. Validate test mocks
python tools/requirements_engineering_toolkit.py validate-mocks --test-file tests/your_test.py
```
### Enhanced TDD8 Workflow
1. **ANALYZE** - Analyze existing domain models and interfaces
2. **ISSUE** - Understand requirements in architectural context
3. **TEST** - Write tests that match actual interfaces
4. **RED** - Verify tests fail for right reasons
5. **GREEN** - Implement with interface compatibility
6. **REFACTOR** - Maintain interface contracts
7. **DOCUMENT** - Update interface documentation
8. **PUBLISH** - Commit with interface change documentation
### Integration with Existing Workflow
#### Makefile Enhancement
```makefile
# Add requirements validation to existing workflow
tdd-start: validate-requirements
python tddai_cli.py tdd-start $(NUM)
validate-requirements:
python tools/requirements_engineering_toolkit.py analyze
```
#### Pre-commit Validation
```bash
# Add to pre-commit hooks
make validate-requirements
python -m pytest tests/test_mock_compatibility.py
```
## Specific Issue #59 Prevention
The agent would have prevented Issue #59 problems through:
### 1. Foundation Analysis
- Would have discovered actual `Issue` domain model structure
- Would have identified `IssueState` enum vs string requirement
- Would have mapped existing `GiteaIssueRepository` interface
### 2. Interface Planning
- Would have identified async/sync mismatch between repository and plugin interface
- Would have planned adapter layer needed
- Would have defined clear interface contracts
### 3. Mock Validation
- Would have enforced `Mock(spec=Issue)` usage
- Would have caught attribute mismatches before running tests
- Would have ensured enum usage instead of strings
### 4. Integration Strategy
- Would have planned how CLI integrates with existing infrastructure
- Would have identified reusable components
- Would have maintained backward compatibility
## Benefits
### Development Efficiency
- **Reduced Debugging Time**: Catch interface issues before implementation
- **Faster Development**: Clear development path with validated foundations
- **Better Architecture**: Planned evolution with backward compatibility
### Code Quality
- **Interface Consistency**: All interfaces match actual implementations
- **Type Safety**: Proper use of enums and type hints
- **Test Reliability**: Mocks that match real objects
### Risk Mitigation
- **Early Problem Detection**: Find compatibility issues during planning
- **Backward Compatibility**: Ensure changes don't break existing code
- **Integration Safety**: Validate all integration points
## Implementation Status
### Completed Components
- ✅ Agent specification and methodology
- ✅ Practical toolkit implementation
- ✅ Prevention demonstration
- ✅ Integration guide
- ✅ Documentation and examples
### Ready for Integration
- ✅ Makefile targets defined
- ✅ CLI commands specified
- ✅ Test patterns documented
- ✅ Workflow enhancements planned
### Next Steps
1. Add Makefile targets to existing workflow
2. Create mock compatibility test suite
3. Integrate with TDD8 process
4. Train development team on usage patterns
## Files and Documentation
```
docs/sub_agents/
├── README.md # This overview
├── requirements_engineering_agent.md # Complete agent specification
└── integration/
└── requirements_engineering_integration.md # Integration guide
tools/
└── requirements_engineering_toolkit.py # Practical implementation
examples/
└── issue_59_prevention_demo.py # Prevention demonstration
tests/
└── test_mock_compatibility.py # Mock validation tests (to be created)
```
## Conclusion
The Requirements Engineering and Incremental Development Planning Sub-Agent provides a comprehensive solution to prevent the interface compatibility issues encountered in Issue #59. By implementing systematic foundation analysis, interface contract verification, and mock validation, it ensures that development builds on solid foundations rather than incorrect assumptions.
The agent integrates seamlessly with existing TDD8 workflow and provides practical tools that make requirements engineering a natural part of the development process. This leads to better architecture, fewer bugs, and more efficient development.

View File

@@ -1,228 +0,0 @@
# Agent Tooling Optimizer Sub-Agent
## Executive Summary
The Agent Tooling Optimizer is a specialized meta-agent designed to address Issue #61: "Optimize agent tooling". This agent systematically analyzes repository tooling, identifies missed optimization opportunities, and provides actionable recommendations to improve agent effectiveness in utilizing existing tools and workflows.
## Problem Analysis
### Core Issues Identified
1. **Tool Discovery Gap**: Agents don't always discover or utilize existing repository tooling
2. **Reinvention Patterns**: Agents sometimes implement solutions that already exist
3. **Priming Inefficiency**: Current agent priming doesn't effectively highlight available tools
4. **Workflow Fragmentation**: Disconnect between available tools and agent awareness
### Impact Assessment
- **Development Efficiency**: Time wasted reimplementing existing solutions
- **Consistency**: Inconsistent use of established patterns and tools
- **Maintenance Overhead**: Multiple ways of doing the same thing
- **Knowledge Transfer**: New agents don't inherit tool knowledge effectively
## Agent Capabilities
### 1. Repository Tooling Discovery
- **Makefile Analysis**: Catalog all targets and their purposes
- **CLI Command Mapping**: Document all available CLI commands and subcommands
- **Script Inventory**: Identify and categorize utility scripts
- **Workflow Automation**: Map existing automation and helpers
- **Configuration Discovery**: Find and document configuration patterns
### 2. Session Analysis & Pattern Recognition
- **Conversation Mining**: Analyze past sessions for tooling opportunities
- **Pattern Detection**: Identify recurring reinvention patterns
- **Efficiency Metrics**: Measure tool usage vs. manual implementation
- **Gap Analysis**: Find systematic gaps in tool awareness
### 3. Agent Priming Optimization
- **Context Enhancement**: Improve agent context with tool awareness
- **Usage Patterns**: Document best practices for tool utilization
- **Decision Trees**: Create tool selection guidance
- **Workflow Templates**: Standardize common task approaches
### 4. Continuous Improvement
- **Feedback Loops**: Monitor agent performance post-optimization
- **Tool Evolution**: Track new tools and update recommendations
- **Success Metrics**: Measure improvement in tool utilization
- **Knowledge Base**: Maintain evolving tool knowledge repository
## Implementation Framework
### Core Components
#### 1. Tooling Discovery Engine
```python
class ToolingDiscoveryEngine:
"""Discovers and catalogs repository tooling."""
def discover_makefile_targets(self) -> Dict[str, ToolMetadata]
def analyze_cli_commands(self) -> List[CommandInfo]
def scan_scripts_directory(self) -> List[ScriptInfo]
def map_workflow_automation(self) -> List[WorkflowInfo]
def generate_tool_catalog(self) -> ToolCatalog
```
#### 2. Session Analysis Framework
```python
class SessionAnalyzer:
"""Analyzes coding sessions for tooling optimization opportunities."""
def analyze_conversation_history(self) -> List[MissedOpportunity]
def identify_reinvention_patterns(self) -> List[Pattern]
def calculate_efficiency_metrics(self) -> EfficiencyReport
def generate_optimization_recommendations(self) -> List[Recommendation]
```
#### 3. Agent Priming Optimizer
```python
class AgentPrimingOptimizer:
"""Optimizes agent priming for better tool utilization."""
def generate_tool_context(self) -> str
def create_usage_guidelines(self) -> List[Guideline]
def build_decision_trees(self) -> DecisionTree
def optimize_agent_instructions(self) -> PrimingTemplate
```
### Tool Categories
#### Development Tools
- **Build System**: Make targets, build scripts, automation
- **Testing**: Test runners, validation scripts, quality checks
- **Code Quality**: Linters, formatters, static analysis
- **Documentation**: Generation, validation, organization tools
#### Repository Management
- **Git Workflows**: Branch management, commit patterns, automation
- **Issue Management**: Creation, tracking, closing workflows
- **Project Organization**: Directory structure, file management
- **Configuration**: Environment setup, preferences, settings
#### Domain-Specific Tools
- **Schema Tools**: Generation, validation, transformation
- **Markdown Processing**: Parsing, analysis, manipulation
- **Database Operations**: Query, schema, data management
- **CLI Interface**: Command structure, help systems, integration
## Usage Patterns
### 1. Proactive Discovery Mode
```bash
# Discover all available tooling
python tools/agent_tooling_optimizer.py discover --scope all
# Generate tool catalog
python tools/agent_tooling_optimizer.py catalog --format markdown
# Analyze tool coverage
python tools/agent_tooling_optimizer.py coverage --report detailed
```
### 2. Session Analysis Mode
```bash
# Analyze recent sessions for missed opportunities
python tools/agent_tooling_optimizer.py analyze-sessions --recent 10
# Generate efficiency report
python tools/agent_tooling_optimizer.py efficiency-report --timeframe 30d
# Identify improvement opportunities
python tools/agent_tooling_optimizer.py opportunities --priority high
```
### 3. Priming Optimization Mode
```bash
# Generate optimized agent context
python tools/agent_tooling_optimizer.py optimize-priming --target cli-tasks
# Create usage guidelines
python tools/agent_tooling_optimizer.py guidelines --format handbook
# Update agent instructions
python tools/agent_tooling_optimizer.py update-instructions --validate
```
## Optimization Strategies
### 1. Context Enhancement
- **Tool Inventory Inclusion**: Always include relevant tool inventory in agent context
- **Usage Pattern Documentation**: Provide clear examples of when to use each tool
- **Decision Criteria**: Help agents choose between multiple tool options
- **Success Stories**: Include examples of effective tool usage
### 2. Workflow Standardization
- **Task Templates**: Standardized approaches for common tasks
- **Tool Chains**: Document how tools work together
- **Fallback Patterns**: What to do when preferred tools aren't available
- **Validation Steps**: How to verify tool usage effectiveness
### 3. Knowledge Transfer
- **Agent Handbooks**: Comprehensive tool usage guides
- **Quick Reference**: Fast lookup for common tool operations
- **Best Practices**: Proven patterns for tool utilization
- **Anti-Patterns**: What to avoid and why
## Integration Points
### With Existing Systems
- **Requirements Engineering Agent**: Enhanced tool discovery
- **TDD8 Workflow**: Tool-aware development cycles
- **Issue Management**: Tool recommendations in issue context
- **Documentation Systems**: Tool usage documentation automation
### With Agent Ecosystem
- **General Purpose Agents**: Enhanced tool awareness
- **Specialized Agents**: Domain-specific tool optimization
- **Meta-Agents**: Self-improvement capabilities
- **User Interfaces**: Tool recommendation integration
## Success Metrics
### Quantitative Measures
- **Tool Utilization Rate**: Percentage of tasks using existing tools
- **Reinvention Reduction**: Decrease in redundant implementations
- **Session Efficiency**: Time saved through better tool usage
- **Error Reduction**: Fewer mistakes from tool misuse
### Qualitative Measures
- **Agent Confidence**: Agents more effectively use available tools
- **User Satisfaction**: Smoother workflows and better outcomes
- **Knowledge Retention**: Better tool knowledge transfer between sessions
- **Workflow Consistency**: More standardized approaches
## Implementation Roadmap
### Phase 1: Discovery & Analysis (Immediate)
1. Create tooling discovery engine
2. Analyze current repository tooling landscape
3. Identify immediate optimization opportunities
4. Generate baseline tool catalog
### Phase 2: Optimization & Integration
1. Implement session analysis framework
2. Create agent priming optimization system
3. Integrate with existing agent workflows
4. Develop usage guidelines and best practices
### Phase 3: Continuous Improvement
1. Implement feedback loops and monitoring
2. Create automated tool discovery updates
3. Develop advanced pattern recognition
4. Establish success metrics and reporting
## Expected Outcomes
### Immediate Benefits
- **Complete Tool Inventory**: Comprehensive catalog of available tooling
- **Gap Identification**: Clear view of tooling utilization gaps
- **Quick Wins**: Immediate improvements in tool usage
- **Foundation**: Solid base for ongoing optimization
### Long-term Impact
- **Enhanced Agent Effectiveness**: Agents consistently use appropriate tools
- **Reduced Development Friction**: Smoother workflows and fewer roadblocks
- **Better Knowledge Transfer**: Tool knowledge persists across sessions
- **Continuous Optimization**: Self-improving tooling ecosystem
---
*This agent represents a meta-level optimization approach, focusing on improving how all agents interact with and utilize repository tooling. By systematically addressing tool discovery, usage patterns, and knowledge transfer, it aims to significantly enhance overall development efficiency and agent effectiveness.*

View File

@@ -1,427 +0,0 @@
# Datamodel Optimization Specialist Agent
## Executive Summary
The Datamodel Optimization Specialist is a Claude Code subagent designed to systematically analyze, optimize, and enhance dataclasses, models, and data structures within a codebase. Based on the successful optimization of `IssueActivity` (Issue #126), this agent provides comprehensive datamodel improvements including convenience methods, interface consistency, code reduction, and test alignment.
## Problem Analysis
### Core Issues Identified
1. **Scattered Interface Logic**: Formatting and display logic spread across multiple files
2. **Test/Production Mismatches**: Tests using dictionary mocks instead of proper dataclass objects
3. **Verbose Code Patterns**: Repetitive serialization and formatting code
4. **Poor Encapsulation**: Direct attribute access without convenient methods
5. **Helper Code Complexity**: Complex utility functions handling multiple data formats
### Impact Assessment
- **Development Efficiency**: Time wasted on repetitive formatting and serialization
- **Code Maintainability**: Logic scattered across multiple locations
- **Test Reliability**: Fragile dictionary mocks breaking easily
- **Interface Consistency**: Inconsistent access patterns across codebase
## Agent Capabilities
### 1. Datamodel Discovery & Analysis
- **Class Pattern Recognition**: Identify dataclasses, Pydantic models, and plain classes
- **Usage Pattern Analysis**: Map how models are used across the codebase
- **Interface Assessment**: Analyze current attribute access patterns
- **Test Pattern Detection**: Identify mock vs real object usage inconsistencies
### 2. Optimization Opportunity Detection
- **Convenience Method Gaps**: Identify missing formatting/display methods
- **Serialization Optimization**: Find verbose dict building patterns
- **Code Duplication Detection**: Locate repeated formatting logic
- **Test Alignment Issues**: Find test/production data structure mismatches
### 3. Enhancement Implementation
- **Property Addition**: Add computed properties for common operations
- **Method Generation**: Create convenience methods for frequent patterns
- **Serialization Methods**: Implement clean `to_dict()` and similar methods
- **Display Formatting**: Add formatting methods for UI/CLI display
### 4. Test Consistency Resolution
- **Mock Replacement**: Convert dictionary mocks to proper object instances
- **Test Data Factories**: Create factories for consistent test objects
- **Mock Validation**: Ensure mocks match real object interfaces
- **Test Coverage Enhancement**: Improve test reliability and maintainability
## Methodology Framework
### Phase 1: Discovery & Analysis
#### 1.1 Datamodel Inventory
```python
# Discover dataclasses and models
find . -name "*.py" -exec grep -l "@dataclass\|BaseModel\|class.*:" {} \;
# Analyze attribute patterns
grep -r "def __init__\|@property" --include="*.py" .
# Map usage patterns
grep -rn "\.attribute\|\.method" --include="*.py" .
```
#### 1.2 Usage Pattern Analysis
```bash
# Find formatting patterns
grep -r "strftime\|\.value\|\.lower()\|\.upper()" --include="*.py" .
# Identify serialization patterns
grep -r "{'.*':\|dict(\|\.items()\|\.keys()" --include="*.py" .
# Detect repetitive code
grep -r -A5 -B5 "for.*in.*:" --include="*.py" . | grep -A10 -B10 "append\|\.get("
```
#### 1.3 Test Pattern Assessment
```bash
# Find mock usage
grep -r "Mock(\|mock\.\|@patch" tests/ --include="*.py"
# Identify dictionary test data
grep -r "{\s*['\"].*['\"]\s*:" tests/ --include="*.py"
# Map test data patterns
grep -r "test.*data\|mock.*data" tests/ --include="*.py"
```
### Phase 2: Optimization Strategy Development
#### 2.1 Enhancement Planning
Based on analysis, create optimization plan:
**Property Candidates:**
- Date/datetime formatting
- Enum value extraction
- Display-friendly representations
- Truncated content for UI
**Method Candidates:**
- Keyword search functionality
- Business logic validation
- Serialization/deserialization
- Comparison operations
**Code Reduction Opportunities:**
- Verbose dictionary building → single method calls
- Repeated formatting logic → property access
- Complex conditional logic → method encapsulation
#### 2.2 Impact Assessment
```python
class OptimizationImpact:
"""Assess potential impact of datamodel optimization."""
def calculate_loc_reduction(self, patterns: List[Pattern]) -> int:
"""Calculate potential lines of code reduction."""
pass
def assess_maintainability_improvement(self) -> MetricScore:
"""Evaluate maintainability improvements."""
pass
def estimate_test_reliability_gain(self) -> MetricScore:
"""Estimate test reliability improvements."""
pass
```
### Phase 3: Implementation Execution
#### 3.1 Datamodel Enhancement
```python
# Example enhancement pattern (based on IssueActivity)
@dataclass
class OptimizedDataModel:
# Original fields (preserve existing interface)
core_field: str
enum_field: SomeEnum
date_field: date
# Add convenience properties
@property
def enum_value(self) -> str:
"""Get string value of enum field."""
return self.enum_field.value if self.enum_field else ''
@property
def display_name(self) -> str:
"""Get display-friendly representation."""
return self.enum_value.replace('_', ' ').title()
@property
def formatted_date(self) -> str:
"""Get formatted date string."""
return self.date_field.strftime('%Y-%m-%d') if self.date_field else 'N/A'
# Add convenience methods
def contains_keyword(self, keyword: str, case_sensitive: bool = False) -> bool:
"""Check if model contains keyword."""
pass
def to_dict(self) -> Dict[str, Any]:
"""Convert to dictionary representation."""
pass
```
#### 3.2 Code Simplification
```python
# BEFORE: Verbose patterns
data_list = []
for item in items:
data = {
'id': item.id,
'name': item.name,
'status': item.status.value if item.status else '',
'date': item.date.strftime('%Y-%m-%d') if item.date else 'N/A'
}
data_list.append(data)
# AFTER: Optimized pattern
data_list = [item.to_dict() for item in items]
```
#### 3.3 Test Consistency Resolution
```python
# BEFORE: Dictionary mocks
mock_data = {
'field1': 'value1',
'field2': 'value2',
'status': 'active' # String instead of enum!
}
# AFTER: Proper object instances
from models import DataModel, StatusEnum
test_data = DataModel(
field1='value1',
field2='value2',
status=StatusEnum.ACTIVE # Proper enum usage
)
```
### Phase 4: Validation & Testing
#### 4.1 Functionality Preservation
```bash
# Ensure all tests still pass
pytest --tb=short -x
# Verify no breaking changes
python -c "from models import DataModel; print('Interface preserved')"
# Check type consistency
mypy . --strict
```
#### 4.2 Optimization Verification
```python
class OptimizationValidator:
"""Validate optimization results."""
def verify_loc_reduction(self) -> bool:
"""Verify actual LOC reduction matches estimates."""
pass
def validate_interface_preservation(self) -> bool:
"""Ensure existing interfaces still work."""
pass
def check_performance_impact(self) -> PerformanceReport:
"""Measure any performance impact."""
pass
```
## Core Optimization Patterns
### Pattern 1: Property-Based Formatting
**Problem**: Repetitive formatting code scattered across files
**Solution**: Centralized formatting properties
```python
# Replace scattered formatting
activity.activity_type.value.title()
activity.activity_date.strftime('%Y-%m-%d') if activity.activity_date else 'N/A'
(activity.details[:40] + '...') if len(activity.details) > 40 else activity.details
# With clean properties
activity.activity_type_display
activity.formatted_date
activity.truncated_details
```
### Pattern 2: Serialization Method Consolidation
**Problem**: Verbose dictionary building patterns
**Solution**: Single method calls
```python
# Replace 18-line dictionary building
activity_data = []
for activity in activities:
data = {
'id': activity.id,
'type': activity.activity_type.value,
'date': activity.activity_date.isoformat() if activity.activity_date else None,
# ... many more lines
}
activity_data.append(data)
# With single method call
activity_data = [activity.to_dict() for activity in activities]
```
### Pattern 3: Business Logic Encapsulation
**Problem**: Complex conditional logic spread across codebase
**Solution**: Encapsulated methods
```python
# Replace complex logic
has_implementation = any(
'implement' in (getattr(activity, 'activity_type', None).value
if hasattr(activity, 'activity_type') and getattr(activity, 'activity_type')
else activity.get('activity_type', '') if hasattr(activity, 'get')
else '').lower()
for activity in activities
)
# With simple method call
has_implementation = any(activity.has_implementation_activity() for activity in activities)
```
### Pattern 4: Test Data Consistency
**Problem**: Mock/real object mismatches
**Solution**: Proper object instances in tests
```python
# Replace fragile dictionary mocks
with patch.object(service, 'get_activities') as mock_activities:
mock_activities.return_value = [
{'activity_type': 'implementation', 'description': 'Implemented feature'}
]
# With proper objects
with patch.object(service, 'get_activities') as mock_activities:
mock_activities.return_value = [
Activity(
activity_type=ActivityType.CREATED,
activity_details='Implemented feature'
)
]
```
## Integration Framework
### With Existing Claude Code Tools
- **Task Agent**: Enhanced for datamodel-specific optimization tasks
- **TodoWrite**: Track optimization progress with specific checkpoints
- **Testing Framework**: Validate optimizations don't break functionality
- **Git Integration**: Clean commits with comprehensive optimization documentation
### With Development Workflow
- **Issue Analysis**: Identify datamodel optimization opportunities in issues
- **Code Review**: Suggest optimizations during development
- **Refactoring Support**: Guide systematic datamodel improvements
- **Documentation**: Maintain optimization knowledge base
## Success Metrics
### Quantitative Measures
- **Lines of Code Reduction**: Measure LOC saved through optimization
- **Code Duplication Elimination**: Track removed duplicate patterns
- **Test Reliability Improvement**: Measure test failure reduction
- **Method Call Simplification**: Count complex patterns replaced with simple calls
### Qualitative Measures
- **Code Maintainability**: Easier to modify and extend datamodels
- **Developer Experience**: Cleaner APIs and more intuitive interfaces
- **Test Consistency**: Reliable test data that matches production models
- **Interface Clarity**: Clear, well-documented datamodel interfaces
## Expected Optimization Outcomes
### Based on IssueActivity Success (Issue #126)
**Code Reduction Achieved:**
- JSON serialization: 18 lines → 1 line (94% reduction)
- Implementation detection: 13 lines → 3 lines (77% reduction)
- Table formatting: 8 lines → 6 lines (25% reduction)
- **Total**: ~21 lines of complex helper code eliminated
**Quality Improvements:**
- Single source of truth for all operations
- Consistent interface across all usage patterns
- Better encapsulation and maintainability
- Enhanced code readability and reliability
### Scalable Benefits
- **Per-datamodel savings**: ~15-25 lines of code reduction potential
- **Codebase-wide impact**: Systematic improvement across all datamodels
- **Maintenance efficiency**: Centralized logic reduces update overhead
- **Development velocity**: Faster feature development with better abstractions
## Usage Patterns
### 1. Proactive Analysis Mode
```bash
# Discover optimization opportunities
markitect analyze-datamodels --scope all --report detailed
# Generate optimization plan
markitect plan-datamodel-optimization --target DataModelClass
# Estimate impact
markitect estimate-optimization-impact --model DataModelClass
```
### 2. Guided Optimization Mode
```bash
# Interactive optimization session
markitect optimize-datamodel --interactive DataModelClass
# Apply common patterns
markitect apply-optimization-patterns --pattern serialization DataModelClass
# Validate optimization
markitect validate-datamodel-optimization DataModelClass
```
### 3. Batch Processing Mode
```bash
# Optimize all datamodels
markitect batch-optimize-datamodels --safe-mode
# Generate optimization report
markitect datamodel-optimization-report --format detailed
# Create test alignment fixes
markitect fix-test-datamodel-alignment --auto-apply
```
## Implementation Roadmap
### Phase 1: Agent Foundation (Immediate)
1. Create datamodel discovery engine
2. Implement usage pattern analysis
3. Develop optimization opportunity detection
4. Generate baseline assessment tools
### Phase 2: Core Optimization Capabilities
1. Implement property generation framework
2. Create method enhancement system
3. Build serialization optimization tools
4. Develop test alignment correction
### Phase 3: Advanced Features
1. Add performance impact analysis
2. Implement optimization success tracking
3. Create integration with existing workflows
4. Develop optimization knowledge base
### Phase 4: Ecosystem Integration
1. Integration with Claude Code agent system
2. Automated optimization suggestions
3. Continuous improvement feedback loops
4. Documentation and training materials
---
*This agent embodies the systematic approach to datamodel optimization demonstrated in the successful IssueActivity enhancement (Issue #126), providing a reusable framework for improving datamodels throughout any codebase while maintaining interface compatibility and test reliability.*

View File

@@ -1,442 +0,0 @@
# Requirements Engineering and Incremental Development Planning Agent
## Overview
A specialized sub-agent designed to prevent interface compatibility issues and mock object mismatches by ensuring solid foundation planning before implementation. This agent addresses the core problems encountered during Issue #59 development where tests assumed interfaces that didn't match the actual domain models.
## Agent Responsibilities
### 1. Bottom-Up Structure Planning
- **Domain Model Discovery**: Analyze existing domain models before writing any tests
- **Interface Inventory**: Map all existing interfaces, abstract classes, and concrete implementations
- **Dependency Mapping**: Understand the complete dependency graph before adding new components
- **Foundation Assessment**: Ensure solid architectural foundations before building new features
### 2. Interface Contract Definition
- **Contract Verification**: Verify that all interfaces match actual implementations
- **Mock Alignment**: Ensure mock objects exactly match real domain model attributes and methods
- **API Compatibility**: Check that new interfaces are compatible with existing infrastructure
- **Type Safety**: Ensure all type hints and signatures are consistent across layers
### 3. Incremental Validation Strategy
- **Validation Checkpoints**: Define specific validation points throughout development
- **Integration Testing**: Plan integration tests before unit tests
- **Compatibility Testing**: Verify backward compatibility at each increment
- **Interface Evolution**: Plan how interfaces will evolve without breaking existing code
### 4. Test-Driven Architecture
- **Domain-First Testing**: Ensure tests reflect actual domain model requirements
- **Infrastructure Awareness**: Write tests that understand existing infrastructure patterns
- **Mock Strategy**: Create mocks that exactly match real object interfaces
- **Test Architecture**: Design test architecture that matches application architecture
## Core Methodologies
### 1. Domain Model First (DMF) Approach
Before writing any tests or implementation:
```bash
# 1. Analyze existing domain models
grep -r "class.*:" domain/*/models.py
grep -r "def " domain/*/models.py
# 2. Map existing interfaces
find . -name "*.py" -exec grep -l "class.*ABC\|@abstractmethod" {} \;
# 3. Understand data flow
grep -r "Repository\|Service" infrastructure/ domain/
```
**Workflow:**
1. **Domain Discovery**: Map all existing domain models and their attributes
2. **Interface Analysis**: Understand all abstract base classes and interfaces
3. **Dependency Review**: Trace dependencies between layers
4. **Contract Documentation**: Document all interface contracts before modification
### 2. Interface-Contract-First (ICF) Testing
```python
# WRONG - Assumption-based mocking
mock_issue = Mock()
mock_issue.number = 59
mock_issue.title = "Test"
mock_issue.state = "open" # String instead of enum!
# RIGHT - Contract-verified mocking
from domain.issues.models import Issue, IssueState, Label
mock_issue = Mock(spec=Issue)
mock_issue.number = 59
mock_issue.title = "Test Issue"
mock_issue.state = IssueState.OPEN # Proper enum
mock_issue.labels = []
mock_issue.created_at = datetime.now(timezone.utc)
mock_issue.updated_at = datetime.now(timezone.utc)
```
**Workflow:**
1. **Spec-Based Mocking**: Always use `spec=` parameter with actual classes
2. **Attribute Verification**: Verify all mock attributes match real object attributes
3. **Type Consistency**: Ensure mock data types match domain model types
4. **Enum Handling**: Use actual enums instead of string representations
### 3. Incremental Architecture Validation (IAV)
**Validation Checkpoints:**
- **Checkpoint 1**: Domain model compatibility
- **Checkpoint 2**: Interface contract verification
- **Checkpoint 3**: Mock object alignment
- **Checkpoint 4**: Integration test validation
- **Checkpoint 5**: End-to-end workflow testing
**Implementation:**
```bash
# Validation script template
validate_domain_compatibility() {
python -c "
from domain.issues.models import Issue
from markitect.issues.base import IssueBackend
# Verify interface compatibility
"
}
validate_mock_alignment() {
# Run tests that verify mocks match real objects
python -m pytest tests/test_mock_compatibility.py
}
```
### 4. Foundation-First Development (FFD)
**Principle**: Build on solid foundations before adding new layers.
**Workflow:**
1. **Foundation Assessment**: Verify existing infrastructure is solid
2. **Interface Stability**: Ensure base interfaces won't change during development
3. **Dependency Injection**: Plan dependency injection patterns
4. **Layer Separation**: Maintain clear separation between architectural layers
## Tools and Frameworks
### 1. Domain Analysis Tools
```bash
# Domain Model Inspector
analyze_domain_models() {
echo "=== Domain Model Analysis ==="
find domain/ -name "models.py" -exec echo "File: {}" \; -exec grep -n "class\|def " {} \;
}
# Interface Contract Checker
check_interface_contracts() {
echo "=== Interface Contract Analysis ==="
grep -r "@abstractmethod\|ABC" . --include="*.py"
}
# Mock Compatibility Validator
validate_mocks() {
echo "=== Mock Compatibility Check ==="
python -c "
import inspect
from domain.issues.models import Issue
print('Issue attributes:', [attr for attr in dir(Issue) if not attr.startswith('_')])
"
}
```
### 2. Test Architecture Framework
```python
# Test Base Classes for Interface Compliance
class DomainModelTestBase:
"""Base class ensuring tests match domain models."""
def setUp(self):
self.validate_test_setup()
def validate_test_setup(self):
"""Verify test setup matches actual domain models."""
pass
def create_mock_with_spec(self, domain_class):
"""Create spec-compliant mock."""
return Mock(spec=domain_class)
class IntegrationTestBase:
"""Base class for integration tests."""
def setUp(self):
self.verify_infrastructure_availability()
def verify_infrastructure_availability(self):
"""Ensure required infrastructure is available."""
pass
```
### 3. Interface Evolution Manager
```python
class InterfaceEvolutionManager:
"""Manages interface changes without breaking compatibility."""
def plan_interface_change(self, interface_name, changes):
"""Plan interface changes with backward compatibility."""
pass
def validate_compatibility(self, old_interface, new_interface):
"""Validate that new interface is backward compatible."""
pass
def generate_migration_plan(self, changes):
"""Generate step-by-step migration plan."""
pass
```
### 4. Mock Validation Framework
```python
class MockValidator:
"""Validates that mocks match real objects."""
@staticmethod
def validate_mock_spec(mock_obj, real_class):
"""Validate mock object matches real class specification."""
mock_attrs = set(dir(mock_obj))
real_attrs = set(dir(real_class))
missing_attrs = real_attrs - mock_attrs
extra_attrs = mock_attrs - real_attrs
if missing_attrs:
raise MockSpecError(f"Mock missing attributes: {missing_attrs}")
return True
@staticmethod
def validate_mock_types(mock_obj, real_instance):
"""Validate mock attribute types match real object types."""
for attr_name in dir(real_instance):
if not attr_name.startswith('_'):
real_value = getattr(real_instance, attr_name)
mock_value = getattr(mock_obj, attr_name, None)
if mock_value is not None and type(mock_value) != type(real_value):
raise MockTypeError(f"Type mismatch for {attr_name}")
```
## Example Workflows
### 1. Adding New CLI Command Workflow
**Phase 1: Foundation Analysis**
```bash
# 1. Analyze existing CLI structure
find cli/ -name "*.py" -exec grep -l "click\|@cli" {} \;
# 2. Understand existing domain models
python -c "
from domain.issues.models import Issue
import inspect
print(inspect.signature(Issue.__init__))
"
# 3. Map existing repository interfaces
grep -r "class.*Repository" infrastructure/
```
**Phase 2: Interface Contract Definition**
```python
# Define interface contract first
class IssueBackend(ABC):
@abstractmethod
def list_issues(self, state: Optional[str] = None) -> List[Issue]:
"""List issues with optional state filter."""
pass
@abstractmethod
def get_issue(self, issue_id: str) -> Issue:
"""Get specific issue by ID."""
pass
```
**Phase 3: Test Architecture Design**
```python
# Design tests that match actual interfaces
class TestIssuesCLIGroup:
def setup_method(self):
# Use actual domain model for mock spec
self.mock_issue = Mock(spec=Issue)
self.mock_issue.number = 59
self.mock_issue.title = "Test Issue"
self.mock_issue.state = IssueState.OPEN # Use actual enum
self.mock_issue.labels = []
self.mock_issue.created_at = datetime.now(timezone.utc)
self.mock_issue.updated_at = datetime.now(timezone.utc)
```
**Phase 4: Incremental Implementation**
- Implement abstract base class
- Create plugin system
- Add CLI commands
- Integrate with existing infrastructure
### 2. Domain Model Extension Workflow
**Phase 1: Impact Analysis**
```bash
# Find all usages of the domain model
grep -r "Issue" . --include="*.py" | grep -v __pycache__
# Check existing tests
grep -r "Issue" tests/ --include="*.py"
# Analyze database schemas
grep -r "Issue" infrastructure/repositories/
```
**Phase 2: Backward Compatibility Planning**
```python
# Plan extension that maintains compatibility
@dataclass
class Issue:
# Existing attributes (DO NOT CHANGE)
number: int
title: str
state: IssueState
labels: List[Label]
created_at: datetime
updated_at: datetime
# New attributes (with defaults for compatibility)
body: str = "" # Add with default
assignees: List[str] = field(default_factory=list)
html_url: str = ""
```
**Phase 3: Migration Strategy**
```python
# Create migration tests
class TestIssueModelMigration:
def test_old_constructor_still_works(self):
"""Ensure old constructor calls still work."""
issue = Issue(
number=1,
title="Test",
state=IssueState.OPEN,
labels=[],
created_at=datetime.now(timezone.utc),
updated_at=datetime.now(timezone.utc)
)
assert issue.body == "" # Default value
```
### 3. Plugin System Development Workflow
**Phase 1: Architecture Planning**
```python
# Define plugin interface based on existing patterns
class IssueBackend(ABC):
"""Abstract base class matching existing repository patterns."""
def __init__(self, config: Dict[str, Any]):
self.config = config
@abstractmethod
def list_issues(self, state: Optional[str] = None) -> List[Issue]:
pass
```
**Phase 2: Integration Strategy**
```python
# Plan integration with existing infrastructure
class GiteaPlugin(IssueBackend):
def __init__(self, config: Dict[str, Any]):
super().__init__(config)
# Reuse existing infrastructure
self.repository = GiteaIssueRepository(
connection_manager=self._create_connection_manager()
)
def list_issues(self, state: Optional[str] = None) -> List[Issue]:
# Use existing async infrastructure
return asyncio.run(self.repository.get_issues(state=state))
```
## Integration Points with Existing Development Workflow
### 1. TDD8 Enhancement
**Enhanced TDD8 Workflow:**
1. **ANALYZE** - Analyze existing domain models and interfaces
2. **ISSUE** - Understand requirements in context of existing architecture
3. **TEST** - Write tests that match actual interfaces
4. **RED** - Verify tests fail for right reasons
5. **GREEN** - Implement with interface compatibility
6. **REFACTOR** - Maintain interface contracts
7. **DOCUMENT** - Update interface documentation
8. **PUBLISH** - Commit with interface change documentation
### 2. TodoWrite Integration
```python
# Enhanced TodoWrite with validation checkpoints
todos = [
{
"content": "Analyze existing Issue domain model",
"status": "pending",
"activeForm": "Analyzing existing Issue domain model",
"checkpoint": "domain_analysis"
},
{
"content": "Define IssueBackend interface contract",
"status": "pending",
"activeForm": "Defining IssueBackend interface contract",
"checkpoint": "interface_definition"
},
{
"content": "Create spec-compliant mocks",
"status": "pending",
"activeForm": "Creating spec-compliant mocks",
"checkpoint": "mock_validation"
}
]
```
### 3. CLI Help Integration
```bash
# Enhanced CLI with validation commands
markitect validate-interfaces # Check interface compatibility
markitect analyze-domain # Analyze domain models
markitect check-mocks # Validate mock objects
markitect plan-migration # Plan interface migrations
```
## Success Metrics
### 1. Interface Compatibility
- **Zero Mock Mismatches**: All mocks must match actual object interfaces
- **Type Safety**: 100% type consistency between tests and implementation
- **Backward Compatibility**: No breaking changes to existing interfaces
### 2. Test Quality
- **Domain Model Alignment**: Tests reflect actual domain model structure
- **Integration Coverage**: All integration points tested with real interfaces
- **Mock Validation**: All mocks validated against real object specifications
### 3. Development Efficiency
- **Reduced Debugging**: Fewer interface-related bugs
- **Faster Development**: Less time spent fixing mock mismatches
- **Better Architecture**: Cleaner interface design and evolution
## Prevention of Issue #59 Problems
This agent would have prevented the Issue #59 problems by:
1. **Domain Model Analysis**: Would have discovered the actual Issue model has `IssueState` enum, not string
2. **Interface Inventory**: Would have mapped existing GiteaIssueRepository before designing plugin interface
3. **Mock Validation**: Would have caught mock attribute mismatches before running tests
4. **Integration Planning**: Would have planned how new CLI integrates with existing infrastructure
5. **Contract Verification**: Would have ensured all interfaces match actual implementations
The result would be a solid, well-planned implementation that builds on existing foundations rather than making incorrect assumptions about interfaces and domain models.

View File

@@ -1,395 +0,0 @@
# Testing Efficiency Optimizer Sub-Agent
## Executive Summary
The Testing Efficiency Optimizer is a specialized sub-agent designed to address Issue #57: "Try to be more efficient automatically calling the tests". This agent focuses on optimizing TDD8 workflow test execution, resolving pytest reliability issues, and enhancing overall testing efficiency for red-green iterations.
## Problem Analysis
### Core Issues Identified
1. **Pytest Reliability Problems**: Mysterious "some problem with pytest" messages interrupting workflow
2. **Test Execution Inefficiency**: Suboptimal test running patterns affecting TDD8 performance
3. **Interface Optimization**: Test running interface may need improvements
4. **Agent Usage Patterns**: Claude may not be using test tools correctly
5. **TDD8 Workflow Integration**: Test efficiency directly impacts red-green iteration speed
### Impact Assessment
- **TDD8 Performance**: Slow or unreliable tests break TDD flow
- **Development Velocity**: Test issues create friction in development cycles
- **Agent Effectiveness**: Unreliable test execution affects agent confidence
- **Workflow Disruption**: Test failures interrupt development momentum
## Agent Capabilities
### 1. Test Execution Diagnosis & Optimization
- **Pytest Issue Detection**: Identify and resolve common pytest problems
- **Test Performance Analysis**: Measure and optimize test execution speed
- **Configuration Optimization**: Enhance pytest and test infrastructure setup
- **Cache Management**: Optimize test caching for faster iterations
### 2. TDD8 Workflow Integration
- **Red-Green Cycle Optimization**: Streamline test execution for TDD cycles
- **Test Selection Intelligence**: Run only relevant tests for specific changes
- **Parallel Execution**: Optimize test parallelization for speed
- **Incremental Testing**: Smart test discovery and execution strategies
### 3. Interface & Automation Improvements
- **Test Command Standardization**: Ensure consistent test execution patterns
- **Error Handling**: Robust error recovery and meaningful error messages
- **Agent Integration**: Optimize how agents interact with test infrastructure
- **Workflow Automation**: Automated test execution triggers and patterns
### 4. Monitoring & Continuous Improvement
- **Performance Metrics**: Track test execution times and reliability
- **Failure Pattern Analysis**: Identify recurring test issues
- **Optimization Recommendations**: Continuous improvement suggestions
- **Health Monitoring**: Test infrastructure health checks
## Implementation Framework
### Core Components
#### 1. Test Execution Analyzer
```python
class TestExecutionAnalyzer:
"""Analyzes test execution patterns and identifies optimization opportunities."""
def analyze_pytest_issues(self) -> List[PytestIssue]
def measure_test_performance(self) -> TestPerformanceMetrics
def identify_slow_tests(self) -> List[SlowTest]
def analyze_test_patterns(self) -> TestPatternAnalysis
def diagnose_infrastructure_issues(self) -> InfrastructureReport
```
#### 2. TDD8 Workflow Optimizer
```python
class TDD8WorkflowOptimizer:
"""Optimizes test execution for TDD8 red-green cycles."""
def optimize_red_phase(self) -> RedPhaseOptimization
def optimize_green_phase(self) -> GreenPhaseOptimization
def implement_smart_test_selection(self) -> TestSelectionStrategy
def optimize_test_feedback_loop(self) -> FeedbackOptimization
```
#### 3. Test Infrastructure Enhancer
```python
class TestInfrastructureEnhancer:
"""Enhances test infrastructure for reliability and performance."""
def optimize_pytest_configuration(self) -> ConfigOptimization
def implement_test_caching(self) -> CacheStrategy
def setup_parallel_execution(self) -> ParallelConfig
def enhance_error_reporting(self) -> ErrorReportingConfig
```
#### 4. Agent Integration Optimizer
```python
class AgentIntegrationOptimizer:
"""Optimizes how agents interact with test infrastructure."""
def generate_test_execution_patterns(self) -> List[ExecutionPattern]
def create_agent_test_guidelines(self) -> AgentGuidelines
def implement_intelligent_test_selection(self) -> TestSelectionLogic
def optimize_agent_test_workflows(self) -> WorkflowOptimization
```
## Diagnostic Framework
### Common Pytest Issues & Solutions
#### 1. Import Path Problems
```python
# Common Issue: ModuleNotFoundError
# Solution: PYTHONPATH configuration
def fix_import_paths():
"""Ensure PYTHONPATH is correctly set for test execution."""
import os
import sys
# Add project root to path
project_root = os.path.dirname(os.path.abspath(__file__))
if project_root not in sys.path:
sys.path.insert(0, project_root)
```
#### 2. Cache Corruption Issues
```python
# Common Issue: Pytest cache corruption
# Solution: Cache cleanup and optimization
def optimize_pytest_cache():
"""Clean and optimize pytest cache for reliable execution."""
cache_dirs = ['.pytest_cache', '__pycache__']
# Implementation for cache cleanup
```
#### 3. Test Discovery Problems
```python
# Common Issue: Tests not discovered or run
# Solution: Improved test discovery configuration
def optimize_test_discovery():
"""Optimize pytest test discovery patterns."""
pytest_config = {
'testpaths': ['tests'],
'python_files': ['test_*.py', '*_test.py'],
'python_classes': ['Test*'],
'python_functions': ['test_*']
}
```
### Performance Optimization Strategies
#### 1. Smart Test Selection
- **Changed File Detection**: Run tests only for modified code
- **Dependency Analysis**: Include tests for dependent modules
- **Test Impact Analysis**: Prioritize high-impact test execution
- **Incremental Testing**: Cache results for unchanged code
#### 2. Parallel Execution Optimization
- **Worker Process Management**: Optimal number of parallel workers
- **Test Distribution**: Smart distribution across workers
- **Resource Management**: Memory and CPU optimization
- **Lock Management**: Prevent resource conflicts
#### 3. Cache Optimization
- **Result Caching**: Cache test results for unchanged code
- **Dependency Caching**: Cache test dependencies
- **Import Caching**: Optimize module import caching
- **Data Caching**: Cache test data and fixtures
## TDD8 Integration Patterns
### Red Phase Optimization
```bash
# Fast failure detection
make test-quick # Run fastest tests first
make test-changed # Run tests for changed files only
make test-arch # Run architectural tests quickly
```
### Green Phase Optimization
```bash
# Comprehensive validation
make test # Full test suite
make test-coverage # With coverage analysis
make test-integration # Integration tests
```
### Continuous Feedback
```bash
# Watch mode for continuous testing
make test-watch # Auto-run tests on file changes
make test-tdd # TDD-optimized test execution
```
## Optimization Strategies
### 1. Test Execution Efficiency
#### Fast Feedback Loops
- **Subset Testing**: Run minimal tests for quick feedback
- **Parallel Execution**: Utilize multiple cores effectively
- **Smart Caching**: Cache test results and dependencies
- **Incremental Execution**: Run only necessary tests
#### Reliability Improvements
- **Robust Configuration**: Eliminate configuration-related failures
- **Error Recovery**: Automatic recovery from common issues
- **Clear Diagnostics**: Meaningful error messages and debugging info
- **Health Checks**: Pre-execution environment validation
### 2. TDD8 Workflow Integration
#### Red-Green Cycle Optimization
- **Fast Red**: Quick test execution to confirm failure
- **Efficient Green**: Targeted test execution for implementation
- **Smart Refactor**: Test execution during refactoring phases
- **Continuous Validation**: Background test execution
#### Intelligent Test Selection
```python
class SmartTestSelector:
def select_tests_for_change(self, changed_files: List[str]) -> List[str]:
"""Select relevant tests based on changed files."""
def prioritize_tests(self, test_files: List[str]) -> List[str]:
"""Prioritize tests by execution time and importance."""
def filter_by_coverage(self, tests: List[str], coverage_threshold: float) -> List[str]:
"""Filter tests based on code coverage impact."""
```
### 3. Infrastructure Optimization
#### Pytest Configuration Enhancement
```ini
# Enhanced pytest.ini configuration
[tool:pytest]
minversion = 6.0
addopts =
--strict-markers
--strict-config
--disable-warnings
--tb=short
--maxfail=5
--timeout=300
-ra
testpaths = tests
python_files = test_*.py
python_classes = Test*
python_functions = test_*
markers =
slow: marks tests as slow
integration: marks tests as integration tests
unit: marks tests as unit tests
smoke: marks tests as smoke tests
```
#### Make Target Optimization
```makefile
# Optimized test targets
test-fast:
@echo "🏃‍♂️ Running fast tests..."
PYTHONPATH=. python -m pytest tests/ -m "not slow" --maxfail=3 -x
test-changed:
@echo "🔄 Running tests for changed files..."
PYTHONPATH=. python -m pytest $(shell git diff --name-only HEAD~1 | grep test_ | tr '\n' ' ')
test-smart:
@echo "🧠 Running smart test selection..."
PYTHONPATH=. python tools/smart_test_selector.py | xargs python -m pytest
```
## Agent Integration Guidelines
### 1. Test Execution Patterns for Agents
#### Preferred Test Commands
```bash
# Primary test execution (most reliable)
make test
# Fast feedback for TDD
make test-quick
# Changed files only
make test-changed
# Specific test file
PYTHONPATH=. python -m pytest tests/specific_test.py -v
```
#### Error Handling Patterns
```python
# Robust test execution with error handling
def execute_tests_safely(test_target: str = "test") -> TestResult:
"""Execute tests with proper error handling and recovery."""
try:
# Clear cache if needed
clear_pytest_cache()
# Set proper environment
setup_test_environment()
# Execute tests
result = run_test_command(f"make {test_target}")
return result
except PytestError as e:
# Handle specific pytest errors
return handle_pytest_error(e)
except Exception as e:
# Handle general errors
return handle_general_error(e)
```
### 2. TDD8 Workflow Integration
#### Red Phase Agent Pattern
```python
def execute_red_phase_tests(test_file: str) -> bool:
"""Execute tests for TDD red phase - expect failures."""
result = execute_tests_safely("test-quick")
if result.has_failures:
logger.info("✅ Red phase successful - tests failing as expected")
return True
else:
logger.warning("⚠️ Red phase issue - tests not failing")
return False
```
#### Green Phase Agent Pattern
```python
def execute_green_phase_tests() -> bool:
"""Execute tests for TDD green phase - expect success."""
result = execute_tests_safely("test")
if result.all_passed:
logger.info("✅ Green phase successful - all tests passing")
return True
else:
logger.error("❌ Green phase failed - implementation needs work")
return False
```
## Monitoring & Metrics
### Performance Metrics
- **Test Execution Time**: Track overall and individual test times
- **Cache Hit Rate**: Measure test caching effectiveness
- **Parallel Efficiency**: Monitor parallel execution performance
- **Failure Rate**: Track test reliability over time
### Quality Metrics
- **Coverage**: Ensure adequate test coverage
- **Test Health**: Monitor test maintenance and quality
- **Flaky Test Detection**: Identify and fix unreliable tests
- **Dependencies**: Track test dependency health
### Workflow Metrics
- **TDD Cycle Time**: Measure red-green-refactor cycle efficiency
- **Agent Success Rate**: Track agent test execution success
- **Error Recovery**: Monitor error handling effectiveness
- **Developer Satisfaction**: Measure workflow efficiency impact
## Implementation Roadmap
### Phase 1: Diagnostic & Analysis (Immediate)
1. **Pytest Issue Diagnosis**: Identify and document current pytest problems
2. **Performance Baseline**: Establish current test execution metrics
3. **Pattern Analysis**: Analyze current test usage patterns
4. **Configuration Audit**: Review and optimize current test configuration
### Phase 2: Optimization & Enhancement
1. **Test Infrastructure Enhancement**: Implement performance optimizations
2. **Smart Test Selection**: Deploy intelligent test selection strategies
3. **Agent Integration**: Optimize agent test execution patterns
4. **TDD8 Workflow Integration**: Streamline red-green cycle testing
### Phase 3: Automation & Monitoring
1. **Automated Optimization**: Implement continuous test optimization
2. **Performance Monitoring**: Deploy test performance tracking
3. **Predictive Optimization**: Implement predictive test selection
4. **Continuous Improvement**: Establish feedback loops for ongoing optimization
## Expected Outcomes
### Immediate Benefits
- **Resolved Pytest Issues**: Eliminate mysterious pytest problems
- **Faster Test Execution**: Optimized test running for TDD8 cycles
- **Improved Reliability**: Consistent, reliable test execution
- **Better Agent Integration**: Agents use test infrastructure effectively
### Long-term Impact
- **Enhanced TDD8 Workflow**: Smoother red-green-refactor cycles
- **Improved Development Velocity**: Faster development through efficient testing
- **Better Code Quality**: More frequent testing leads to higher quality
- **Reduced Friction**: Seamless test execution removes development barriers
---
*This agent represents a specialized optimization approach focused on test execution efficiency and TDD8 workflow enhancement. By systematically addressing pytest reliability issues and optimizing test execution patterns, it aims to significantly improve development velocity and workflow smoothness.*