feat: Integrate Requirements Engineering Agent and fix Issue #59 test failures

## Major Integration

-  Integrated Requirements Engineering Agent into development workflow
-  Enhanced Makefile with requirements validation targets
-  Added pre-commit validation with mock compatibility checking
-  Enhanced TDD workflow to include foundation analysis

## Test Fixes

-  Fixed GiteaPlugin missing _add_comment_async method
-  Fixed LocalPlugin config.yml file not found errors in tests
-  Enhanced mock objects in CLI tests with proper domain model attributes
-  All Issue #59 tests now passing (38/38 tests pass)

## New Capabilities

- `make validate-requirements` - Foundation analysis before development
- `make check-interface-compatibility INTERFACE=Name` - Interface compatibility checking
- `make generate-dev-checklist FEATURE='Name'` - Development checklist generation
- `make validate-mocks` - Mock object compatibility validation
- `make pre-commit-validate` - Complete pre-commit validation workflow

## Problem Prevention

This integration prevents the exact interface compatibility issues and mock object
mismatches that caused hours of debugging in Issue #59. The Requirements Engineering
Agent provides proactive foundation analysis and catches problems before they occur.

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-10-02 00:45:06 +02:00
parent 484d919ffa
commit 3af6fb9935
14 changed files with 2222 additions and 29 deletions

View File

