name: E2E Smoke

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

jobs:
  smoke:
    name: Playwright dashboard + SSE
    runs-on: ubuntu-latest
    env:
      DEMO_MODE: "true"

    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-node@v4
        with:
          node-version: "20"
          cache: npm
          cache-dependency-path: |
            package-lock.json
            web/package-lock.json

      - run: npm ci
      - run: npm --prefix web ci
      - run: npm run build

      - name: Start server
        run: npm start &

      - name: Wait for API
        run: |
          for i in $(seq 1 45); do
            curl -sf http://localhost:8080/api/health > /dev/null && echo "Ready after ${i}s" && exit 0
            sleep 1
          done
          echo "::error::Server did not become ready in 45s" && exit 1

      - run: npx playwright install --with-deps chromium

      - name: Run smoke tests
        run: npm run test:e2e
