Merge branch 'wecode-ai:main' into main #40
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
| # SPDX-FileCopyrightText: 2025 Weibo, Inc. | |
| # | |
| # SPDX-License-Identifier: Apache-2.0 | |
| name: Tests | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - master | |
| - develop | |
| pull_request: | |
| branches: | |
| - main | |
| - master | |
| - develop | |
| jobs: | |
| test-backend: | |
| name: Test Backend | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| python-version: ['3.10', '3.11', '3.12'] | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python ${{ matrix.python-version }} | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Cache Python dependencies | |
| uses: actions/cache@v3 | |
| with: | |
| path: ~/.cache/uv | |
| key: ${{ runner.os }}-uv-${{ hashFiles('backend/pyproject.toml') }} | |
| restore-keys: | | |
| ${{ runner.os }}-uv- | |
| - name: Install dependencies | |
| working-directory: ./backend | |
| run: | | |
| curl -LsSf https://astral.sh/uv/install.sh | sh | |
| source $HOME/.cargo/env | |
| uv sync --dev | |
| - name: Run backend tests | |
| working-directory: ./backend | |
| env: | |
| PYTHONPATH: ${{ github.workspace }} | |
| run: | | |
| source $HOME/.cargo/env | |
| uv run pytest tests/ --cov=app --cov-report=xml --cov-report=term-missing -v | |
| - name: Upload coverage to Codecov | |
| uses: codecov/codecov-action@v3 | |
| with: | |
| files: ./backend/coverage.xml | |
| flags: backend | |
| name: backend-coverage | |
| test-executor: | |
| name: Test Executor | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python 3.10 | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.10' | |
| - name: Cache Python dependencies | |
| uses: actions/cache@v3 | |
| with: | |
| path: ~/.cache/uv | |
| key: ${{ runner.os }}-uv-executor-${{ hashFiles('executor/pyproject.toml') }} | |
| restore-keys: | | |
| ${{ runner.os }}-uv-executor- | |
| - name: Install dependencies | |
| working-directory: ./executor | |
| run: | | |
| curl -LsSf https://astral.sh/uv/install.sh | sh | |
| source $HOME/.cargo/env | |
| uv sync --dev | |
| - name: Run executor tests | |
| working-directory: ./executor | |
| env: | |
| PYTHONPATH: ${{ github.workspace }}:${{ github.workspace }}/executor | |
| run: | | |
| source $HOME/.cargo/env | |
| uv run pytest tests/ --cov=agents --cov-report=xml --cov-report=term-missing -v | |
| - name: Upload coverage to Codecov | |
| uses: codecov/codecov-action@v3 | |
| with: | |
| files: ./executor/coverage.xml | |
| flags: executor | |
| name: executor-coverage | |
| test-executor-manager: | |
| name: Test Executor Manager | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python 3.11 | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.11' | |
| - name: Cache Python dependencies | |
| uses: actions/cache@v3 | |
| with: | |
| path: ~/.cache/uv | |
| key: ${{ runner.os }}-uv-executor-manager-${{ hashFiles('executor_manager/pyproject.toml') }} | |
| restore-keys: | | |
| ${{ runner.os }}-uv-executor-manager- | |
| - name: Install dependencies | |
| working-directory: ./executor_manager | |
| run: | | |
| curl -LsSf https://astral.sh/uv/install.sh | sh | |
| source $HOME/.cargo/env | |
| uv sync --dev | |
| - name: Run executor manager tests | |
| working-directory: ./executor_manager | |
| env: | |
| PYTHONPATH: ${{ github.workspace }} | |
| COVERAGE_CORE: sysmon | |
| PYTHONUNBUFFERED: "1" | |
| PYTHONFAULTHANDLER: "1" | |
| run: | | |
| source $HOME/.cargo/env | |
| uv run pytest tests/ --cov=executors --cov-report=xml --cov-report=term-missing -v -s | |
| - name: Upload coverage to Codecov | |
| uses: codecov/codecov-action@v3 | |
| with: | |
| files: ./executor_manager/coverage.xml | |
| flags: executor-manager | |
| name: executor-manager-coverage | |
| test-shared: | |
| name: Test Shared | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python 3.10 | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.10' | |
| - name: Cache Python dependencies | |
| uses: actions/cache@v3 | |
| with: | |
| path: ~/.cache/uv | |
| key: ${{ runner.os }}-uv-shared-${{ hashFiles('shared/pyproject.toml') }} | |
| restore-keys: | | |
| ${{ runner.os }}-uv-shared- | |
| - name: Install dependencies | |
| working-directory: ./shared | |
| run: | | |
| curl -LsSf https://astral.sh/uv/install.sh | sh | |
| source $HOME/.cargo/env | |
| uv sync --dev | |
| - name: Run shared tests | |
| working-directory: ./shared | |
| env: | |
| COVERAGE_CORE: sysmon | |
| PYTHONUNBUFFERED: "1" | |
| PYTHONFAULTHANDLER: "1" | |
| run: | | |
| source $HOME/.cargo/env | |
| # Run pytest and capture exit code, ignoring thread cleanup errors | |
| set +e | |
| uv run pytest tests/ --cov=utils --cov-config=.coveragerc --cov-report=xml --cov-report=term-missing -v -p no:cacheprovider 2>&1 | |
| PYTEST_EXIT=$? | |
| set -e | |
| # Exit code 0 = success, others indicate test failures | |
| # Thread cleanup errors cause exit 134 but tests pass, so check coverage.xml exists | |
| if [ $PYTEST_EXIT -eq 0 ] || ([ $PYTEST_EXIT -eq 134 ] && [ -f coverage.xml ]); then | |
| echo "Tests completed successfully" | |
| exit 0 | |
| else | |
| echo "Tests failed with exit code $PYTEST_EXIT" | |
| exit $PYTEST_EXIT | |
| fi | |
| - name: Upload coverage to Codecov | |
| uses: codecov/codecov-action@v3 | |
| with: | |
| files: ./shared/coverage.xml | |
| flags: shared | |
| name: shared-coverage | |
| test-frontend: | |
| name: Test Frontend | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '18.x' | |
| cache: 'npm' | |
| cache-dependency-path: ./frontend/package-lock.json | |
| - name: Cache Next.js build | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ./frontend/.next/cache | |
| key: ${{ runner.os }}-nextjs-${{ hashFiles('./frontend/package-lock.json') }}-${{ hashFiles('./frontend/src/**/*.[jt]s', './frontend/src/**/*.[jt]sx') }} | |
| restore-keys: | | |
| ${{ runner.os }}-nextjs-${{ hashFiles('./frontend/package-lock.json') }}- | |
| ${{ runner.os }}-nextjs- | |
| - name: Install dependencies | |
| working-directory: ./frontend | |
| run: npm ci | |
| - name: Run frontend tests | |
| working-directory: ./frontend | |
| env: | |
| NEXT_TELEMETRY_DISABLED: 1 | |
| run: npm test -- --coverage --passWithNoTests | |
| - name: Upload coverage to Codecov | |
| uses: codecov/codecov-action@v3 | |
| with: | |
| files: ./frontend/coverage/coverage-final.json | |
| flags: frontend | |
| name: frontend-coverage | |
| test-wegent-cli: | |
| name: Test wegent CLI | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python 3.10 | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.10' | |
| - name: Cache Python dependencies | |
| uses: actions/cache@v3 | |
| with: | |
| path: ~/.cache/pip | |
| key: ${{ runner.os }}-pip-wegent-cli-${{ hashFiles('wegent-cli/requirements.txt') }} | |
| restore-keys: | | |
| ${{ runner.os }}-pip-wegent-cli- | |
| - name: Install dependencies | |
| working-directory: ./wegent-cli | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| pip install pytest pytest-cov pytest-mock | |
| - name: Run wegent unit tests | |
| working-directory: ./wegent-cli | |
| run: | | |
| pytest tests/ --ignore=tests/test_integration.py --cov=wegent --cov-report=xml --cov-report=term-missing -v | |
| - name: Upload coverage to Codecov | |
| uses: codecov/codecov-action@v3 | |
| with: | |
| files: ./wegent-cli/coverage.xml | |
| flags: wegent-cli | |
| name: wegent-cli-coverage | |
| test-wegent-cli-integration: | |
| name: Test wegent CLI Integration | |
| runs-on: ubuntu-latest | |
| services: | |
| mysql: | |
| image: mysql:8.0 | |
| env: | |
| MYSQL_ROOT_PASSWORD: test123 | |
| MYSQL_DATABASE: task_manager | |
| MYSQL_USER: task_user | |
| MYSQL_PASSWORD: task_pass | |
| ports: | |
| - 3306:3306 | |
| options: >- | |
| --health-cmd="mysqladmin ping -h localhost -u root -ptest123" | |
| --health-interval=10s | |
| --health-timeout=5s | |
| --health-retries=10 | |
| --health-start-period=30s | |
| redis: | |
| image: redis:7-alpine | |
| ports: | |
| - 6379:6379 | |
| options: >- | |
| --health-cmd="redis-cli ping" | |
| --health-interval=10s | |
| --health-timeout=5s | |
| --health-retries=5 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python 3.10 | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.10' | |
| - name: Install backend dependencies | |
| working-directory: ./backend | |
| run: | | |
| curl -LsSf https://astral.sh/uv/install.sh | sh | |
| source $HOME/.cargo/env | |
| uv sync | |
| - name: Install shared module | |
| run: | | |
| pip install ./shared || pip install cryptography | |
| - name: Start backend service | |
| working-directory: ./backend | |
| env: | |
| ENVIRONMENT: development | |
| DB_AUTO_MIGRATE: "True" | |
| DATABASE_URL: mysql+pymysql://task_user:task_pass@localhost:3306/task_manager | |
| SECRET_KEY: test-secret-key-for-ci | |
| ALGORITHM: HS256 | |
| ACCESS_TOKEN_EXPIRE_MINUTES: 1440 | |
| REDIS_URL: redis://localhost:6379/0 | |
| INIT_DATA_ENABLED: "False" | |
| PYTHONPATH: ${{ github.workspace }} | |
| run: | | |
| uvicorn app.main:app --host 0.0.0.0 --port 8000 & | |
| echo "Waiting for backend to start..." | |
| for i in {1..30}; do | |
| if curl -s http://localhost:8000/api/health > /dev/null 2>&1; then | |
| echo "Backend is ready!" | |
| break | |
| fi | |
| echo "Waiting... ($i/30)" | |
| sleep 2 | |
| done | |
| - name: Install wegent dependencies | |
| working-directory: ./wegent-cli | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| pip install pytest pytest-cov | |
| - name: Run wegent integration tests | |
| working-directory: ./wegent-cli | |
| env: | |
| WEGENT_TEST_SERVER: http://localhost:8000 | |
| run: | | |
| pytest tests/test_integration.py --integration -v | |
| test-summary: | |
| name: Test Summary | |
| runs-on: ubuntu-latest | |
| needs: [test-backend, test-executor, test-executor-manager, test-shared, test-frontend, test-wegent-cli, test-wegent-cli-integration] | |
| if: always() | |
| steps: | |
| - name: Check test results | |
| run: | | |
| echo "All test jobs completed" | |
| if [[ "${{ needs.test-backend.result }}" == "failure" ]] || \ | |
| [[ "${{ needs.test-executor.result }}" == "failure" ]] || \ | |
| [[ "${{ needs.test-executor-manager.result }}" == "failure" ]] || \ | |
| [[ "${{ needs.test-shared.result }}" == "failure" ]] || \ | |
| [[ "${{ needs.test-frontend.result }}" == "failure" ]] || \ | |
| [[ "${{ needs.test-wegent-cli.result }}" == "failure" ]] || \ | |
| [[ "${{ needs.test-wegent-cli-integration.result }}" == "failure" ]]; then | |
| echo "One or more test jobs failed" | |
| exit 1 | |
| fi |