Comprehensive integration and end-to-end tests for Summary Bot NG, validating complete workflows and cross-component interactions.
Integration tests verify real component interactions with mocked external APIs.
Purpose: Test full Discord command flow from interaction to response
Coverage:
- Bot initialization with real service container
- Command registration and execution
- Full summarize command flow (interaction → handler → engine → response)
- Error propagation through layers
- Permission checking in command flow
- Concurrent command execution
Key Tests:
test_bot_initialization_with_real_container()
test_command_registration_flow()
test_full_summarize_command_flow()
test_error_propagation_through_layers()
test_permission_check_integration()
test_concurrent_command_execution()
test_cost_estimation_integration()Test Approach:
- Uses real
ServiceContainerwith mockedClaudeClient - Mocks Discord API but uses real bot components
- Tests complete message flow with actual processing logic
Purpose: Test full API request flow through webhook service
Coverage:
- Health check and root endpoints
- Complete API request flow (request → auth → handler → engine → response)
- Authentication and authorization
- Rate limiting enforcement
- Concurrent API request handling
- CORS and compression middleware
- Error handling and recovery
Key Tests:
test_health_check_endpoint()
test_root_endpoint()
test_full_api_request_flow()
test_authentication_required()
test_rate_limiting_enforcement()
test_concurrent_api_requests()
test_error_handling_in_api()
test_cors_headers()Test Approach:
- Uses
AsyncClientfor async HTTP testing - Real FastAPI app with mocked Claude API
- Tests middleware stack integration
Purpose: Test repository operations with real database
Coverage:
- Create and retrieve operations
- Transaction handling and rollback
- Concurrent database access
- Query operations (by channel, by guild, etc.)
- Update and delete operations
- Schema creation and migrations
Key Tests:
test_create_and_retrieve_summary()
test_transaction_rollback()
test_concurrent_database_access()
test_query_summaries_by_channel()
test_update_summary()
test_delete_summary()
test_migration_execution()Test Approach:
- Uses in-memory SQLite for fast, isolated testing
- Tests real SQLAlchemy async operations
- Validates concurrent access patterns
E2E tests validate complete workflows across all system components.
Purpose: Test complete summarization workflows from trigger to response
Test Classes:
TestDiscordSummarizationWorkflow:
- Complete Discord user flow:
/summarize→ fetch → process → store → respond - Error recovery scenarios
- Scheduled summary workflow
TestWebhookSummarizationWorkflow:
- Webhook-triggered summary flow
- API request → authentication → processing → storage → response
TestCrossComponentWorkflow:
- Bot and webhook service coexistence
- System-wide health checks
Key Scenarios:
test_complete_discord_summarization_flow()
test_error_recovery_workflow()
test_scheduled_summary_workflow()
test_webhook_triggered_summary_workflow()
test_bot_and_webhook_coexistence()
test_system_health_checks()Purpose: Test complete system integration with all services running
Coverage:
- System startup and initialization
- Shared service access between components
- Concurrent bot and webhook operations
- Health check endpoints
- Graceful shutdown
- Error isolation
- Resource cleanup
- Performance under load
- Memory usage
Key Tests:
test_system_startup()
test_shared_service_access()
test_concurrent_bot_and_webhook_operations()
test_system_health_check_endpoint()
test_graceful_shutdown()
test_error_isolation()
test_resource_cleanup_on_error()
test_sustained_load()
test_memory_usage()Shared Fixtures (conftest.py):
mock_config: Complete bot configurationintegration_service_container: Real container with mocked external APIsintegration_bot: Configured bot instanceintegration_webhook_server: Webhook server instancereal_test_database: In-memory database for testinge2e_full_system: Complete system setup
Class-Level Fixtures:
- Test-specific setup with proper async handling
- Automatic cleanup via context managers
- Isolated test environments
Mock External APIs Only:
- Discord API (network calls)
- Claude API (AI service)
- External webhooks
Use Real Components:
- Service container
- Summarization engine
- Command handlers
- Message processors
- Database operations (with in-memory SQLite)
All async tests use pytest_asyncio:
@pytest_asyncio.fixture
async def my_fixture():
# Setup
yield resource
# Cleanup
@pytest.mark.asyncio
async def test_async_operation():
result = await some_async_function()
assert result is not Nonepytest tests/integration/ -vpytest tests/integration/test_discord_integration.py -vpytest tests/e2e/ -v -k "not slow"pytest tests/integration/ tests/e2e/ --cov=src --cov-report=htmlpytest -m integration -vpytest -m e2e -v@pytest.mark.integration: Integration tests@pytest.mark.e2e: End-to-end tests@pytest.mark.slow: Long-running tests@pytest.mark.asyncio: Async tests
Each test should be completely independent:
@pytest_asyncio.fixture
async def isolated_container(mock_config):
container = ServiceContainer(mock_config)
await container.initialize()
yield container
await container.cleanup() # Always cleanupUse descriptive test names that explain what and why:
def test_full_summarize_command_flow():
"""Test complete summarize command flow from interaction to response."""Structure tests clearly:
async def test_example():
# Arrange
container = ServiceContainer(config)
# Act
result = await container.summarization_engine.summarize_messages(...)
# Assert
assert result.summary_text is not NoneEach test should verify one specific behavior:
# Good
async def test_permission_check_integration():
"""Test permission checking in command flow."""
# Test only permission checking
# Bad - tests multiple things
async def test_everything():
# Tests permissions, summaries, database, etc.- Target: < 5 seconds per test
- Use in-memory databases
- Mock slow external APIs
- Limit message batch sizes
- Target: < 30 seconds per test
- Mark slow tests with
@pytest.mark.slow - Use appropriate timeouts
- Clean up resources properly
1. Async Fixture Warnings
# Wrong
@pytest.fixture
async def my_fixture():
...
# Right
@pytest_asyncio.fixture
async def my_fixture():
...2. Resource Leaks Always cleanup in fixtures:
@pytest_asyncio.fixture
async def resource():
r = await create_resource()
yield r
await r.cleanup() # Critical!3. Test Isolation Use fresh instances per test:
@pytest_asyncio.fixture
async def fresh_container(mock_config):
# New container each test
container = ServiceContainer(mock_config)
await container.initialize()
yield container
await container.cleanup()- Integration Tests: 80%+ coverage of service layer
- E2E Tests: Validate all critical user workflows
- Overall: 85%+ code coverage across test suite
- Performance Benchmarks: Add performance regression tests
- Load Testing: Validate system under high concurrency
- Chaos Testing: Test system resilience to failures
- Contract Testing: API contract validation
- Visual Regression: For any UI components
/tests/unit/: Unit test documentation/tests/performance/: Performance test documentation/tests/security/: Security test documentationTEST_RESULTS.md: Comprehensive test results and analysis