feat: 统一前缀亲和 Session 与 Replay 使用记录语义 #2646
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: 🧪 Test Suite | |
| on: | |
| push: | |
| branches: [main, dev] | |
| pull_request: | |
| branches: [main, dev] | |
| # 取消同一分支的进行中的工作流 | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| # ==================== 代码质量检查 ==================== | |
| quality: | |
| name: 📋 Code Quality | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 15 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v6 | |
| - name: Setup Bun | |
| uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version-file: .bun-version | |
| - name: Cache Bun package cache | |
| uses: actions/cache@v5 | |
| with: | |
| path: ~/.bun/install/cache | |
| # This repo intentionally does not track Bun lockfiles; rotate cache on package/runtime inputs. | |
| key: ${{ runner.os }}-bun-${{ hashFiles('package.json', '.bun-version') }} | |
| restore-keys: | | |
| ${{ runner.os }}-bun- | |
| - name: Install dependencies | |
| timeout-minutes: 8 | |
| # No lockfile is committed in this repository, so use a non-frozen install. | |
| run: bun install | |
| - name: Run linting | |
| run: bun run lint | |
| - name: Run type checking | |
| run: bun run typecheck | |
| - name: Check v1 OpenAPI contract | |
| run: | | |
| bun run openapi:check | |
| bun run openapi:lint | |
| - name: Check formatting | |
| run: bun run format:check | |
| # ==================== 单元测试 ==================== | |
| unit-tests: | |
| name: ⚡ Unit Tests | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 15 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v6 | |
| - name: Setup Bun | |
| uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version-file: .bun-version | |
| - name: Cache Bun package cache | |
| uses: actions/cache@v5 | |
| with: | |
| path: ~/.bun/install/cache | |
| # This repo intentionally does not track Bun lockfiles; rotate cache on package/runtime inputs. | |
| key: ${{ runner.os }}-bun-${{ hashFiles('package.json', '.bun-version') }} | |
| restore-keys: | | |
| ${{ runner.os }}-bun- | |
| - name: Install dependencies | |
| timeout-minutes: 8 | |
| # No lockfile is committed in this repository, so use a non-frozen install. | |
| run: bun install | |
| - name: Run unit tests | |
| run: bun run test -- tests/unit/ --passWithNoTests | |
| - name: Run v1 management API tests | |
| run: bun run test:v1 | |
| # ==================== 集成测试(需要数据库)==================== | |
| integration-tests: | |
| name: 🔗 Integration Tests | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 25 | |
| services: | |
| postgres: | |
| image: postgres:16-alpine | |
| env: | |
| POSTGRES_USER: test_user | |
| POSTGRES_PASSWORD: test_password | |
| POSTGRES_DB: claude_code_hub_test | |
| options: >- | |
| --health-cmd "pg_isready -U test_user -d claude_code_hub_test" | |
| --health-interval 10s | |
| --health-timeout 5s | |
| --health-retries 5 | |
| ports: | |
| - 5432:5432 | |
| redis: | |
| image: redis:7-alpine | |
| options: >- | |
| --health-cmd "redis-cli ping" | |
| --health-interval 10s | |
| --health-timeout 5s | |
| --health-retries 5 | |
| ports: | |
| - 6379:6379 | |
| env: | |
| DSN: postgres://test_user:test_password@localhost:5432/claude_code_hub_test | |
| REDIS_URL: redis://localhost:6379/1 | |
| ADMIN_TOKEN: test-admin-token-for-ci | |
| AUTO_MIGRATE: true | |
| ENABLE_RATE_LIMIT: true | |
| AUTH_SESSION_TTL_SECONDS: 604800 | |
| SESSION_TTL: 300 | |
| VITEST_STATEFUL_MAX_WORKERS: 2 | |
| VITEST_STATEFUL_MAX_CONCURRENCY: 3 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v6 | |
| - name: Setup Bun | |
| uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version-file: .bun-version | |
| - name: Cache Bun package cache | |
| uses: actions/cache@v5 | |
| with: | |
| path: ~/.bun/install/cache | |
| # This repo intentionally does not track Bun lockfiles; rotate cache on package/runtime inputs. | |
| key: ${{ runner.os }}-bun-${{ hashFiles('package.json', '.bun-version') }} | |
| restore-keys: | | |
| ${{ runner.os }}-bun- | |
| - name: Install dependencies | |
| timeout-minutes: 8 | |
| # No lockfile is committed in this repository, so use a non-frozen install. | |
| run: bun install | |
| - name: Run database migrations | |
| run: bun run db:migrate | |
| - name: Run integration tests | |
| run: > | |
| bun x vitest run | |
| --config tests/configs/integration.config.ts | |
| --passWithNoTests | |
| # ==================== API 测试(需要运行服务)==================== | |
| api-tests: | |
| name: 🌐 API Tests | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 35 | |
| services: | |
| postgres: | |
| image: postgres:16-alpine | |
| env: | |
| POSTGRES_USER: test_user | |
| POSTGRES_PASSWORD: test_password | |
| POSTGRES_DB: claude_code_hub_test | |
| options: >- | |
| --health-cmd "pg_isready -U test_user -d claude_code_hub_test" | |
| --health-interval 10s | |
| --health-timeout 5s | |
| --health-retries 5 | |
| ports: | |
| - 5432:5432 | |
| redis: | |
| image: redis:7-alpine | |
| options: >- | |
| --health-cmd "redis-cli ping" | |
| --health-interval 10s | |
| --health-timeout 5s | |
| --health-retries 5 | |
| ports: | |
| - 6379:6379 | |
| env: | |
| DSN: postgres://test_user:test_password@localhost:5432/claude_code_hub_test | |
| REDIS_URL: redis://localhost:6379/1 | |
| ADMIN_TOKEN: test-admin-token-for-ci | |
| AUTO_MIGRATE: true | |
| PORT: 13500 | |
| ENABLE_RATE_LIMIT: true | |
| AUTH_SESSION_TTL_SECONDS: 604800 | |
| SESSION_TTL: 300 | |
| VITEST_STATEFUL_MAX_WORKERS: 1 | |
| VITEST_STATEFUL_MAX_CONCURRENCY: 3 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v6 | |
| - name: Setup Bun | |
| uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version-file: .bun-version | |
| - name: Cache Bun package cache | |
| uses: actions/cache@v5 | |
| with: | |
| path: ~/.bun/install/cache | |
| # This repo intentionally does not track Bun lockfiles; rotate cache on package/runtime inputs. | |
| key: ${{ runner.os }}-bun-${{ hashFiles('package.json', '.bun-version') }} | |
| restore-keys: | | |
| ${{ runner.os }}-bun- | |
| - name: Install dependencies | |
| timeout-minutes: 8 | |
| # No lockfile is committed in this repository, so use a non-frozen install. | |
| run: bun install | |
| - name: Run database migrations | |
| run: bun run db:migrate | |
| - name: Cache Next.js build cache | |
| uses: actions/cache@v5 | |
| with: | |
| path: ${{ github.workspace }}/.next/cache | |
| key: ${{ runner.os }}-nextjs-${{ hashFiles('package.json', '.bun-version') }}-${{ hashFiles('src/**/*.js', 'src/**/*.jsx', 'src/**/*.ts', 'src/**/*.tsx', 'next.config.*', 'tsconfig.json', 'postcss.config.*') }} | |
| restore-keys: | | |
| ${{ runner.os }}-nextjs-${{ hashFiles('package.json', '.bun-version') }}- | |
| - name: Build application | |
| timeout-minutes: 15 | |
| run: bun run build | |
| - name: Start server (background) | |
| run: | | |
| bun run start & | |
| echo $! > server.pid | |
| sleep 15 # 等待服务启动 | |
| - name: Wait for server ready | |
| run: | | |
| timeout 60 bash -c 'until curl -f http://localhost:13500/api/actions/health && curl -f http://localhost:13500/api/v1/health; do sleep 2; done' | |
| - name: Run E2E API tests | |
| run: bun run test:e2e | |
| env: | |
| API_BASE_URL: http://localhost:13500/api/actions | |
| API_E2E_BASE_URL: http://localhost:13500/api/v1 | |
| TEST_ADMIN_TOKEN: test-admin-token-for-ci | |
| AUTO_CLEANUP_TEST_DATA: true | |
| - name: Stop server | |
| if: always() | |
| run: | | |
| if [ -f server.pid ]; then | |
| kill $(cat server.pid) || true | |
| fi | |
| # ==================== 测试结果汇总 ==================== | |
| test-summary: | |
| name: 📊 Test Summary | |
| runs-on: ubuntu-latest | |
| needs: [quality, unit-tests, integration-tests, api-tests] | |
| if: always() | |
| steps: | |
| - name: Check test results | |
| run: | | |
| if [ "${{ needs.quality.result }}" != "success" ] || \ | |
| [ "${{ needs.unit-tests.result }}" != "success" ] || \ | |
| [ "${{ needs.integration-tests.result }}" != "success" ] || \ | |
| [ "${{ needs.api-tests.result }}" != "success" ]; then | |
| echo "❌ 部分测试失败" | |
| exit 1 | |
| else | |
| echo "✅ 所有测试通过" | |
| fi | |
| - name: Create summary | |
| if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository | |
| uses: actions/github-script@v9 | |
| with: | |
| script: | | |
| const summary = `## 🧪 测试结果 | |
| | 测试类型 | 状态 | | |
| |---------|------| | |
| | 代码质量 | ${{ needs.quality.result == 'success' && '✅' || '❌' }} | | |
| | 单元测试 | ${{ needs.unit-tests.result == 'success' && '✅' || '❌' }} | | |
| | 集成测试 | ${{ needs.integration-tests.result == 'success' && '✅' || '❌' }} | | |
| | API 测试 | ${{ needs.api-tests.result == 'success' && '✅' || '❌' }} | | |
| **总体结果**: ${{ (needs.quality.result == 'success' && needs.unit-tests.result == 'success' && needs.integration-tests.result == 'success' && needs.api-tests.result == 'success') && '✅ 所有测试通过' || '❌ 部分测试失败' }} | |
| `; | |
| github.rest.issues.createComment({ | |
| issue_number: context.issue.number, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| body: summary | |
| }); |