name: UI Sweep (full discovery)

on:
  push:
    branches: [ui-sweep-run]
  workflow_dispatch:

concurrency:
  group: ui-sweep-full-${{ github.ref }}
  cancel-in-progress: true

permissions:
  actions: read
  contents: read

env:
  BUILD_NO_LOCK: '1'
  NODE_OPTIONS: --max-old-space-size=6144

jobs:
  full-sweep:
    name: UI sweep — full matrix
    runs-on: [self-hosted, linux, x64, multideal-gate]
    timeout-minutes: 120
    env:
      GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      NEON_API_KEY: ${{ secrets.NEON_CI_API_KEY }}
      NEON_PROJECT_ID: ${{ secrets.NEON_CI_PROJECT_ID }}
      NEON_MAIN_BRANCH_ID: ${{ secrets.NEON_CI_FACTORY_BRANCH_ID }}
      SOURCE_DATABASE_URL: ${{ secrets.DATABASE_URL }}
      JWT_SECRET: ${{ secrets.JWT_SECRET }}
      PII_KEY: ${{ secrets.PII_KEY }}
      PUBLIC_TURNSTILE_SITE_KEY: ${{ vars.TURNSTILE_SITE_KEY }}
      E2E_SECRET: ${{ secrets.E2E_SECRET }}
      RENDER_DO_SECRET: ${{ secrets.RENDER_DO_SECRET }}
    steps:
      - uses: actions/checkout@v7
        with:
          fetch-depth: 0
      - uses: ./.github/actions/setup
        with:
          github-packages-token: ${{ secrets.GH_PKG_READ_TOKEN }}
      - working-directory: apps/web
        run: pnpm exec playwright install chromium
      - name: Reset findings log
        working-directory: apps/web
        run: ': > tests/e2e/sweep/findings-log.jsonl; : > tests/e2e/sweep/nav-fingerprints.jsonl; rm -f tests/e2e/sweep/sweep-run-complete.json'
      - name: Full sweep
        id: sweep
        env:
          SWEEP_SKIP_BUILD: '1'
        run: bash apps/web/scripts/cpu-limit.sh bash apps/web/scripts/ci-with-disposable-factory-pg.sh pnpm sweep:full
      - name: Fold nav-consistency findings
        if: always()
        working-directory: apps/web
        run: node scripts/sweep-nav-consistency.mjs
      - name: Upload sweep findings
        if: always()
        uses: actions/upload-artifact@v7
        with:
          name: sweep-findings
          path: |
            apps/web/tests/e2e/sweep/findings-log.jsonl
            apps/web/tests/e2e/sweep/nav-fingerprints.jsonl
            apps/web/tests/e2e/sweep/sweep-run-complete.json
          if-no-files-found: warn
          retention-days: 14
