mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-11-24 22:28:10 +09:00
## 🔧 Critical Swarm System Fixes ### Fixed Task File Naming Bug - Tasks were being saved as '[object Object].json' due to TaskId object structure - Now properly extracts task ID string for file naming - Files save correctly as 'task_<id>.json' ### Added Task Timeout Protection - Implemented automatic timeout detection in task execution loop - Tasks that exceed timeout (default 5 minutes) are marked as failed - Prevents swarms from hanging indefinitely on stuck tasks - Agent state properly cleaned up on timeout ### Fixed Target Directory Propagation - Testing tasks were receiving null targetDir, preventing file access - Target directory now extracted from objective description - All tasks inherit targetDir through context - Enhanced extractTargetDirectory to check multiple sources ### Improved Task Dependencies - Fixed taskDependenciesMet to handle both string and TaskId objects - Added convertDependenciesToTaskDependencies for Map structure - Dependencies now properly resolve for sequential task execution ### Auto Strategy Integration - Added missing autoStrategy property and initialization - Proper AutoStrategy instantiation in coordinator constructor - Enables intelligent task decomposition for 'auto' strategy ## 📊 Added Comprehensive Benchmarks ### Benchmark Suite Integration - Added complete Python-based benchmarking tool - Tests 7 strategies across 5 coordination modes - 100% success rate across all test scenarios - Performance metrics: 0.10s - 0.20s execution times ### Real-World Performance Data - Calculator example: 4m 20s total (3 tasks) - Task breakdown: Analysis 29%, Implementation 22%, Testing 48% - Successfully created 6 files with proper directory structure ## 📝 Documentation Updates ### Updated README.md - Added v1.0.50 changelog with critical fixes - Integrated benchmark performance results table - Added real-world timing example - Removed old update notes for clarity - Added dedicated Benchmarks & Performance section ## 🧪 Test Results - Swarm now completes successfully with proper task coordination - All fixes validated in production environment - Task files save with correct names - Testing tasks find implementation files - Swarms exit cleanly after completion 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
398 lines
10 KiB
Markdown
398 lines
10 KiB
Markdown
# Agent Swarm Benchmarking Tool - Testing Strategy
|
|
|
|
## 🧪 Test-Driven Development (TDD) Approach
|
|
|
|
### TDD Cycle
|
|
1. **RED** - Write a failing test
|
|
2. **GREEN** - Write minimal code to pass the test
|
|
3. **REFACTOR** - Improve code while keeping tests green
|
|
4. **REPEAT** - Continue until feature is complete
|
|
|
|
### TDD Benefits
|
|
- Ensures code correctness from the start
|
|
- Provides living documentation
|
|
- Enables confident refactoring
|
|
- Catches regressions early
|
|
- Improves code design
|
|
|
|
## 📋 Testing Pyramid
|
|
|
|
```
|
|
▲
|
|
/ \
|
|
/ \
|
|
/ E2E \
|
|
/ \
|
|
/─────────\
|
|
/Integration\
|
|
/ \
|
|
/───────────────\
|
|
/ Unit \
|
|
/ \
|
|
/─────────────────────\
|
|
```
|
|
|
|
### Test Distribution
|
|
- **70% Unit Tests** - Fast, isolated, comprehensive
|
|
- **20% Integration Tests** - Component interactions
|
|
- **10% E2E Tests** - Complete workflows
|
|
|
|
## 🔬 Test Categories
|
|
|
|
### 1. Unit Tests (`tests/unit/`)
|
|
Test individual components in isolation.
|
|
|
|
#### Core Components
|
|
```python
|
|
# tests/unit/core/test_benchmark_engine.py
|
|
def test_benchmark_engine_initialization():
|
|
engine = BenchmarkEngine()
|
|
assert engine.status == EngineStatus.READY
|
|
assert engine.task_queue.is_empty()
|
|
|
|
def test_benchmark_engine_task_submission():
|
|
engine = BenchmarkEngine()
|
|
task = Task(id="1", objective="test", strategy="auto")
|
|
engine.submit_task(task)
|
|
assert len(engine.task_queue) == 1
|
|
```
|
|
|
|
#### Strategy Tests
|
|
```python
|
|
# tests/unit/strategies/test_auto_strategy.py
|
|
def test_auto_strategy_selection():
|
|
strategy = AutoStrategy()
|
|
task = Task(objective="analyze data", parameters={})
|
|
selected = strategy.select_strategy(task)
|
|
assert selected == "analysis"
|
|
|
|
def test_auto_strategy_execution():
|
|
strategy = AutoStrategy()
|
|
task = create_test_task()
|
|
result = await strategy.execute(task)
|
|
assert result.status == ResultStatus.SUCCESS
|
|
```
|
|
|
|
#### Coordination Mode Tests
|
|
```python
|
|
# tests/unit/modes/test_centralized_mode.py
|
|
def test_centralized_mode_agent_assignment():
|
|
mode = CentralizedMode()
|
|
agents = create_test_agents(5)
|
|
tasks = create_test_tasks(10)
|
|
assignments = mode.assign_tasks(agents, tasks)
|
|
assert len(assignments) == 10
|
|
```
|
|
|
|
### 2. Integration Tests (`tests/integration/`)
|
|
Test component interactions and data flow.
|
|
|
|
#### Strategy-Mode Integration
|
|
```python
|
|
# tests/integration/test_strategy_mode_integration.py
|
|
async def test_research_strategy_with_distributed_mode():
|
|
strategy = ResearchStrategy()
|
|
mode = DistributedMode()
|
|
task = create_research_task()
|
|
|
|
result = await mode.execute_with_strategy(strategy, task)
|
|
assert result.status == ResultStatus.SUCCESS
|
|
assert result.coordination_metrics["overhead"] < 0.1
|
|
```
|
|
|
|
#### Output Integration
|
|
```python
|
|
# tests/integration/test_output_integration.py
|
|
def test_json_sqlite_consistency():
|
|
results = create_test_results()
|
|
|
|
json_writer = JSONWriter()
|
|
sqlite_manager = SQLiteManager()
|
|
|
|
json_data = json_writer.export(results)
|
|
sqlite_manager.store(results)
|
|
|
|
sqlite_data = sqlite_manager.query_all()
|
|
assert normalize_data(json_data) == normalize_data(sqlite_data)
|
|
```
|
|
|
|
### 3. Performance Tests (`tests/performance/`)
|
|
Validate system performance under various conditions.
|
|
|
|
#### Load Testing
|
|
```python
|
|
# tests/performance/test_load_handling.py
|
|
async def test_high_task_volume():
|
|
engine = BenchmarkEngine()
|
|
tasks = create_test_tasks(1000)
|
|
|
|
start_time = time.time()
|
|
results = await engine.execute_batch(tasks)
|
|
execution_time = time.time() - start_time
|
|
|
|
assert len(results) == 1000
|
|
assert execution_time < 60 # Should complete within 1 minute
|
|
assert all(r.status == ResultStatus.SUCCESS for r in results)
|
|
```
|
|
|
|
#### Stress Testing
|
|
```python
|
|
# tests/performance/test_resource_limits.py
|
|
def test_memory_usage_under_load():
|
|
with resource_monitor() as monitor:
|
|
engine = BenchmarkEngine()
|
|
tasks = create_memory_intensive_tasks(100)
|
|
engine.execute_batch(tasks)
|
|
|
|
assert monitor.peak_memory < 1024 * 1024 * 1024 # < 1GB
|
|
```
|
|
|
|
### 4. End-to-End Tests (`tests/e2e/`)
|
|
Test complete user workflows through the CLI.
|
|
|
|
#### CLI Workflow Tests
|
|
```python
|
|
# tests/e2e/test_cli_workflows.py
|
|
def test_complete_benchmark_workflow():
|
|
# Execute via CLI
|
|
result = subprocess.run([
|
|
"python", "-m", "swarm_benchmark",
|
|
"run", "test-benchmark",
|
|
"--strategy", "research",
|
|
"--mode", "distributed",
|
|
"--output", "json,sqlite"
|
|
], capture_output=True, text=True)
|
|
|
|
assert result.returncode == 0
|
|
assert "Benchmark completed successfully" in result.stdout
|
|
|
|
# Verify outputs exist
|
|
assert os.path.exists("reports/test-benchmark.json")
|
|
assert os.path.exists("reports/test-benchmark.db")
|
|
```
|
|
|
|
## 🛠️ Test Infrastructure
|
|
|
|
### Test Fixtures (`tests/fixtures/`)
|
|
Reusable test data and objects.
|
|
|
|
```python
|
|
# tests/fixtures/tasks.py
|
|
def create_test_task(**kwargs):
|
|
defaults = {
|
|
"id": str(uuid.uuid4()),
|
|
"objective": "test objective",
|
|
"strategy": "auto",
|
|
"mode": "centralized",
|
|
"timeout": 60,
|
|
"max_retries": 3
|
|
}
|
|
defaults.update(kwargs)
|
|
return Task(**defaults)
|
|
|
|
def create_test_tasks(count: int) -> List[Task]:
|
|
return [create_test_task(id=str(i)) for i in range(count)]
|
|
```
|
|
|
|
### Mock Objects (`tests/mocks/`)
|
|
Mock external dependencies for isolated testing.
|
|
|
|
```python
|
|
# tests/mocks/claude_flow_client.py
|
|
class MockClaudeFlowClient:
|
|
def __init__(self):
|
|
self.calls = []
|
|
|
|
async def execute_swarm(self, objective: str, **kwargs):
|
|
self.calls.append(("execute_swarm", objective, kwargs))
|
|
return MockResult(success=True, output="mock output")
|
|
```
|
|
|
|
### Test Utilities (`tests/utils/`)
|
|
Helper functions for testing.
|
|
|
|
```python
|
|
# tests/utils/assertions.py
|
|
def assert_result_valid(result: Result):
|
|
assert result.task_id is not None
|
|
assert result.status in [ResultStatus.SUCCESS, ResultStatus.FAILURE]
|
|
assert result.execution_time >= 0
|
|
assert isinstance(result.metrics, dict)
|
|
|
|
def assert_metrics_complete(metrics: Dict[str, Any]):
|
|
required_keys = ["execution_time", "resource_usage", "quality_score"]
|
|
for key in required_keys:
|
|
assert key in metrics
|
|
```
|
|
|
|
## 📊 Test Coverage Strategy
|
|
|
|
### Coverage Goals
|
|
- **Overall Coverage**: ≥ 95%
|
|
- **Unit Tests**: ≥ 98%
|
|
- **Integration Tests**: ≥ 90%
|
|
- **Critical Paths**: 100%
|
|
|
|
### Coverage Measurement
|
|
```bash
|
|
# Run tests with coverage
|
|
pytest --cov=src --cov-report=html --cov-report=term
|
|
|
|
# Coverage requirements in pytest.ini
|
|
[tool:pytest]
|
|
addopts = --cov=src --cov-fail-under=95
|
|
```
|
|
|
|
### Coverage Exclusions
|
|
- Configuration files
|
|
- CLI entry points
|
|
- Error handling for unreachable states
|
|
- Development/debug utilities
|
|
|
|
## 🔄 Continuous Testing
|
|
|
|
### Pre-commit Hooks
|
|
```yaml
|
|
# .pre-commit-config.yaml
|
|
repos:
|
|
- repo: local
|
|
hooks:
|
|
- id: pytest
|
|
name: pytest
|
|
entry: pytest
|
|
language: python
|
|
stages: [commit]
|
|
types: [python]
|
|
```
|
|
|
|
### GitHub Actions
|
|
```yaml
|
|
# .github/workflows/test.yml
|
|
name: Test Suite
|
|
on: [push, pull_request]
|
|
|
|
jobs:
|
|
test:
|
|
runs-on: ubuntu-latest
|
|
strategy:
|
|
matrix:
|
|
python-version: [3.8, 3.9, 3.10, 3.11]
|
|
|
|
steps:
|
|
- uses: actions/checkout@v2
|
|
- name: Set up Python
|
|
uses: actions/setup-python@v2
|
|
with:
|
|
python-version: ${{ matrix.python-version }}
|
|
- name: Install dependencies
|
|
run: |
|
|
pip install -r requirements.txt
|
|
pip install -r requirements-dev.txt
|
|
- name: Run tests
|
|
run: pytest --cov=src --cov-report=xml
|
|
- name: Upload coverage
|
|
uses: codecov/codecov-action@v1
|
|
```
|
|
|
|
## 🎯 Test Data Management
|
|
|
|
### Test Data Strategy
|
|
- **Synthetic Data** - Generated test data for consistency
|
|
- **Fixtures** - Predefined test scenarios
|
|
- **Factories** - Dynamic test data generation
|
|
- **Snapshots** - Golden master testing for outputs
|
|
|
|
### Data Generation
|
|
```python
|
|
# tests/data/generators.py
|
|
class TaskGenerator:
|
|
@staticmethod
|
|
def simple_task() -> Task:
|
|
return Task(
|
|
id="simple-001",
|
|
objective="Simple test task",
|
|
strategy="auto",
|
|
mode="centralized"
|
|
)
|
|
|
|
@staticmethod
|
|
def complex_workflow() -> List[Task]:
|
|
return [
|
|
Task(id=f"complex-{i}", objective=f"Step {i}")
|
|
for i in range(10)
|
|
]
|
|
```
|
|
|
|
## 🚨 Test Environment Setup
|
|
|
|
### Local Development
|
|
```bash
|
|
# Setup test environment
|
|
python -m venv venv
|
|
source venv/bin/activate
|
|
pip install -r requirements-dev.txt
|
|
|
|
# Run tests
|
|
pytest
|
|
|
|
# Run with coverage
|
|
pytest --cov=src
|
|
|
|
# Run specific test category
|
|
pytest tests/unit/
|
|
pytest tests/integration/
|
|
pytest tests/performance/
|
|
```
|
|
|
|
### Docker Testing
|
|
```dockerfile
|
|
# Dockerfile.test
|
|
FROM python:3.9-slim
|
|
|
|
WORKDIR /app
|
|
COPY requirements*.txt ./
|
|
RUN pip install -r requirements-dev.txt
|
|
|
|
COPY . .
|
|
CMD ["pytest", "--cov=src", "--cov-report=html"]
|
|
```
|
|
|
|
## 📈 Test Metrics and Reporting
|
|
|
|
### Key Metrics
|
|
- **Test Coverage** - Code coverage percentage
|
|
- **Test Execution Time** - Performance of test suite
|
|
- **Test Reliability** - Flaky test detection
|
|
- **Bug Detection** - Tests catching real issues
|
|
|
|
### Reporting Tools
|
|
- **Coverage.py** - Code coverage measurement
|
|
- **pytest-html** - HTML test reports
|
|
- **pytest-benchmark** - Performance benchmarking
|
|
- **allure-pytest** - Advanced test reporting
|
|
|
|
## 🔍 Test Quality Assurance
|
|
|
|
### Test Review Checklist
|
|
- [ ] Tests follow naming conventions
|
|
- [ ] Tests are independent and isolated
|
|
- [ ] Tests have clear assertions
|
|
- [ ] Tests cover edge cases
|
|
- [ ] Tests are maintainable
|
|
- [ ] Tests execute quickly
|
|
- [ ] Tests are deterministic
|
|
|
|
### Code Quality Tools
|
|
```bash
|
|
# Linting
|
|
flake8 tests/
|
|
pylint tests/
|
|
|
|
# Type checking
|
|
mypy tests/
|
|
|
|
# Security scanning
|
|
bandit -r tests/
|
|
```
|
|
|
|
This comprehensive testing strategy ensures robust, reliable, and maintainable code through systematic test-driven development practices. |