docs/TESTING_SUMMARY.md
Comprehensive unit test suite for LangBot's pipeline stages, providing extensible test infrastructure and automated CI/CD integration.
tests/pipeline/conftest.py)importlib.import_module()Total: 27 test cases
GitHub Actions Workflow (.github/workflows/pipeline-tests.yml):
run_tests.sh scriptProblem: Direct imports of pipeline modules caused circular dependency errors:
pkg.pipeline.stage → pkg.core.app → pkg.pipeline.pipelinemgr → pkg.pipeline.resprule
Solution: Implemented lazy imports using importlib.import_module():
def get_bansess_module():
return import_module('pkg.pipeline.bansess.bansess')
# Use in tests
bansess = get_bansess_module()
stage = bansess.BanSessionCheckStage(mock_app)
Problem: Some stages use Pydantic models that validate new_query parameter.
Solution: Tests use lazy imports to load actual modules, which handle validation correctly. Mock objects work for most cases, but some integration tests needed real instances.
Problem: Lists don't allow .copy attribute assignment in Python.
Solution: Use Mock objects instead of bare lists:
mock_messages = Mock()
mock_messages.copy = Mock(return_value=[])
conversation.messages = mock_messages
Running bash run_tests.sh shows:
test_simple.py tests (infrastructure validation)Some tests encounter:
For CI/CD purposes:
test_simple.py to validate test infrastructuretest_pipelinemgr.py for manager logicFor local development:
.
├── .github/workflows/
│ └── pipeline-tests.yml # CI/CD workflow
├── tests/
│ ├── README.md # Testing documentation
│ ├── __init__.py
│ └── pipeline/
│ ├── __init__.py
│ ├── conftest.py # Shared fixtures
│ ├── test_simple.py # Infrastructure tests ✅
│ ├── test_bansess.py # BanSession tests
│ ├── test_ratelimit.py # RateLimit tests
│ ├── test_preproc.py # PreProcessor tests
│ ├── test_respback.py # ResponseBack tests
│ ├── test_resprule.py # ResponseRule tests
│ ├── test_pipelinemgr.py # Manager tests ✅
│ └── test_stages_integration.py # Integration tests
├── pytest.ini # Pytest config
├── run_tests.sh # Test runner
└── TESTING_SUMMARY.md # This file
bash run_tests.sh
pytest tests/pipeline/test_simple.py -v
pytest tests/pipeline/ --cov=pkg/pipeline --cov-report=html
open htmlcov/index.html
This test suite provides:
Next steps should focus on refactoring the pipeline module structure to eliminate circular dependencies, which will allow all tests to run successfully.