← back to George Gmail
check-body-regression.sh
73 lines
#!/bin/bash
# Weekly check: are George's recent sends arriving with non-empty bodies?
# Regression target: buildRawMessage in server.js (fixed 2026-05-01).
# If any of the 5 most-recent sends has body length 0, alert Steve via George.
set -u
GEORGE="http://localhost:9850"
AUTH="admin:DWSecure2024!"
LOG="${HOME}/Library/Logs/george-body-check.log"
ts() { date '+%Y-%m-%d %H:%M:%S'; }
log() { echo "[$(ts)] $*" >> "$LOG"; }
log "=== body-regression check start ==="
if ! curl -s -m 5 -u "$AUTH" "$GEORGE/api/health" | grep -q '"status":"ready"'; then
log "george unreachable or unhealthy — skipping (not a regression)"
exit 0
fi
# buildRawMessage was fixed at this UTC timestamp (2026-05-01 19:00 UTC).
# Earlier sends had legacy empty-body bug — those are not regressions, skip.
FIX_CUTOFF_MS=1777662000000
ids=$(curl -s -u "$AUTH" "$GEORGE/api/search?q=in:sent&limit=10" \
| /usr/bin/python3 -c "import json,sys; d=json.load(sys.stdin); print('\n'.join(m['id'] for m in (d.get('messages') or [])[:10]))")
if [ -z "$ids" ]; then
log "no recent sent messages found — exiting clean"
exit 0
fi
bad=()
checked=0
for id in $ids; do
read -r blen mdate <<< "$(curl -s -u "$AUTH" "$GEORGE/api/messages/$id" \
| /usr/bin/python3 -c "import json,sys; d=json.load(sys.stdin); print(len(d.get('body') or ''), d.get('internalDate') or 0)")"
if [ "$mdate" -lt "$FIX_CUTOFF_MS" ]; then
log " $id body=$blen SKIP (pre-fix, $mdate)"
continue
fi
log " $id body=$blen"
checked=$((checked+1))
if [ "$blen" = "0" ]; then bad+=("$id"); fi
done
log "checked $checked post-fix messages"
if [ "${#bad[@]}" -eq 0 ]; then
log "all healthy — no alert sent"
exit 0
fi
log "REGRESSION: empty-body messages: ${bad[*]}"
body_html="<p>George body-empty regression detected — the <code>buildRawMessage</code> fix from 2026-05-01 may have been reverted.</p><p>Empty-body sends:</p><ul>"
for id in "${bad[@]}"; do
body_html+="<li><code>$id</code></li>"
done
body_html+="</ul><p>Source: <code>~/Projects/george-gmail/server.js</code> (function <code>buildRawMessage</code>, ~line 789).</p><p>The <code>filter(Boolean)</code> bug was: it stripped the empty-string element that should be the blank line between MIME headers and the base64 body, so Gmail rendered no body.</p>"
payload=$(/usr/bin/python3 -c "
import json
print(json.dumps({
'to': 'steveabramsdesigns@gmail.com',
'subject': 'George body-empty regression detected',
'body': '''$body_html'''
}))
")
resp=$(curl -s -u "$AUTH" -X POST "$GEORGE/api/send" \
-H 'Content-Type: application/json' -d "$payload")
log "alert sent: $resp"