name: CI

on:
  push:
    branches:
      - main
  pull_request:

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Setup Node
        uses: actions/setup-node@v4
        with:
          node-version: "22"
          cache: "npm"

      - name: Install deps
        run: npm ci --ignore-scripts

      - name: Static syntax checks
        run: |
          node --check src/server.js
          node --check src/mcp-server.js
          node --check src/layout.js
          node --check src/compile.js
          node --check frontend/app.js

      - name: Run tests
        run: npm test

      - name: React path quality stubs
        run: npm run frontend:react:check

      - name: Install Playwright browsers
        run: npx playwright install chromium

      - name: Run browser regression
        run: npm run test:ui

      - name: UI metrics report (always)
        if: always()
        run: |
          echo "UI metrics report:"
          cat output/playwright/ui-metrics-report.json || true

      - name: Browser artifacts listing (always)
        if: always()
        run: |
          echo "Playwright output:"
          ls -R output/playwright || true
