#!/usr/bin/env bash # scripts/check.sh — one-command health report for the AWS deployment. # # Written for an operator working from a phone terminal: five separate # commands is five chances to mistype on a small keyboard, so this is the # single "how is my bot doing?" answer. Read-only — it never restarts, # edits or trades anything. # # bash scripts/check.sh # # Nothing here prints a secret: the status endpoint carries no keys, the # token is read into a variable for the curl call and never echoed, and the # log tail goes through the bot's own redaction filter (modules/logger.py) # before it is ever written to disk. cd "$(dirname "$0")/.." || exit 1 SERVICE=garden-angel-terminal echo "════════ SERVICE ════════" STATE=$(systemctl is-active "$SERVICE" 2>/dev/null) echo "state: $STATE" if [ "$STATE" != "active" ]; then echo "⚠️ NOT RUNNING — recent failures:" sudo journalctl -u "$SERVICE" -n 15 --no-pager 2>/dev/null | tail -15 fi systemctl show "$SERVICE" -p NRestarts 2>/dev/null echo "uptime: $(systemctl show "$SERVICE" -p ActiveEnterTimestamp --value 2>/dev/null)" echo echo "════════ BOT STATUS ════════" PORT=$(grep -m1 '^BOT_API_PORT=' .env 2>/dev/null | cut -d= -f2-) PORT=${PORT:-8081} curl -s --max-time 5 "localhost:${PORT}/status" \ | python3 -c 'import json,sys try: d = json.load(sys.stdin) except Exception: print(" (no response — API not up yet)"); raise SystemExit for k, v in d.items(): print(f" {k:20} {v}")' 2>/dev/null || echo " (API not responding)" echo echo "════════ TRADE JOURNAL ════════" if [ -f data/trade_journal.csv ]; then venv/bin/python scripts/journal.py 2>/dev/null | sed 's/^/ /' else echo " no journal yet — created on the first scan cycle" fi echo echo "════════ RECENT ACTIVITY ════════" LOGF=$(grep -m1 '^LOG_FILE=' .env 2>/dev/null | cut -d= -f2-) if [ -n "$LOGF" ] && [ -f "$LOGF" ]; then grep -iE "signal|executed|scan|profit|error|warning" "$LOGF" 2>/dev/null \ | tail -12 | cut -c1-160 | sed 's/^/ /' else sudo journalctl -u "$SERVICE" -n 12 --no-pager 2>/dev/null | cut -c1-160 | sed 's/^/ /' fi echo echo "════════ RESOURCES ════════" echo " disk: $(df -h . | awk 'NR==2 {print $4" free of "$2}')" echo " mem: $(free -h | awk 'NR==2 {print $7" available of "$2}')" echo echo "Deeper checks: bash scripts/check.sh --speed" if [ "$1" = "--speed" ]; then echo echo "════════ SPEEDTEST ════════" set -a; . ./.env 2>/dev/null; set +a venv/bin/python scripts/speedtest.py fi if [ "$1" = "--tests" ]; then echo echo "════════ REGRESSION TESTS ════════" # v1.70 — A FAILING TEST NOW FAILS THIS SCRIPT. # # These three lines used to be `... | tail -2` and `... | grep -E`. # In a pipeline the shell reports the exit status of the LAST command, # so `grep` matching its own pattern returned 0 and the red ❌ it had # just printed was thrown away. Every run of `check.sh --tests` exited # 0 no matter what — the tests could print failure but could not BE a # failure, which is the one thing a regression suite exists to do. # # This is the same class of bug scripts/test_go_live.sh was written to # catch in go_live.sh (printing ✅ after a warning), living in the # runner that was supposed to be catching it. # # Output is still filtered — the point of the filtering was a readable # summary on a phone, and that is worth keeping — but now via a temp # file so the test's own status survives, and every failure is # re-printed IN FULL rather than reduced to one line. _test_failures=0 _run_test() { local script="$1" filter="$2" out out="$(mktemp)" if venv/bin/python "$script" >"$out" 2>&1; then eval "$filter" <"$out" else _test_failures=$((_test_failures + 1)) echo echo "❌ FAILED: $script" sed 's/^/ /' "$out" echo fi rm -f "$out" } _run_test scripts/test_blackout.py "tail -2" _run_test scripts/test_pipeline.py "grep -E '✅ all|❌' || true" _run_test scripts/test_signal_quality.py "grep -E '✅ all|❌' || true" _run_test scripts/test_hotpath.py "grep -E '✅ all|❌' || true" _run_test scripts/test_ws_state.py "grep -E '✅ all|❌' || true" _run_test scripts/test_feed_client.py "grep -E '✅ all|❌' || true" _run_test scripts/test_truth.py "grep -E '✅ all|❌' || true" _run_test scripts/test_agent.py "grep -E '✅ all|❌' || true" _run_test scripts/test_scripts.py "grep -E '✅ all|❌' || true" _run_test scripts/test_limiter.py "grep -E '✅ all|❌' || true" _run_test scripts/test_ai_model.py "grep -E '✅ all|❌' || true" echo if [ "$_test_failures" -gt 0 ]; then echo "❌ $_test_failures test script(s) FAILED — see full output above" exit 1 fi echo "✅ all test scripts passed" fi if [ "$1" = "--net" ]; then echo bash scripts/latency_audit.sh fi