#!/usr/bin/env bash # Live M4 smoke test. Run from repo root: # bash scripts/m4_smoke.sh # # Walks through the 5 scenarios in M4_VERIFICATION.md: # # Step 2 — happy path: 1 alert via MQTT → 2 deliveries # Step 3 — 5 alerts, mixed severity + 30% dedupe → 10 deliveries # Step 4 — bad signature (correct user, wrong HMAC) → broker accepts, # ingestd rejects, no delivery, bad_signature counter ticks # Step 5 — ACL violation (prom-prod user → globex's topic) → broker # denies the publish, no delivery, no ingestd counter tick # Step 6 — non-JSON body → invalid_json counter ticks # # The script assumes the loadgen-mqtt binary is built at /tmp/loadgen-mqtt # (run `cd loadgen && go build -o /tmp/loadgen-mqtt ./cmd/mqtt`). The # failure-path test binaries (m4_badsig, m4_acl_violation, m4_badjson) # are auto-built on first run; they live in /tmp and are reused on # subsequent runs. # # Exit code is the number of failed checks. set -e cd "$(dirname "$0")/.." PG="docker exec -i broad-announce-postgres-1 psql -U ba -d ba -A -t" INGESTD_METRICS=http://localhost:8800/metrics BROKER=tcp://localhost:1883 SRC=acme-001:prom-prod:s3cret-acme SRC_USER=prom-prod-acme-001 fails=0 pass() { echo " ✅ $*"; } fail() { echo " ❌ $*"; fails=$((fails+1)); } reset_state() { $PG -c "UPDATE individuals SET telegram_chat_id = NULL, telegram_user_id = NULL, telegram_invite_code = 'acme-bob-002' WHERE id = 'ind-acme-002';" >/dev/null $PG -c "UPDATE individuals SET telegram_chat_id = NULL, telegram_user_id = NULL WHERE id = 'ind-acme-003';" >/dev/null $PG -c "UPDATE subscriptions SET min_severity = 'critical' WHERE individual_id = 'ind-acme-002' AND source_id = 'prom-prod';" >/dev/null $PG -c "TRUNCATE deliveries;" >/dev/null curl -sS -X POST http://localhost:8830/admin/reset >/dev/null docker compose restart telegramd >/dev/null for i in 1 2 3 4 5 6 7 8 9 10; do if curl -sS http://localhost:8822/health 2>/dev/null | grep -q '"status":"ok"'; then sleep 1 break fi sleep 1 done } mqtt_counter() { # $1 = result label # Reads /metrics and returns the integer value of # ba_ingestd_mqtt_messages_total{result="