This document describes the comprehensive test suite for Claude Code features, including unit tests, integration tests, safety tests, and security audits.
tests/
├── unit/ # Unit tests for individual components
│ ├── test_planning_agent.py # Planning Agent tests
│ ├── test_file_creator.py # File Creator tests
│ ├── test_command_executor.py # Command Executor tests
│ └── test_approval_system.py # Approval System tests
│
├── integration/ # Integration tests
│ ├── test_claude_code_workflows.py # End-to-end workflow tests
│ └── test_safety_mechanisms.py # Safety mechanism tests
│
└── security/ # Security audit tests
└── test_security_audit.py # Security tests
Unit tests verify individual components in isolation.
- Plan creation for different task types
- Task decomposition
- Complexity estimation
- Plan validation
- Circular dependency detection
- Plan execution with approval callbacks
- Progress tracking
Run:
pytest tests/unit/test_planning_agent.py -v- File creation, modification, deletion
- Diff generation and preview
- Directory structure creation
- Operation approval workflow
- Batch operations
- File type detection
Run:
pytest tests/unit/test_file_creator.py -v- Command classification (safe/risky/dangerous)
- Command execution with approval
- Error recovery and suggestions
- Streaming output
- Retry mechanisms
- Command history tracking
Run:
pytest tests/unit/test_command_executor.py -v- Approval workflows
- Batch approval
- Preference storage
- Undo point creation
- Rollback mechanisms
- Conflict detection
- File backup and restore
Run:
pytest tests/unit/test_approval_system.py -vIntegration tests verify component interactions and end-to-end workflows.
- Project creation workflow
- Refactoring workflow
- Error recovery workflow
- Component interaction
- Batch operations
- Complex multi-step workflows
Run:
pytest tests/integration/test_claude_code_workflows.py -v- Command blocking for dangerous operations
- File backup and restore
- Rollback mechanisms
- Permission handling
- Atomic operations
- Safety auditing
Run:
pytest tests/integration/test_safety_mechanisms.py -vSecurity tests audit the system for security vulnerabilities.
- Command execution security
- Path traversal prevention
- Input validation
- Permission handling
- Audit logging
- Security best practices
Run:
pytest tests/security/test_security_audit.py -vpytest tests/ -v# Unit tests only
pytest tests/unit/ -v
# Integration tests only
pytest tests/integration/ -v
# Security tests only
pytest tests/security/ -vpytest tests/unit/test_planning_agent.py -vpytest tests/unit/test_planning_agent.py::TestPlanningAgent::test_create_plan_project_creation -vpytest tests/ --cov=src/codegenie/core --cov-report=html# Run only async tests
pytest tests/ -m asyncio -v
# Skip slow tests
pytest tests/ -m "not slow" -v| Component | Unit Tests | Integration Tests | Security Tests |
|---|---|---|---|
| Planning Agent | ✓ | ✓ | - |
| File Creator | ✓ | ✓ | ✓ |
| Command Executor | ✓ | ✓ | ✓ |
| Approval System | ✓ | ✓ | ✓ |
- Overall Coverage: > 80%
- Core Components: > 90%
- Critical Paths: 100%
pip install pytest pytest-asyncio pytest-cov# Install project dependencies
pip install -r requirements.txt
# Install test dependencies
pip install -r requirements-test.txt # if existsimport pytest
class TestFeatureName:
"""Test suite for feature name."""
@pytest.fixture
def setup_fixture(self):
"""Set up test fixture."""
# Setup code
yield fixture_data
# Teardown code
def test_specific_behavior(self, setup_fixture):
"""Test specific behavior with clear description."""
# Arrange
input_data = setup_fixture
# Act
result = function_under_test(input_data)
# Assert
assert result.success
assert result.value == expected_value- Test Isolation: Each test should be independent
- Clear Names: Test names should describe what is being tested
- Arrange-Act-Assert: Follow AAA pattern
- Use Fixtures: Leverage pytest fixtures for setup/teardown
- Mock External Dependencies: Isolate the code under test
- Test Edge Cases: Include boundary conditions
- Document Complex Tests: Add comments for complex test logic
- ✓ Create plans for different task types
- ✓ Break down complex tasks
- ✓ Estimate complexity accurately
- ✓ Validate plans for errors
- ✓ Detect circular dependencies
- ✓ Execute plans with approval
- ✓ Track execution progress
- ✓ Create new files
- ✓ Modify existing files
- ✓ Delete files safely
- ✓ Generate diffs
- ✓ Create directory structures
- ✓ Handle approval workflows
- ✓ Batch operations
- ✓ Classify command risk levels
- ✓ Execute safe commands
- ✓ Block dangerous commands
- ✓ Handle command failures
- ✓ Provide error recovery
- ✓ Stream command output
- ✓ Retry failed commands
- ✓ Request approval
- ✓ Batch approval
- ✓ Store preferences
- ✓ Create undo points
- ✓ Rollback changes
- ✓ Detect conflicts
- ✓ Backup files
- ✓ Project creation workflow
- ✓ Refactoring workflow
- ✓ Error recovery workflow
- ✓ Component interaction
- ✓ Batch operations
- ✓ Complex multi-step workflows
- ✓ Command blocking
- ✓ File backup/restore
- ✓ Rollback mechanisms
- ✓ Permission handling
- ✓ Atomic operations
- ✓ Safety auditing
- ✓ Dangerous command detection
- ✓ Command injection prevention
- ✓ Timeout enforcement
- ✓ Environment isolation
- ✓ Sudo command detection
- ✓ Path traversal prevention
- ✓ Symlink handling
- ✓ Permission preservation
- ✓ Overwrite prevention
- ✓ Backup before destruction
- ✓ Approval for high-risk operations
- ✓ Preference storage security
- ✓ Undo history access control
- ✓ File path validation
- ✓ Content validation
- ✓ Command string validation
- ✓ Null byte injection prevention
name: Test Suite
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.12'
- name: Install dependencies
run: |
pip install -r requirements.txt
pip install pytest pytest-asyncio pytest-cov
- name: Run tests
run: pytest tests/ -v --cov=src/codegenie/core
- name: Upload coverage
uses: codecov/codecov-action@v2Import Errors
# Ensure project is installed in development mode
pip install -e .Async Test Failures
# Install pytest-asyncio
pip install pytest-asyncioPermission Errors
# Run tests with appropriate permissions
# Or use temporary directories for file operationsTimeout Errors
# Increase timeout for slow tests
pytest tests/ --timeout=300- Total Tests: 150+
- Unit Tests: 80+
- Integration Tests: 50+
- Security Tests: 20+
- Pass Rate: > 95%
- Unit Test Execution: < 30 seconds
- Integration Test Execution: < 2 minutes
- Full Test Suite: < 5 minutes
- Identify the component or feature to test
- Choose appropriate test category (unit/integration/security)
- Create test file following naming convention
- Write tests following best practices
- Run tests locally
- Submit pull request with tests
- Tests are independent and isolated
- Test names are descriptive
- Edge cases are covered
- Fixtures are used appropriately
- Tests pass locally
- Coverage is maintained or improved
- Documentation is updated
- Pytest Documentation
- Pytest-asyncio Documentation
- Python Testing Best Practices
- Test-Driven Development
This comprehensive test suite ensures the reliability, safety, and security of Claude Code features. The tests cover:
- Core Functionality: All major components are thoroughly tested
- Integration: Component interactions are verified
- Safety: Safety mechanisms are validated
- Security: Security vulnerabilities are audited
Regular execution of these tests helps maintain code quality and prevents regressions.