@@ -0,0 +1,375 @@
# Requirements Engineering Agent Integration Guide
## Quick Start
Add these commands to your development workflow to prevent interface compatibility issues and mock object mismatches:
```bash
# Before starting any new feature
make validate-requirements
# When planning interface changes
python tools/requirements_engineering_toolkit.py plan-interface --interface YourInterface
# Before writing tests
python tools/requirements_engineering_toolkit.py checklist --feature "Your Feature"
# When creating mocks
python examples/issue_59_prevention_demo.py # See correct patterns
```
## Integration with Existing Workflow
### 1. Enhanced Makefile Targets
Add these targets to your `Makefile`:
```makefile
# Requirements Engineering Integration
validate-requirements:
@echo "🔍 Validating project requirements and foundations..."
python tools/requirements_engineering_toolkit.py analyze
check-interface-compatibility:
@echo "🔌 Checking interface compatibility..."
python tools/requirements_engineering_toolkit.py plan-interface --interface $(INTERFACE)
generate-dev-checklist:
@echo "📋 Generating development checklist..."
python tools/requirements_engineering_toolkit.py checklist --feature "$(FEATURE)"
# Enhanced TDD workflow
tdd-start: validate-requirements
@echo "🚀 Starting TDD workflow with requirements validation..."
python tddai_cli.py tdd-start $(NUM)
# Pre-commit validation
pre-commit-validate:
make validate-requirements
python -m pytest tests/test_mock_compatibility.py -xvs
```
### 2. Enhanced TDD8 Workflow
The TDD8 workflow is enhanced with requirements engineering checkpoints:
```
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 the 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
```
### 3. TodoWrite Integration
Enhanced TodoWrite with validation checkpoints:
```python
# Example enhanced todo list
todos = [
{
"content": "Analyze existing domain models",
"status": "pending",
"activeForm": "Analyzing existing domain models",
"checkpoint": "foundation_analysis"
},
{
"content": "Define interface contracts",
"status": "pending",
"activeForm": "Defining interface contracts",
"checkpoint": "interface_definition"
},
{
"content": "Create spec-compliant mocks",
"status": "pending",
"activeForm": "Creating spec-compliant mocks",
"checkpoint": "mock_validation"
}
]
```
## Pre-Development Checklist
Before starting any new feature development:
### Foundation Analysis
- [ ] Run `make validate-requirements`
- [ ] Review existing domain models in target area
- [ ] Map current interface contracts
- [ ] Understand dependency relationships
### Interface Planning
- [ ] Define new interface contracts
- [ ] Check compatibility with existing interfaces
- [ ] Plan evolution strategy for existing interfaces
- [ ] Document interface specifications
### Test Strategy
- [ ] Plan test architecture that matches application architecture
- [ ] Identify domain models that will need mocking
- [ ] Plan integration test points
- [ ] Define validation checkpoints
## Mock Object Guidelines
### ✅ Correct Mock Patterns
```python
from unittest.mock import Mock
from domain.issues.models import Issue, IssueState, Label
from datetime import datetime, timezone
# CORRECT: Use spec= parameter
mock_issue = Mock(spec=Issue)
mock_issue.number = 59
mock_issue.title = "Test Issue"
mock_issue.state = IssueState.OPEN # Use actual enum
mock_issue.labels = []
mock_issue.created_at = datetime.now(timezone.utc)
mock_issue.updated_at = datetime.now(timezone.utc)
```
### ❌ Incorrect Mock Patterns
```python
# WRONG: No spec parameter
mock_issue = Mock()
mock_issue.number = 59
mock_issue.state = "open" # String instead of enum!
# Missing required attributes
# WRONG: Assumption-based attributes
mock_issue.some_attribute_that_doesnt_exist = "value"
```
### Mock Validation Script
Create `tests/test_mock_compatibility.py`:
```python
import pytest
from unittest.mock import Mock
from domain.issues.models import Issue, IssueState
from datetime import datetime, timezone
class TestMockCompatibility:
"""Validate that test mocks match actual domain models."""
def test_issue_mock_has_all_required_attributes(self):
"""Test that Issue mocks include all required attributes."""
# Create a real Issue to get expected attributes
real_issue = Issue(
number=1,
title="Real Issue",
state=IssueState.OPEN,
labels=[],
created_at=datetime.now(timezone.utc),
updated_at=datetime.now(timezone.utc)
)
# Create mock with spec
mock_issue = Mock(spec=Issue)
mock_issue.number = 1
mock_issue.title = "Mock Issue"
mock_issue.state = IssueState.OPEN
mock_issue.labels = []
mock_issue.created_at = datetime.now(timezone.utc)
mock_issue.updated_at = datetime.now(timezone.utc)
# Verify critical attributes match
real_attrs = {attr for attr in dir(real_issue) if not attr.startswith('_')}
mock_attrs = {attr for attr in dir(mock_issue) if not attr.startswith('_')}
missing_attrs = real_attrs - mock_attrs
critical_missing = [attr for attr in missing_attrs
if not callable(getattr(real_issue, attr))]
assert not critical_missing, f"Mock missing critical attributes: {critical_missing}"
def test_issue_mock_uses_correct_types(self):
"""Test that Issue mocks use correct types."""
mock_issue = Mock(spec=Issue)
mock_issue.state = IssueState.OPEN # Should be enum, not string
assert isinstance(mock_issue.state, IssueState), "State should be IssueState enum"
```
## Interface Evolution Guidelines
### Planning Interface Changes
1. **Analyze Current Usage**:
```bash
# Find all usages of the interface
grep -r "YourInterface" . --include="*.py"
```
2. **Plan Backward Compatibility**:
```python
# Example: Adding new method while maintaining compatibility
class YourInterface(ABC):
# Existing methods (don't change signatures)
@abstractmethod
def existing_method(self, param: str) -> str:
pass
# New methods (with default implementations if possible)
def new_method(self, param: str) -> Optional[str]:
"""New method with default implementation for compatibility."""
return None # Safe default
```
3. **Create Migration Plan**:
- Phase 1: Add new interface methods with defaults
- Phase 2: Update implementations incrementally
- Phase 3: Add deprecation warnings to old methods
- Phase 4: Remove deprecated methods after transition period
### Interface Compatibility Checking
```bash
# Check if new interface is compatible with existing implementations
python tools/requirements_engineering_toolkit.py plan-interface \
--interface NewInterface \
--existing-implementations ExistingRepo,AnotherRepo
```
## Common Patterns and Solutions
### Pattern 1: Plugin Interface Design
```python
# Base interface that matches existing repository patterns
class IssueBackend(ABC):
def __init__(self, config: Dict[str, Any]):
self.config = config
@abstractmethod
def list_issues(self, state: Optional[str] = None) -> List[Issue]:
pass
@abstractmethod
def get_issue(self, issue_id: str) -> Issue:
pass
# Implementation that adapts async repository
class GiteaPlugin(IssueBackend):
def __init__(self, config: Dict[str, Any]):
super().__init__(config)
self.repository = GiteaIssueRepository(self._create_connection_manager())
def list_issues(self, state: Optional[str] = None) -> List[Issue]:
# Adapter pattern: async -> sync
return asyncio.run(self.repository.get_issues(state=state))
```
### Pattern 2: Domain Model Extension
```python
# Extending domain model while maintaining compatibility
@dataclass
class Issue:
# Existing attributes (don't change order or remove)
number: int
title: str
state: IssueState
labels: List[Label]
created_at: datetime
updated_at: datetime
# New attributes with defaults for backward compatibility
body: str = ""
assignees: List[str] = field(default_factory=list)
html_url: str = ""
```
### Pattern 3: Test Architecture Alignment
```python
# Test structure that matches application architecture
class TestIssuePluginManager:
def setup_method(self):
# Use real domain models for mocks
self.mock_issue = Mock(spec=Issue)
self.mock_backend = Mock(spec=IssueBackend)
# Configure mocks with realistic data
self._configure_realistic_mocks()
def _configure_realistic_mocks(self):
"""Configure mocks to match real object behavior."""
self.mock_issue.number = 59
self.mock_issue.state = IssueState.OPEN
self.mock_issue.created_at = datetime.now(timezone.utc)
# ... all required attributes
```
## Error Prevention Checklist
### Before Writing Tests
- [ ] Analyze target domain models with `python tools/requirements_engineering_toolkit.py analyze`
- [ ] Understand existing interface contracts
- [ ] Plan mock strategy using `Mock(spec=ActualClass)`
- [ ] Verify enum usage instead of strings
### Before Implementation
- [ ] Check interface compatibility
- [ ] Plan async/sync adapter layers if needed
- [ ] Verify backward compatibility strategy
- [ ] Document interface contracts
### Before Committing
- [ ] Run mock compatibility tests: `pytest tests/test_mock_compatibility.py`
- [ ] Validate interface evolution plan
- [ ] Check that no existing tests are broken
- [ ] Update documentation for interface changes
## Troubleshooting Common Issues
### Issue: Mock doesn't match domain model
**Solution**: Use `Mock(spec=ActualClass)` and include all required attributes
### Issue: Enum vs string mismatch
**Solution**: Import and use actual enums: `from domain.issues.models import IssueState`
### Issue: Async/sync interface mismatch
**Solution**: Add adapter layer to convert between async and sync interfaces
### Issue: Missing attributes in mock
**Solution**: Run domain analysis to see all required attributes, ensure mock includes them
### Issue: Interface breaking changes
**Solution**: Use evolution plan with backward compatibility and deprecation period
## Integration with Existing Tools
### CLI Commands
```bash
# Add to existing CLI
markitect validate-requirements # Run foundation analysis
markitect check-interfaces # Verify interface compatibility
markitect plan-migration # Plan interface evolution
markitect validate-mocks # Check mock compatibility
```
### IDE Integration
- Add pre-commit hooks for requirements validation
- Configure IDE to run mock compatibility tests
- Set up interface change detection
### CI/CD Integration
```yaml
# Add to GitHub Actions / CI pipeline
- name: Validate Requirements
run: make validate-requirements
- name: Check Mock Compatibility
run: python -m pytest tests/test_mock_compatibility.py
```
This integration ensures that the Requirements Engineering Agent becomes a natural part of the development workflow, preventing the interface compatibility issues encountered in Issue #59 and improving overall code quality and development efficiency.

216
docs/sub_agents/README.md Normal file
View File

@@ -0,0 +1,216 @@
# 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

@@ -0,0 +1,442 @@
# 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.