#!/usr/bin/env bash # Offline smoke checks for the watcher tree (no network required for syntax). set -euo pipefail ROOT="$(cd "$(dirname "$0")/.." && pwd)" cd "${ROOT}" fail=0 echo "== bash -n ==" while IFS= read -r -d '' f; do if bash -n "${f}"; then echo " ok ${f}" else echo " FAIL ${f}" fail=1 fi done < <(find scripts -name '*.sh' -print0 | sort -z) echo "== required files ==" for f in \ POLL_INSTRUCTIONS.md \ README.md \ config/state.template.json \ config/watcher.env.example \ scripts/lib/common.sh \ scripts/discover.sh \ scripts/poll-once.sh \ scripts/poll-loop.sh \ scripts/health-check.sh \ scripts/health-loop.sh \ scripts/restore.sh \ scripts/install-live.sh do if [[ -f "${f}" ]]; then echo " ok ${f}" else echo " FAIL missing ${f}" fail=1 fi done echo "== source common.sh ==" # shellcheck source=lib/common.sh if WATCHER_DIR="${ROOT}" source "${ROOT}/scripts/lib/common.sh" \ && [[ -n "${ORG:-}" && -n "${BOT_LOGIN:-}" ]]; then echo " ok ORG=${ORG} BOT_LOGIN=${BOT_LOGIN} FORGE_BACKEND=${FORGE_BACKEND}" else echo " FAIL sourcing common.sh" fail=1 fi echo "== state template is valid JSON ==" if command -v jq >/dev/null 2>&1; then if jq empty config/state.template.json; then echo " ok state.template.json" else echo " FAIL state.template.json" fail=1 fi else echo " skip jq not installed" fi echo "== discover --help-ish (dry: unknown backend should fail cleanly) ==" if FORGE_BACKEND=not-a-backend FORMAT=json bash scripts/discover.sh 2>/dev/null; then echo " FAIL expected non-zero for bad backend" fail=1 else echo " ok bad backend rejected" fi if (( fail == 0 )); then echo echo "self-test: PASS" exit 0 fi echo echo "self-test: FAIL" exit 1