name: Node.js CI

permissions:
  contents: read

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

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '18'
          cache: npm
      - name: Install dependencies
        run: npm ci
      - name: Guardrails (no KYC / no surveillance)
        run: |
          npm run lint:guardrails
          npm run lint:values
          npm run lint:paid-logging
          npm run lint:privileged-surface
          npm run lint:events-surface
          npm run lint:external-calls
          npm run lint:storage-growth
      - name: Build TypeScript (root only, excludes base-mini-app)
        run: npm run build:test
      - name: Run tests
        env:
          CI: true
          VAULTFIRE_TEST_QUIET: "1"
        run: npm test
      - name: Upload coverage report
        if: always()
        uses: actions/upload-artifact@v4
        with:
          name: jest-coverage
          path: coverage
          if-no-files-found: ignore
      - name: Upload snapshot artifacts
        if: always()
        uses: actions/upload-artifact@v4
        with:
          name: jest-snapshots
          path: |
            **/__snapshots__/**
          if-no-files-found: ignore
