name: Tests

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

jobs:
  unit:
    name: Unit Tests
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      
      - uses: actions/setup-node@v4
        with:
          node-version: '20'
          cache: 'npm'
      
      - name: Install dependencies
        run: npm ci

      - name: Lint runtime console usage
        run: npm run lint:console
      
      - name: Build
        run: npm run build
      
      - name: Run unit tests
        run: npm run test:run

  e2e:
    name: E2E Tests
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      
      - uses: actions/setup-node@v4
        with:
          node-version: '20'
          cache: 'npm'
      
      - name: Install dependencies
        run: npm ci

      - name: Lint runtime console usage
        run: npm run lint:console
      
      - name: Build
        run: npm run build
      
      - name: Run e2e tests
        # Tests requiring secrets (bot.e2e, models.e2e) skip gracefully via describe.skipIf.
        # OpenAI SDK compat tests always run (no secrets needed, uses mock gateway).
        run: npm run test:e2e
        env:
          LETTA_API_KEY: ${{ secrets.LETTA_API_KEY }}
          LETTA_E2E_AGENT_ID: ${{ secrets.LETTA_E2E_AGENT_ID }}

  docker:
    name: Docker Build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Build Docker image
        # Ensures Dockerfile build path stays healthy on main and PRs.
        run: docker build --tag lettabot:test .
