5.0 KiB
5.0 KiB
description, auto_execution_mode
| description | auto_execution_mode |
|---|---|
| Test and debug workflow for AITBC platform | 3 |
Test and Debug Workflow
This workflow helps you run tests and debug issues in the AITBC platform.
Steps
1. Run All Integration Tests
# Run all integration tests
cd /home/oib/windsurf/aitbc
python -m pytest tests/integration/test_full_workflow.py -v --no-cov
# Run with detailed output
python -m pytest tests/integration/test_full_workflow.py -v --no-cov -s --tb=short
2. Run Specific Test Classes
# Test wallet payment flow
python -m pytest tests/integration/test_full_workflow.py::TestWalletToCoordinatorIntegration::test_job_payment_flow -v --no-cov -s
# Test marketplace integration
python -m pytest tests/integration/test_full_workflow.py::TestMarketplaceIntegration::test_service_listing_and_booking -v --no-cov -s
# Test security integration
python -m pytest tests/integration/test_full_workflow.py::TestSecurityIntegration::test_end_to_end_encryption -v --no-cov -s
3. Debug Test Failures
# Run with pdb on failure
python -m pytest tests/integration/test_full_workflow.py -v --no-cov --pdb
# Run with verbose output and show local variables
python -m pytest tests/integration/test_full_workflow.py -v --no-cov -s --tb=long
# Stop on first failure
python -m pytest tests/integration/test_full_workflow.py -v --no-cov -x
4. Check Test Coverage
# Run tests with coverage
python -m pytest tests/integration/test_full_workflow.py --cov=apps/coordinator-api --cov-report=html
# View coverage report
open htmlcov/index.html
5. Debug Services
# Check if coordinator API is running
curl http://localhost:18000/v1/health
# Check if wallet daemon is running
curl http://localhost:20000/api/v1/health
# Check if exchange is running
curl http://localhost:23000/api/health
# Check if marketplace is accessible
curl https://aitbc.bubuit.net/marketplace
6. View Logs
# View coordinator API logs
docker logs aitbc-coordinator-api -f
# View wallet daemon logs
docker logs aitbc-wallet-daemon -f
# View exchange logs
docker logs aitbc-exchange -f
7. Test Payment Flow Manually
# Create a job with AITBC payment
curl -X POST http://localhost:18000/v1/jobs \
-H "X-Api-Key: REDACTED_CLIENT_KEY" \
-H "Content-Type: application/json" \
-d '{
"payload": {
"job_type": "ai_inference",
"parameters": {"model": "gpt-4", "prompt": "Test"}
},
"payment_amount": 100,
"payment_currency": "AITBC"
}'
# Check payment status
curl http://localhost:18000/v1/jobs/{job_id}/payment \
-H "X-Api-Key: REDACTED_CLIENT_KEY"
8. Common Debug Commands
# Check Python environment
python --version
pip list | grep -E "(fastapi|sqlmodel|pytest|httpx)"
# Check database connection
psql -h localhost -U aitbc -d aitbc -c "\dt"
# Check running services
ps aux | grep -E "(coordinator|wallet|exchange)"
# Check network connectivity
netstat -tlnp | grep -E "(18000|20000|23000)"
9. Performance Testing
# Run tests with performance profiling
python -m pytest tests/integration/test_full_workflow.py --profile
# Load test payment endpoints
ab -n 100 -c 10 http://localhost:18000/v1/health
10. Clean Test Environment
# Clean pytest cache
rm -rf .pytest_cache
# Clean coverage files
rm -rf htmlcov .coverage
# Reset test database
dropdb aitbc_test && createdb aitbc_test
Troubleshooting
Common Issues
-
Import Error: No module named 'app.schemas.payments'
- The test is using mock client (expected in CI)
- Real client requires full environment setup
-
ModuleNotFoundError: No module named 'requests'
- Install requests:
pip install requests - Check if in correct Python environment
- Install requests:
-
Connection Refused Errors
- Check if services are running on expected ports
- Verify docker containers are up:
docker ps
-
Payment Test Fails
- Ensure wallet daemon is running
- Check exchange API is accessible
- Verify AITBC token balance
-
Marketplace Test Fails
- Check internet connectivity
- Verify marketplace URL is accessible
- May need to skip if network issues
Debug Tips
- Use
--pdbto drop into debugger on failure - Use
-sto see print statements - Use
--tb=longfor detailed tracebacks - Use
-xto stop on first failure - Check logs for service errors
- Verify environment variables are set
Test Categories
Unit Tests
# Run unit tests only
python -m pytest tests/unit/ -v
Integration Tests
# Run integration tests only
python -m pytest tests/integration/ -v
End-to-End Tests
# Run e2e tests only
python -m pytest tests/e2e/ -v
Security Tests
# Run security tests
python -m pytest tests/security/ -v
Quick Test Commands
# Quick test run
pytest tests/ -x -q
# Full test suite
pytest tests/ --cov
# Debug specific test
pytest tests/integration/test_full_workflow.py::TestWalletToCoordinatorIntegration::test_job_payment_flow -v -s