heavy-duty-watcher/scripts/self-test.sh
grok-reviewer-andresmgsl 8d6f902209 Harden watcher: shared config, dual forge backends, safer discovery
- Add scripts/lib/common.sh (ORG/BOT/FORGE_BACKEND, logging, process_running)
- discover.sh: dedupe review-requested+assignee PRs; JSON+summary formats
- discover.sh: FORGE_BACKEND=forgejo via Forgejo API + stoke token
- Fix poll-loop process detection (basename, not install path)
- health-check: jq-safe JSON; backend-aware auth (gh or stoke)
- install-live: require rsync/jq/tmux; soft-warn missing gh/stoke
- self-test.sh offline smoke; restore/poll-once use shared config
- Docs: Forgejo table, watcher.env, OPERATIONS troubleshooting
2026-07-22 23:23:33 +00:00

79 lines
1.7 KiB
Bash
Executable file

#!/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