name: test

# Runs the Node test suite on every PR and on pushes to main. Originally
# Ubuntu-only (#198): PR checks were Cursor Bugbot + Security, neither of
# which runs `npm test`, so a green PR did NOT mean the tests passed.
#
# This workflow now also runs the suite on Windows + macOS via a second job
# (test-cross). #198 explicitly flagged Windows / macOS as a follow-up: the
# suite still has Linux-specific assumptions (symlink reliance, hard-coded
# ~/.volta layout, POSIX-style path equality) that would fail on those
# hosts. test-cross runs on PRs in **advisory** mode (continue-on-error)
# so those red signals are visible to reviewers without blocking merge
# while the suite is being made hermetic. Each fix can flip its tests
# from "red on Win/Mac" to "green on Win/Mac" incrementally. Once the
# remaining failures are cleaned up, drop `continue-on-error: true` and
# add `test-cross` to required checks to make cross-platform green a
# hard merge gate.
#
# main pushes skip test-cross to keep private-repo billing predictable
# (macos-latest is 10x and windows-latest is 2x the ubuntu rate).

on:
  pull_request:
  push:
    branches: [main]

permissions:
  contents: read

concurrency:
  group: test-${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

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

      - uses: actions/setup-node@v4
        with:
          node-version: '22' # engines: node >=22.12
          cache: npm

      - name: Install dependencies
        run: npm ci

      - name: Run tests (node --test)
        run: npm test

  test-cross:
    # Advisory cross-platform run: PR-only (skips main push to save billing),
    # continue-on-error so a known Win/Mac regression does not block merge
    # while the suite is being hardened. Reviewers still see the result and
    # can opt-in to wait for a fix on a per-PR basis.
    if: github.event_name == 'pull_request'
    strategy:
      fail-fast: false
      matrix:
        os: [windows-latest, macos-latest]
    runs-on: ${{ matrix.os }}
    continue-on-error: true
    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-node@v4
        with:
          node-version: '22'
          cache: npm

      - name: Install dependencies
        run: npm ci

      - name: Run tests (node --test)
        run: npm test
