name: e2e-full

# Boots the full explorer stack (docker-compose deps + backend + frontend)
# and runs the Playwright full-stack smoke spec against it. Not on every
# PR (too expensive) — runs on:
#
#   * workflow_dispatch           (manual)
#   * pull_request when the 'run-e2e-full' label is applied
#   * nightly at 04:00 UTC
#
# Screenshots from every route are uploaded as a build artefact so
# reviewers can eyeball the render without having to boot the stack.

on:
  workflow_dispatch:
  pull_request:
    types: [labeled, opened, synchronize, reopened]
  schedule:
    - cron: '0 4 * * *'

jobs:
  e2e-full:
    if: >
      github.event_name == 'workflow_dispatch' ||
      github.event_name == 'schedule' ||
      (github.event_name == 'pull_request' &&
       contains(github.event.pull_request.labels.*.name, 'run-e2e-full'))
    runs-on: ubuntu-latest
    timeout-minutes: 30

    steps:
      - uses: actions/checkout@v4
        with:
          submodules: recursive

      - uses: actions/setup-go@v5
        with:
          go-version: '1.23.x'

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

      - name: Install root Playwright dependency
        run: npm ci --no-audit --no-fund --prefix .

      - name: Run full-stack e2e
        env:
          JWT_SECRET: ${{ secrets.JWT_SECRET || 'ci-ephemeral-jwt-secret-not-for-prod' }}
          CSP_HEADER: "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; connect-src 'self' http://localhost:8080 ws://localhost:8080"
        run: make e2e-full

      - name: Upload screenshots
        if: always()
        uses: actions/upload-artifact@v4
        with:
          name: e2e-screenshots
          path: test-results/screenshots/
          if-no-files-found: warn

      - name: Upload playwright report
        if: always()
        uses: actions/upload-artifact@v4
        with:
          name: playwright-report
          path: |
            playwright-report/
            test-results/
          if-no-files-found: warn
