This document describes the test suite and coverage for ChatrixCD.
# Install test dependencies
pip install pytest pytest-cov pytest-asyncio
# Run all tests
pytest tests/
# Run with verbose output
pytest tests/ -v# Run tests with coverage report
pytest tests/ --cov=chatrixcd --cov-report=term-missing
# Generate HTML coverage report
pytest tests/ --cov=chatrixcd --cov-report=html
# Open htmlcov/index.html in a browser| Module | Coverage | Lines | Tested | Description |
|---|---|---|---|---|
__init__.py |
100% | 1 | 1 | Package initialization |
config.py |
71% | 200 | 142 | Configuration management |
auth.py |
100% | 22 | 22 | Authentication (password, OIDC) |
semaphore.py |
68% | 143 | 97 | Semaphore API client |
bot.py |
52% | 537 | 281 | Matrix bot core and lifecycle |
commands.py |
55% | 704 | 384 | Command handlers |
main.py |
23% | 294 | 67 | Entry point (E2E tests added!) |
verification.py |
56% | 235 | 132 | Device verification |
messages.py |
69% | 88 | 61 | Message templates |
redactor.py |
93% | 69 | 64 | Sensitive information redaction |
aliases.py |
71% | 111 | 79 | Command aliases |
- Total Tests: 433
- Configuration Tests: 18
- Authentication Tests: 10
- Bot Tests: 17
- CLI Tests: 10
- Command Handler Tests: 38
- Semaphore Client Tests: 19
- Verification Tests: 19
- Verification E2E Tests: 20
- Message Tests: 10
- Aliases Tests: 14
- TUI Tests: 134 (⬆️ increased from 40!)
- Unit Tests: 40 (component creation and imports)
- Regular TUI Pilot Core Tests: 44 (main app, screens, widgets)
- Regular TUI Pilot Interactive Tests: 17 (workflows, navigation, error handling)
- Turbo TUI Pilot Tests: 33 (menu system, navigation, themes)
- Redactor Tests: 9
- Workflow Tests: 104
- Main Entry Point E2E Tests: 21
- Workflow E2E Tests: 14
- ✅ Default values loading
- ✅ Environment variable configuration
- ✅ JSON file configuration
- ✅ Fallback and default value handling
- ✅ Password authentication initialization
- ✅ OIDC authentication initialization
- ✅ Password retrieval
- ✅ Missing password handling
- ✅ Unknown auth type handling
- ✅ OIDC redirect URL configuration
- ✅ Configuration validation (password and OIDC)
- ✅ Client initialization
- ✅ URL trailing slash handling
- ✅ Session creation and cleanup
- ✅ Get projects (success, failure, exception)
- ✅ Get project templates (success, failure)
- ✅ Start task (success, failure, with options)
- ✅ Get task status (success, failure)
- ✅ Get task output/logs (success, failure)
- ✅ Stop task (success, failure, exception)
- ✅ Handler initialization
- ✅ Room permission checks (allowed_rooms)
- ✅ Admin permission checks (admin_users)
- ✅ Message filtering (command prefix, non-commands)
- ✅ Help command
- ✅ List projects (success, empty)
- ✅ List templates (success, empty, invalid args)
- ✅ Run task (success, failure, validation)
- ✅ Check task status
- ✅ Stop task
- ✅ Get task logs (including truncation)
- ✅ Unknown command handling
- ✅ Callback registration
- ✅ Message filtering (own messages)
- ✅ Decryption failure handling
- ✅ Login validation (user_id checks)
- ✅ Encryption store loading
- ✅ Startup messages (enabled/disabled)
- ✅ Shutdown messages (enabled/disabled)
- ✅ Room invite handling
- ✅ Message sending (plain text, HTML formatted)
Comprehensive E2E tests have been added for:
- ✅ CLI argument parsing (--version, --help, flags)
- ✅ Configuration file loading and validation
- ✅ Show-config mode with output verification
- ✅ Verbose logging levels
- ✅ Color and redaction flags
- ✅ Admin users and allowed rooms flags
- ✅ Combined flag scenarios
- ✅ Error handling and user feedback
- ✅ Configuration wizard flow
- ✅ Multi-step command sequences
- ✅ Configuration migration scenarios
- ✅ Output formatting verification
- ✅ Error message clarity
- ✅ First-time user workflows
New Comprehensive Pilot Tests (61 tests added!)
Using Textual's pilot feature for automated TUI testing:
- ✅ Main app startup and rendering
- ✅ Main menu button rendering and functionality
- ✅ All keyboard bindings (q, s, a, r, e, m, l, t, c, x)
- ✅ Theme application and switching
- ✅ Default theme
- ✅ Midnight theme
- ✅ Grayscale theme
- ✅ Windows 3.1 theme
- ✅ MS-DOS theme
- ✅ Invalid theme fallback
- ✅ Screen navigation
- ✅ AdminsScreen display and navigation
- ✅ RoomsScreen display and navigation
- ✅ SessionsScreen display
- ✅ SayScreen display
- ✅ LogScreen display
- ✅ SetScreen display
- ✅ ShowScreen display
- ✅ AliasesScreen display and navigation
- ✅ OIDCAuthScreen display and special character handling
- ✅ MessageScreen display and closing
- ✅ Widget functionality
- ✅ BotStatusWidget rendering and updates
- ✅ ActiveTasksWidget rendering and task display
-
✅ Alias management workflows
- ✅ Alias screen button selection
- ✅ Keyboard navigation (b, escape)
-
✅ Multi-screen navigation
- ✅ Multiple screen navigation sequence
- ✅ Rapid navigation stress testing
- ✅ Screen stack integrity verification
-
✅ Theme system validation
- ✅ All themes render correctly
- ✅ CSS variable completeness
-
✅ Widget updates
- ✅ Active tasks widget dynamic updates
- ✅ Bot status widget reactive updates
-
✅ Error handling
- ✅ Graceful handling of missing bot
- ✅ Graceful handling of missing Matrix client
-
✅ Keyboard shortcuts
- ✅ All shortcuts trigger correct actions
- ✅ Quit shortcuts functionality
-
✅ Application lifecycle
- ✅ App startup validation
- ✅ Metrics initialization
- ✅ Login task handling
-
✅ Main app startup and rendering
-
✅ Menu bar and status bar rendering
-
✅ F-key bindings (F1-F4) for menu navigation
-
✅ Arrow key navigation (left/right menu cycling)
-
✅ Theme application and validation
- ✅ Default theme
- ✅ Midnight theme
- ✅ Grayscale theme
- ✅ Windows 3.1 theme
- ✅ MS-DOS theme
- ✅ Invalid theme fallback
-
✅ Menu screen navigation
- ✅ FileMenuScreen display
- ✅ EditMenuScreen display
- ✅ RunMenuScreen display
- ✅ HelpMenuScreen display
- ✅ Escape key navigation
-
✅ Multi-menu navigation workflows
-
✅ Rapid menu navigation stress testing
-
✅ Menu cycling with arrow keys
-
✅ Active tasks widget integration
-
✅ Status bar updates
-
✅ Error handling
- ✅ Graceful handling of missing bot
- ✅ Graceful handling of missing Matrix client
-
✅ Application lifecycle
- ✅ App startup validation
- ✅ Metrics initialization
- ✅ Login task handling
- ✅ Menu navigation state tracking
- ✅ Component creation and imports
- ✅ CSS compatibility across themes
- ✅ Menu screen functionality
- ✅ OIDC authentication screens
- ✅ CLI integration
The following areas require integration testing with live services:
- Matrix client connection
- Room joining and sync
- Message sending and receiving
- Encryption handling
- Event callbacks
- Command parsing
- Project listing
- Template listing
- Task execution
- Task monitoring
- Status reporting
- Error handling
- Application startup
- Configuration loading
- Signal handling
- Graceful shutdown
# Quick test
pytest tests/
# Full test with coverage
pytest tests/ --cov=chatrixcd --cov-report=term-missingWhen adding new functionality:
- Write tests first (TDD approach when possible)
- Test edge cases: Empty inputs, None values, errors
- Mock external dependencies: Matrix servers, Semaphore API
- Use descriptive test names:
test_<what>_<condition>_<expected> - Keep tests isolated: Each test should be independent
tests/
├── __init__.py
├── test_config.py # Configuration tests
├── test_auth.py # Authentication tests
├── test_semaphore.py # Semaphore client tests
├── test_bot.py # Bot tests
├── test_commands.py # Command handler tests
├── test_messages.py # Message template tests
├── test_aliases.py # Command aliases tests
├── test_redactor.py # Sensitive info redaction tests
├── test_verification.py # Device verification tests
├── test_verification_e2e.py # Verification E2E tests
├── test_tui.py # TUI unit tests
├── test_tui_menu_fixes.py # TUI menu tests
├── test_tui_navigation.py # TUI navigation tests
├── test_tui_pilot.py # Regular TUI pilot tests (NEW! 44 tests)
├── test_tui_pilot_interactive.py # Regular TUI interactive workflow tests (NEW! 17 tests)
├── test_cli.py # CLI argument tests
├── test_workflow.py # GitHub workflow tests
├── test_e2e_main.py # Main entry point E2E tests
└── test_e2e_workflow.py # Workflow E2E tests
Tests run automatically on:
- Pull requests
- Pushes to main branch
- Multiple Python versions (3.12, 3.13, 3.14)
See .github/workflows/test.yml for CI configuration.
- ✅ Config: 71% (comprehensive unit tests)
- ✅ Auth: 100% (full password and OIDC coverage)
- ⏳ Semaphore: 68% (API methods tested, needs edge cases)
- ⏳ Bot: 52% (core functionality tested, needs more coverage)
- ⏳ Commands: 55% (command tests, needs workflow coverage)
- ✅ Main: 23% (E2E tests added! Up from 0%)
- ✅ Verification: 56% (device verification tested)
- ✅ Redactor: 93% (excellent coverage)
- ✅ Messages: 69% (message templates tested)
- ✅ Aliases: 71% (alias handling tested)
- ✅ TUI: Significantly improved with Textual pilot tests (94 new automated tests!)
- ✅ Overall: 40% (and improving!)
- ⏳ Bot: 60%+ (additional edge cases and async flows)
- ⏳ Commands: 65%+ (more workflow coverage)
- ⏳ Main: 40%+ (more TUI and daemon mode E2E tests)
- ⏳ Overall: 50%+
- ⏳ Overall: 70%+
- ⏳ Full integration tests with Matrix server
- ⏳ End-to-end testing with Semaphore instance
- ⏳ Performance and stress testing
- ⏳ TUI interaction tests with textual pilot
- Async Mocking Complexity: Some async tests with aiohttp are simplified to avoid complex mocking issues
- Matrix Server Required: Full bot integration tests require a test Matrix server
- Semaphore Server Required: Full Semaphore integration tests need a test Semaphore instance
- TUI Testing: TUI tests have lower coverage (15%) due to interactive nature - textual pilot could be used for more coverage
- Config Wizard Testing: Configuration wizard (0% coverage) requires interactive input testing
When contributing tests:
- Ensure all tests pass:
pytest tests/ - Check coverage doesn't decrease:
pytest tests/ --cov=chatrixcd - Follow existing test patterns
- Document complex test scenarios
- Use meaningful assertions with clear error messages
Recommended tools for test development:
# Install development tools
pip install pytest pytest-cov pytest-asyncio pytest-mock
# Run specific test file
pytest tests/test_auth.py -v
# Run specific test
pytest tests/test_auth.py::TestMatrixAuth::test_init_password_auth -v
# Stop on first failure
pytest tests/ -x
# Show local variables on failure
pytest tests/ -l- ARCHITECTURE.md - System architecture
- INSTALL.md - Installation guide
- README.md - Project overview