mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-11-23 21:59:14 +09:00
- Reorganize v3/ into implementation/ subfolders: - planning/, architecture/, migration/, integration/ - security/, adrs/, research/, swarm-plans/ - Add 15-agent concurrent swarm implementation plans: - SWARM-OVERVIEW.md: Hierarchical mesh topology, 4 phases - AGENT-SPECIFICATIONS.md: 15 agent configs with capabilities - TDD-LONDON-SCHOOL-PLAN.md: Mock-first TDD methodology - BENCHMARK-OPTIMIZATION.md: Performance targets (2.49x-7.47x) - DEPLOYMENT-PLAN.md: Release strategy, CI/CD, rollback - GITHUB-ISSUE-TRACKING.md: Issue workflow with agent replies - Update .claude/settings.json with proper hooks format - Add bash aliases for claude --dangerously-skip-permissions 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
10 KiB
10 KiB
Agent Swarm Benchmarking Tool - Testing Strategy
🧪 Test-Driven Development (TDD) Approach
TDD Cycle
- RED - Write a failing test
- GREEN - Write minimal code to pass the test
- REFACTOR - Improve code while keeping tests green
- 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
# 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
# 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
# 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
# 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
# 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
# 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
# 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
# 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.
# 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.
# 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.
# 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
# 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
# .pre-commit-config.yaml
repos:
- repo: local
hooks:
- id: pytest
name: pytest
entry: pytest
language: python
stages: [commit]
types: [python]
GitHub Actions
# .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
# 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
# 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.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
# 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.