name: TypeScript Tests

on:
  push:
    branches:
      - "main"
    paths:
      - "**/*.ts"
      - "**/package.json"
      - '.github/workflows/jest.yml'
  pull_request:
    branches:
      - "main"
      - "dev"
    paths:
      - "**/*.ts"
      - "**/package.json"
      - '.github/workflows/jest.yml'

jobs:
  test:
    runs-on: ubuntu-latest
    permissions:
      contents: read
    strategy:
      matrix:
        node-version:
          - "20"

    concurrency:
      group: ci-task-lock
      cancel-in-progress: false

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: ${{ matrix.node-version }}
          cache: 'npm'
          cache-dependency-path: './src_ts/package-lock.json'

      - name: Install dependencies
        working-directory: ./src_ts
        run: |
          npm ci

      - name: Run linter
        working-directory: ./src_ts
        run: |
          npm run lint

      - name: Run build
        working-directory: ./src_ts
        run: |
          npm run build

      - name: Run tests
        working-directory: ./src_ts
        run: |
          npm test
        env:
          ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
          GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
          OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
          ZAI_API_KEY: ${{ secrets.ZAI_API_KEY }}
          MOONSHOT_API_KEY: ${{ secrets.MOONSHOT_API_KEY }}
          DEEPSEEK_API_KEY: ${{ secrets.DEEPSEEK_API_KEY }}
          MODELVERSE_API_KEY: ${{ secrets.MODELVERSE_API_KEY }}
          OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }}
          SILICONFLOW_API_KEY: ${{ secrets.SILICONFLOW_API_KEY }}
          BEDROCK_API_KEY: ${{ secrets.BEDROCK_API_KEY }}
          VERTEX_API_KEY: ${{ secrets.VERTEX_API_KEY }}
