update tests #17
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Full CI Pipeline | |
| on: | |
| push: | |
| branches: [ main, develop ] | |
| pull_request: | |
| branches: [ main, develop ] | |
| jobs: | |
| lint: | |
| name: Lint and Security Checks | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.10' | |
| - name: Install linting tools | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install flake8 black isort bandit | |
| - name: Run Black (code formatting check) | |
| run: | | |
| black --check mcp_server/ auth_platform/auth_platform/ || true | |
| - name: Run isort (import sorting check) | |
| run: | | |
| isort --check-only mcp_server/ auth_platform/auth_platform/ || true | |
| - name: Run Flake8 (linting) | |
| run: | | |
| flake8 mcp_server/ auth_platform/auth_platform/ --max-line-length=120 --extend-ignore=E203,W503 || true | |
| - name: Run Bandit (security check) | |
| run: | | |
| bandit -r mcp_server/ auth_platform/auth_platform/ -ll || true | |
| unit-tests: | |
| name: Unit Tests | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.10' | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| cd mcp_server | |
| pip install -e .[test] | |
| - name: Run MCP Server unit tests | |
| run: | | |
| cd mcp_server | |
| pytest tests/unit/test_fraud_detector.py -v --tb=short | |
| integration-tests: | |
| name: Integration Tests | |
| runs-on: ubuntu-latest | |
| needs: [lint, unit-tests] | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.10' | |
| - name: Install test dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| cd mcp_server | |
| pip install -e .[test] | |
| pip install httpx | |
| - name: Build Docker images | |
| run: | | |
| cd auth_platform | |
| docker compose build | |
| - name: Start services | |
| run: | | |
| cd auth_platform | |
| docker compose up -d | |
| - name: Wait for services | |
| run: | | |
| echo "Waiting for services to start..." | |
| sleep 15 | |
| # Wait for MCP Server with retries | |
| for i in {1..30}; do | |
| if curl -f http://localhost:8001/health > /dev/null 2>&1; then | |
| echo "✓ MCP Server is ready" | |
| break | |
| fi | |
| if [ $i -eq 30 ]; then | |
| echo "❌ MCP Server failed to start" | |
| docker logs $(docker ps -aq --filter "name=mcp-server") || echo "MCP Server container not found" | |
| exit 1 | |
| fi | |
| echo "Waiting for MCP Server... ($i/30)" | |
| sleep 2 | |
| done | |
| # Wait for Auth Service with retries | |
| for i in {1..30}; do | |
| if curl -f http://localhost:8000/docs > /dev/null 2>&1; then | |
| echo "✓ Auth Service is ready" | |
| break | |
| fi | |
| if [ $i -eq 30 ]; then | |
| echo "❌ Auth Service failed to start" | |
| docker logs $(docker ps -aq --filter "name=auth-service") || echo "Auth Service container not found" | |
| exit 1 | |
| fi | |
| echo "Waiting for Auth Service... ($i/30)" | |
| sleep 2 | |
| done | |
| - name: Verify service health | |
| run: | | |
| echo "=== Checking MCP Server ===" | |
| curl -f http://localhost:8001/health | |
| curl -f http://localhost:8001/ | |
| echo -e "\n=== Checking Auth Service ===" | |
| curl -f http://localhost:8000/docs | |
| - name: Run integration tests | |
| run: | | |
| cd mcp_server | |
| pytest tests/e2e/test_e2e_simple.py -v -s --log-cli-level=INFO | |
| - name: Test email notification logging | |
| run: | | |
| echo "Testing fraud detection and email notification..." | |
| # Send multiple failed login attempts to trigger fraud detection | |
| for i in {1..12}; do | |
| TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%S.000Z") | |
| curl -X POST http://localhost:8001/mcp/ingest \ | |
| -H "Content-Type: application/json" \ | |
| -d "{ | |
| \"user_id\": 999, | |
| \"username\": \"ci_test_user\", | |
| \"event_type\": \"login_failure\", | |
| \"timestamp\": \"$TIMESTAMP\", | |
| \"ip_address\": \"10.0.0.1\", | |
| \"user_agent\": \"CI-Test/1.0\" | |
| }" > /dev/null 2>&1 | |
| sleep 0.3 | |
| done | |
| echo "Waiting for fraud analysis..." | |
| sleep 3 | |
| # Check logs for email notification | |
| docker logs $(docker ps -aq --filter "name=mcp-server") 2>&1 | grep "📧 EMAIL NOTIFICATION TRIGGER" && \ | |
| echo "✓ Email notification logging verified" || \ | |
| (echo "❌ Email notification not found in logs" && exit 1) | |
| - name: Show service logs on failure | |
| if: failure() | |
| run: | | |
| echo "=== MCP Server Logs ===" | |
| docker logs $(docker ps -aq --filter "name=mcp-server") 2>&1 | tail -100 || echo "MCP Server container not found" | |
| echo -e "\n=== Auth Service Logs ===" | |
| docker logs $(docker ps -aq --filter "name=auth-service") 2>&1 | tail -100 || echo "Auth Service container not found" | |
| - name: Stop services | |
| if: always() | |
| run: | | |
| cd auth_platform | |
| docker compose down -v | |
| build-check: | |
| name: Docker Build Check | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Build Auth Service image | |
| run: | | |
| cd auth_platform | |
| docker build -t auth-service-test -f Dockerfile . | |
| - name: Build MCP Server image | |
| run: | | |
| cd mcp_server | |
| docker build -t mcp-server-test -f Dockerfile . | |
| - name: Check image sizes | |
| run: | | |
| echo "=== Docker Image Sizes ===" | |
| docker images | grep -E "auth-service-test|mcp-server-test" |