name: CI

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

jobs:
  build:
    runs-on: ubuntu-latest

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

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version-file: ".nvmrc"

      - name: Install dependencies
        # Delete package-lock.json to work around npm bug with platform-specific optional deps
        # See: https://github.com/npm/cli/issues/4828
        run: rm -f package-lock.json && npm install

      # Explicit build step before lint/test to ensure build artifacts are fresh
      # Note: npm ci runs 'prepare' which also builds, but we rebuild here to
      # guarantee a clean build before tests run
      - name: Build package
        run: npm run build

      - name: Run linter
        run: npm run lint

      - name: Run tests
        run: npm test
