#!/usr/bin/env bash
set -euo pipefail

MOD="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
RUNNER="$MOD/test/run-all.sh"

[ -x "$RUNNER" ] || { echo "FAIL buildbox runner missing or not executable: $RUNNER" >&2; exit 1; }
[ "$(jq -r '.scripts.test // empty' "$MOD/package.json")" = "bash test/run-all.sh" ] \
  || { echo "FAIL package test script does not invoke buildbox runner" >&2; exit 1; }

listed=$(bash "$RUNNER" --list)
while IFS= read -r suite; do
  [ "$suite" = run-all.sh ] && continue
  grep -Fq "$suite"$'\t' <<<"$listed" \
    || { echo "FAIL runner does not classify $suite" >&2; exit 1; }
done < <(find "$MOD/test" -maxdepth 1 -type f -name '*.sh' -printf '%f\n' | sort)

echo "buildbox runner wiring test passed"
