#!/usr/bin/env bash set -euo pipefail ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" require_approval=1 if [[ "${APPROVE:-}" != "1" && $require_approval -eq 1 ]]; then echo "[verify] blocked: verification commands are policy-gated." echo "Run with APPROVE=1 ./verify.sh " exit 2 fi show_help() { cat <<'EOF_HELP' usage: ./verify.sh Targets: unit lint typecheck all EOF_HELP } run_if() { local label="$1" local cmd="$2" echo "[verify] $label" if eval "$cmd"; then return 0 fi return 1 } run_unit() { if [[ -f "$ROOT_DIR/package.json" ]] && jq -e '.scripts.test' "$ROOT_DIR/package.json" >/dev/null 2>&1; then run_if unit "cd '$ROOT_DIR' && npm run -s test" return fi if [[ -x "$ROOT_DIR/vendor/bin/phpunit" ]]; then run_if unit "cd '$ROOT_DIR' && ./vendor/bin/phpunit" return fi if [[ -x "$ROOT_DIR/bin/phpunit" ]]; then run_if unit "cd '$ROOT_DIR' && ./bin/phpunit" return fi if [[ -x "$ROOT_DIR/node_modules/.bin/jest" ]]; then run_if unit "cd '$ROOT_DIR' && ./node_modules/.bin/jest" return fi echo "[verify] no unit target auto-detected" return 2 } run_lint() { if [[ -f "$ROOT_DIR/package.json" ]] && jq -e '.scripts.lint' "$ROOT_DIR/package.json" >/dev/null 2>&1; then run_if lint "cd '$ROOT_DIR' && npm run -s lint" return fi if [[ -x "$ROOT_DIR/vendor/bin/pint" ]]; then run_if lint "cd '$ROOT_DIR' && ./vendor/bin/pint --test" return fi if [[ -f "$ROOT_DIR/package.json" ]] && jq -e '.scripts.style' "$ROOT_DIR/package.json" >/dev/null 2>&1; then run_if lint "cd '$ROOT_DIR' && npm run -s style" return fi echo "[verify] no lint target auto-detected" return 2 } run_typecheck() { if [[ -f "$ROOT_DIR/package.json" ]] && jq -e '.scripts.typecheck' "$ROOT_DIR/package.json" >/dev/null 2>&1; then run_if typecheck "cd '$ROOT_DIR' && npm run -s typecheck" return fi if [[ -x "$ROOT_DIR/node_modules/.bin/tsc" ]]; then run_if typecheck "cd '$ROOT_DIR' && ./node_modules/.bin/tsc -p ." return fi if [[ -x "$ROOT_DIR/.venv/bin/mypy" ]]; then run_if typecheck "cd '$ROOT_DIR' && .venv/bin/mypy ." return fi echo "[verify] no typecheck target auto-detected" return 2 } case "${1:-help}" in unit) run_unit ;; lint) run_lint ;; typecheck) run_typecheck ;; all) run_unit run_lint run_typecheck ;; help|*) show_help ;; esac