name: Web E2E

on:
  push:
    branches: [master]
    paths:
      - 'solitaire_server/web/**'
      - 'solitaire_server/src/**'
      - 'solitaire_server/e2e/**'
      - 'solitaire_wasm/**'
      - 'solitaire_core/**'
      - 'Cargo.toml'
      - 'Cargo.lock'
      - '.gitea/workflows/web-e2e.yml'
  workflow_dispatch:

jobs:
  web-e2e:
    runs-on: ubuntu-latest

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

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable

      - name: Cache cargo build
        uses: Swatinem/rust-cache@v2

      # Prebuild the server so Playwright's `webServer` (which runs
      # `cargo run -p solitaire_server`) starts from a compiled binary instead
      # of cold-compiling the whole dependency graph (axum/sqlx/reqwest) inside
      # its 120s startup window — the timeout that was failing every run.
      # SQLX_OFFLINE uses the checked-in `.sqlx/` query cache (no live DB).
      - name: Prebuild server
        env:
          SQLX_OFFLINE: 'true'
        run: cargo build -p solitaire_server --quiet

      - name: Set up Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '20'
          cache: 'npm'
          cache-dependency-path: solitaire_server/e2e/package-lock.json

      - name: Install e2e dependencies
        working-directory: solitaire_server/e2e
        run: npm ci

      - name: Install Playwright browser
        working-directory: solitaire_server/e2e
        run: npx playwright install --with-deps chromium

      - name: Run web e2e tests
        working-directory: solitaire_server/e2e
        run: npm test

      - name: Run cycle regression gate
        working-directory: solitaire_server/e2e
        run: npm run review:cycles:regression
