Some checks failed
API Endpoint Tests / test-api-endpoints (push) Successful in 56s
Blockchain Synchronization Verification / sync-verification (push) Failing after 3s
CLI Tests / test-cli (push) Failing after 5s
Coverage Phase 1 (70% Target) / test-coverage-70 (push) Failing after 19s
Coverage Phase 2 (85% Target) / test-coverage-85 (push) Failing after 18s
Cross-Chain Functionality Tests / test-cross-chain-sync (push) Successful in 3s
Cross-Chain Functionality Tests / test-cross-chain-transactions (push) Successful in 4s
Cross-Chain Functionality Tests / test-multi-chain-consensus (push) Successful in 5s
Deploy to Testnet / deploy-testnet (push) Failing after 21s
Documentation Validation / validate-docs (push) Failing after 13s
Documentation Validation / validate-policies-strict (push) Successful in 4s
Integration Tests / test-service-integration (push) Failing after 2s
Multi-Chain Island Architecture Tests / test-multi-chain-island (push) Successful in 4s
Multi-Node Blockchain Health Monitoring / health-check (push) Failing after 14s
Node Failover Simulation / failover-test (push) Successful in 9s
P2P Network Verification / p2p-verification (push) Successful in 5s
Package Tests / Python package - aitbc-agent-sdk (push) Successful in 51s
Package Tests / Python package - aitbc-core (push) Failing after 3s
Package Tests / Python package - aitbc-crypto (push) Successful in 22s
Package Tests / Python package - aitbc-sdk (push) Successful in 16s
Package Tests / JavaScript package - aitbc-sdk-js (push) Successful in 21s
Package Tests / JavaScript package - aitbc-token (push) Failing after 18s
Production Tests / Production Integration Tests (push) Failing after 1m9s
Python Tests / test-python (push) Failing after 3s
Security Scanning / security-scan (push) Failing after 41s
Smart Contract Tests / test-solidity (map[name:aitbc-contracts path:contracts]) (push) Failing after 6s
Smart Contract Tests / test-solidity (map[name:aitbc-token path:packages/solidity/aitbc-token]) (push) Failing after 7s
Smart Contract Tests / test-foundry (push) Failing after 20s
Smart Contract Tests / lint-solidity (push) Failing after 4s
Smart Contract Tests / deploy-contracts (push) Failing after 5s
Cross-Chain Functionality Tests / aggregate-results (push) Successful in 2s
Multi-Node Stress Testing / stress-test (push) Successful in 2s
Cross-Node Transaction Testing / transaction-test (push) Successful in 3s
Phase 1: Security fixes - Added CORSMiddleware to marketplace-service with specific origins - Fixed blockchain-node auth to fail closed on JWT errors - Added security regression tests (test_cors_configuration.py, test_dispute_auth.py) Phase 2: Repository cleanup - Removed 51 fix/backup/legacy files - Deleted marketplace-service-debug directory Phase 3.1: Python version constraints - Updated aitbc-crypto and aitbc-sdk with requires-python >=3.13 - Added explicit [tool.poetry].packages declarations Phase 3.2: Agent service DI architecture - Created aitbc-agent-core package with protocols and shared service - Implemented adapters for agent-management and coordinator-api - Created factory functions for gradual migration - Added migration comments to existing integration files Phase 4.1: Auth/utils extraction - Created auth.py module with JWT validation and security utilities - Created utils.py module with common helpers Phase 4.2: Router decomposition - Decomposed router.py into 10 domain modules (58 endpoints) - Created route table snapshot for verification - Preserved router_old.py as reference Phase 5: App shell classification - Documented app shell patterns across services Phase 6: Quality gates - Verified mypy type checking (75% error reduction) - Analyzed logging inconsistencies with structlog migration plan - Removed unused orjson dependency Documentation: - Created comprehensive remediation report - Added architecture documentation for DI pattern - Added quality analysis documents
AITBC Test Suite
This directory contains the comprehensive test suite for the AITBC platform, including unit tests, integration tests, end-to-end tests, security tests, and load tests.
Table of Contents
- Test Structure
- Prerequisites
- Running Tests
- Test Types
- Configuration
- CI/CD Integration
- Troubleshooting
Test Structure
tests/
├── conftest.py # Shared fixtures and configuration
├── conftest_fixtures.py # Comprehensive test fixtures
├── pytest.ini # Pytest configuration
├── README.md # This file
├── run_test_suite.py # Test suite runner script
├── unit/ # Unit tests
│ ├── test_coordinator_api.py
│ ├── test_wallet_daemon.py
│ └── test_blockchain_node.py
├── integration/ # Integration tests
│ ├── test_blockchain_node.py
│ └── test_full_workflow.py
├── e2e/ # End-to-end tests
│ ├── test_wallet_daemon.py
│ └── test_user_scenarios.py
├── security/ # Security tests
│ ├── test_confidential_transactions.py
│ └── test_security_comprehensive.py
├── load/ # Load tests
│ └── locustfile.py
└── fixtures/ # Test data and fixtures
├── sample_receipts.json
└── test_transactions.json
Prerequisites
Required Dependencies
# Core testing framework
pip install pytest pytest-asyncio pytest-cov pytest-mock pytest-xdist
# Security testing
pip install bandit safety
# Load testing
pip install locust
# Additional testing tools
pip install requests-mock websockets psutil
System Dependencies
# Ubuntu/Debian
sudo apt-get update
sudo apt-get install -y postgresql redis-server
# macOS
brew install postgresql redis
# Docker (for isolated testing)
docker --version
Environment Setup
- Clone the repository:
git clone https://github.com/aitbc/aitbc.git
cd aitbc
- Create virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
- Install dependencies:
pip install -r requirements.txt
pip install -r requirements-test.txt
- Set up test databases:
# PostgreSQL
createdb aitbc_test
# Redis (use test database 1)
redis-cli -n 1 FLUSHDB
- Environment variables:
export DATABASE_URL="postgresql://localhost/aitbc_test"
export REDIS_URL="redis://localhost:6379/1"
export TEST_MODE="true"
Running Tests
Basic Commands
# Run all tests
pytest
# Run using the test suite script (recommended)
python run_test_suite.py
# Run with coverage
python run_test_suite.py --coverage
# Run specific suite
python run_test_suite.py --suite unit
python run_test_suite.py --suite integration
python run_test_suite.py --suite e2e
python run_test_suite.py --suite security
# Run specific test file
pytest tests/unit/test_coordinator_api.py
# Run specific test class
pytest tests/unit/test_coordinator_api.py::TestJobEndpoints
# Run specific test method
pytest tests/unit/test_coordinator_api.py::TestJobEndpoints::test_create_job_success
Running by Test Type
# Unit tests only (fast)
pytest -m unit
# Integration tests (require services)
pytest -m integration
# End-to-end tests (full system)
pytest -m e2e
# Security tests
pytest -m security
# Load tests (requires Locust)
locust -f tests/load/locustfile.py
# Performance tests
pytest -m performance
# GPU tests (requires GPU)
pytest -m gpu
Parallel Execution
# Run with multiple workers
pytest -n auto
# Specify number of workers
pytest -n 4
# Distribute by test file
pytest --dist=loadfile
Filtering Tests
# Run tests matching pattern
pytest -k "test_create_job"
# Run tests not matching pattern
pytest -k "not slow"
# Run tests with multiple markers
pytest -m "unit and not slow"
# Run tests with any of multiple markers
pytest -m "unit or integration"
Test Types
Unit Tests (tests/unit/)
Fast, isolated tests that test individual components:
- Purpose: Test individual functions and classes
- Speed: < 1 second per test
- Dependencies: Mocked external services
- Database: In-memory SQLite
- Examples:
pytest tests/unit/ -v
Integration Tests (tests/integration/)
Tests that verify multiple components work together:
- Purpose: Test component interactions
- Speed: 1-10 seconds per test
- Dependencies: Real services required
- Database: Test PostgreSQL instance
- Examples:
# Start required services first docker-compose up -d postgres redis # Run integration tests pytest tests/integration/ -v
End-to-End Tests (tests/e2e/)
Full system tests that simulate real user workflows:
- Purpose: Test complete user journeys
- Speed: 10-60 seconds per test
- Dependencies: Full system running
- Database: Production-like setup
- Examples:
# Start full system docker-compose up -d # Run E2E tests pytest tests/e2e/ -v -s
Security Tests (tests/security/)
Tests that verify security properties and vulnerability resistance:
- Purpose: Test security controls
- Speed: Variable (some are slow)
- Dependencies: May require special setup
- Tools: Bandit, Safety, Custom security tests
- Examples:
# Run security scanner bandit -r apps/ -f json -o bandit-report.json # Run security tests pytest tests/security/ -v
Load Tests (tests/load/)
Performance and scalability tests:
- Purpose: Test system under load
- Speed: Long-running (minutes)
- Dependencies: Locust, staging environment
- Canonical Entry Point:
tests/load/test_api_load.py - Examples:
# Run canonical load test with runner script (recommended) scripts/testing/run_load_tests.sh # Run with custom parameters LOAD_USERS=200 LOAD_DURATION=10m scripts/testing/run_load_tests.sh # Run Locust web UI directly locust -f tests/load/test_api_load.py --web-host 127.0.0.1 # Run headless directly locust -f tests/load/test_api_load.py --headless -u 100 -r 10 -t 5m
Configuration
Pytest Configuration (pytest.ini)
Key configuration options:
[tool:pytest]
# Test paths
testpaths = tests
python_files = test_*.py
# Coverage settings
addopts = --cov=apps --cov=packages --cov-report=html
# Markers
markers =
unit: Unit tests
integration: Integration tests
e2e: End-to-end tests
security: Security tests
slow: Slow tests
Environment Variables
# Test configuration
export TEST_MODE=true
export TEST_DATABASE_URL="postgresql://localhost/aitbc_test"
export TEST_REDIS_URL="redis://localhost:6379/1"
# Service URLs for integration tests
export COORDINATOR_URL="http://localhost:8001"
export WALLET_URL="http://localhost:8002"
export BLOCKCHAIN_URL="http://localhost:8545"
# Security test configuration
export TEST_HSM_ENDPOINT="http://localhost:9999"
export TEST_ZK_CIRCUITS_PATH="./apps/zk-circuits"
Test Data Management
# Using fixtures in conftest.py
@pytest.fixture
def test_data():
return {
"sample_job": {...},
"sample_receipt": {...},
}
# Custom test configuration
@pytest.fixture(scope="session")
def test_config():
return TestConfig(
database_url="sqlite:///:memory:",
redis_url="redis://localhost:6379/1",
)
CI/CD Integration
GitHub Actions Example
name: Tests
on: [push, pull_request]
jobs:
unit-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python: "3.11"
- name: Install dependencies
run: |
pip install -r requirements.txt
pip install -r requirements-test.txt
- name: Run unit tests
run: |
pytest tests/unit/ -v --cov=apps --cov-report=xml
- name: Upload coverage
uses: codecov/codecov-action@v3
with:
file: ./coverage.xml
integration-tests:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:15
env:
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
redis:
image: redis:7
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python: "3.11"
- name: Install dependencies
run: |
pip install -r requirements.txt
pip install -r requirements-test.txt
- name: Run integration tests
run: |
pytest tests/integration/ -v
env:
DATABASE_URL: postgresql://postgres:postgres@localhost/postgres
REDIS_URL: redis://localhost:6379/0
Docker Compose for Testing
# docker-compose.test.yml
version: '3.8'
services:
postgres:
image: postgres:15
environment:
POSTGRES_DB: aitbc_test
POSTGRES_USER: test
POSTGRES_PASSWORD: test
ports:
- "5433:5432"
healthcheck:
test: ["CMD-SHELL", "pg_isready -U test"]
interval: 5s
timeout: 5s
retries: 5
redis:
image: redis:7-alpine
ports:
- "6380:6379"
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 5s
timeout: 5s
retries: 5
coordinator:
build: ./apps/coordinator-api
environment:
DATABASE_URL: postgresql://test:test@postgres:5432/aitbc_test
REDIS_URL: redis://redis:6379/0
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
ports:
- "8001:8000"
Troubleshooting
Common Issues
-
Import Errors
# Ensure PYTHONPATH is set export PYTHONPATH="${PYTHONPATH}:$(pwd)" # Or install in development mode pip install -e . -
Database Connection Errors
# Check if PostgreSQL is running pg_isready -h localhost -p 5432 # Create test database createdb -h localhost -p 5432 aitbc_test -
Redis Connection Errors
# Check if Redis is running redis-cli ping # Use correct database redis-cli -n 1 FLUSHDB -
Test Timeouts
# Increase timeout for slow tests pytest --timeout=600 # Run tests sequentially pytest -n 0 -
Port Conflicts
# Kill processes using ports lsof -ti:8001 | xargs kill -9 lsof -ti:8002 | xargs kill -9
Debugging Tests
# Run with verbose output
pytest -v -s
# Stop on first failure
pytest -x
# Run with pdb on failure
pytest --pdb
# Print local variables on failure
pytest --tb=long
# Run specific test with debugging
pytest tests/unit/test_coordinator_api.py::TestJobEndpoints::test_create_job_success -v -s --pdb
Performance Issues
# Profile test execution
pytest --profile
# Find slowest tests
pytest --durations=10
# Run with memory profiling
pytest --memprof
Test Data Issues
# Clean test database
psql -h localhost -U test -d aitbc_test -c "DROP SCHEMA public CASCADE; CREATE SCHEMA public;"
# Reset Redis
redis-cli -n 1 FLUSHALL
# Regenerate test fixtures
python tests/generate_fixtures.py
Best Practices
- Write Isolated Tests: Each test should be independent
- Use Descriptive Names: Test names should describe what they test
- Mock External Dependencies: Use mocks for external services
- Clean Up Resources: Use fixtures for setup/teardown
- Test Edge Cases: Don't just test happy paths
- Use Type Hints: Makes tests more maintainable
- Document Complex Tests: Add comments for complex logic
Contributing
When adding new tests:
- Follow the existing structure and naming conventions
- Add appropriate markers (
@pytest.mark.unit, etc.) - Update this README if adding new test types
- Ensure tests pass on CI before submitting PR
- Add coverage for new features