name: CI

on:
  push:
    branches: [ main, dev/** ]
  pull_request:
    branches: [ main ]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Use Node.js 20
        uses: actions/setup-node@v4
        with:
          node-version: 20
          cache: 'npm'
          # 指定锁文件路径以启用 npm 缓存（仓库根部无 lockfile）
          cache-dependency-path: 'server/package-lock.json'

      - name: Install dependencies (server)
        working-directory: server
        run: npm ci

      - name: Lint (server)
        working-directory: server
        run: npm run lint -- --max-warnings=0

      - name: Validate OpenAPI
        working-directory: server
        run: npm run openapi:validate

      - name: Run tests (server)
        working-directory: server
        env:
          NODE_ENV: test
        run: npm test -- --ci
