# Run tests by Harnessed CI
name: harness-ci

on:
  workflow_dispatch:
    inputs:
      testsuite:
        description: 'Run specific test suite (leave empty to run all)'
        type: choice
        options:
          - ''
          - 'suite/'
          - 'suitep2p/'
        default: ''

permissions:
  contents: read

jobs:
  test:
    runs-on: ubuntu-latest
    timeout-minutes: 30
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          submodules: recursive

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '24.x'
          cache: 'npm'

      - name: Install dependencies
        run: npm ci

      - name: Install test dependencies (Playwright Chromium)
        run: npm run test:install-dependencies

      - name: Start test services (CouchDB)
        run: npm run test:docker-couchdb:start
        if: ${{ inputs.testsuite == '' || inputs.testsuite == 'suite/' }}
      - name: Start test services (MinIO)
        run: npm run test:docker-s3:start
        if: ${{ inputs.testsuite == '' || inputs.testsuite == 'suite/' }}
      - name: Start test services (Nostr Relay + WebPeer)
        run: npm run test:docker-p2p:start
        if: ${{ inputs.testsuite == '' || inputs.testsuite == 'suitep2p/' }}
      - name: Run tests suite
        if: ${{ inputs.testsuite == '' || inputs.testsuite == 'suite/' }}
        env:
          CI: true
        run: npm run test suite/
      - name: Run P2P tests suite
        if: ${{ inputs.testsuite == '' || inputs.testsuite == 'suitep2p/' }}
        env:
          CI: true
        run: npm run test:p2p
      - name: Stop test services (CouchDB)
        run: npm run test:docker-couchdb:stop
        if: ${{ inputs.testsuite == '' || inputs.testsuite == 'suite/' }}
      - name: Stop test services (MinIO)
        run: npm run test:docker-s3:stop
        if: ${{ inputs.testsuite == '' || inputs.testsuite == 'suite/' }}
      - name: Stop test services (Nostr Relay + WebPeer)
        run: npm run test:docker-p2p:stop
        if: ${{ inputs.testsuite == '' || inputs.testsuite == 'suitep2p/' }}