Lab bootstrap scripts exercise CRM PHP, Node redirector, health endpoints, and MySQL analytics on 10.10.50.17. Bearer auth is checked before session dev-login; redirector reads CRM_API_URL at fetch time so dotenv applies correctly. Paperclip-Task: BIT-24693 Paperclip-Run: 3467cbf0-a91f-4cb0-808a-ccb043de28d3 Co-authored-by: Cursor <[email protected]>
115 lines
3.4 KiB
Bash
Executable File
115 lines
3.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Smoke test MoneyFlix lab stack (BIT-24693)
|
|
set -euo pipefail
|
|
|
|
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
|
ENV_FILE="${MONEYFLIX_LAB_ENV:-$ROOT/.env.lab}"
|
|
|
|
if [[ ! -f "$ENV_FILE" ]]; then
|
|
echo "Run bootstrap first: bash tools/lab/bootstrap.sh" >&2
|
|
exit 1
|
|
fi
|
|
|
|
# shellcheck disable=SC1090
|
|
source "$ENV_FILE"
|
|
|
|
PASS=0
|
|
FAIL=0
|
|
RESULTS=()
|
|
|
|
check() {
|
|
local name=$1
|
|
local cmd=$2
|
|
local expect=$3
|
|
local out
|
|
out="$(eval "$cmd" 2>/dev/null || true)"
|
|
if echo "$out" | grep -qE "$expect"; then
|
|
PASS=$((PASS + 1))
|
|
RESULTS+=("PASS $name")
|
|
echo "PASS $name"
|
|
else
|
|
FAIL=$((FAIL + 1))
|
|
RESULTS+=("FAIL $name")
|
|
echo "FAIL $name"
|
|
echo " expected pattern: $expect"
|
|
echo " got: $(echo "$out" | head -c 200)"
|
|
fi
|
|
}
|
|
|
|
echo "=== MoneyFlix lab smoke (BIT-24693) ==="
|
|
echo "Host: $(hostname -I | awk '{print $1}')"
|
|
echo "CRM port: $CRM_PORT | Redirector port: $REDIRECTOR_PORT"
|
|
echo
|
|
|
|
# Ensure stack is up
|
|
if ! curl -sf "http://127.0.0.1:${CRM_PORT}/system/status" >/dev/null 2>&1; then
|
|
echo "Stack not running — starting..."
|
|
bash "$ROOT/tools/lab/start.sh"
|
|
sleep 2
|
|
fi
|
|
|
|
check "CRM /system/status" \
|
|
"curl -sf http://127.0.0.1:${CRM_PORT}/system/status" \
|
|
'"status"[[:space:]]*:[[:space:]]*"OK"'
|
|
|
|
check "CRM /api/redirects (Bearer)" \
|
|
"curl -sf -H 'Authorization: Bearer ${REDIRECTS_API_KEY}' http://127.0.0.1:${CRM_PORT}/api/redirects" \
|
|
'"success"[[:space:]]*:[[:space:]]*true'
|
|
|
|
check "Redirector /health" \
|
|
"curl -sf http://127.0.0.1:${REDIRECTOR_PORT}/health" \
|
|
'"status"[[:space:]]*:[[:space:]]*"healthy"'
|
|
|
|
check "Redirector /status" \
|
|
"curl -sf http://127.0.0.1:${REDIRECTOR_PORT}/status" \
|
|
'"status"[[:space:]]*:[[:space:]]*"running"'
|
|
|
|
check "Redirector /test-db" \
|
|
"curl -sf http://127.0.0.1:${REDIRECTOR_PORT}/test-db" \
|
|
'"status"[[:space:]]*:[[:space:]]*"ok"'
|
|
|
|
# Hit redirect slug — should 302 to example.com
|
|
REDIR_CODE="$(curl -s -o /dev/null -w '%{http_code}' -L --max-redirs 0 "http://127.0.0.1:${REDIRECTOR_PORT}/lab-smoke-test" 2>/dev/null || true)"
|
|
if [[ "$REDIR_CODE" == "302" || "$REDIR_CODE" == "301" ]]; then
|
|
PASS=$((PASS + 1))
|
|
RESULTS+=("PASS redirect /lab-smoke-test -> 302")
|
|
echo "PASS redirect /lab-smoke-test -> HTTP $REDIR_CODE"
|
|
else
|
|
FAIL=$((FAIL + 1))
|
|
RESULTS+=("FAIL redirect /lab-smoke-test")
|
|
echo "FAIL redirect /lab-smoke-test (HTTP $REDIR_CODE)"
|
|
fi
|
|
|
|
# Flush analytics queue and verify MySQL write
|
|
curl -sf "http://127.0.0.1:${REDIRECTOR_PORT}/process-queue" >/dev/null 2>&1 || true
|
|
sleep 2
|
|
|
|
MARIADB_CONTAINER="${MARIADB_CONTAINER:-}"
|
|
if [[ -z "$MARIADB_CONTAINER" ]]; then
|
|
MARIADB_CONTAINER="$(docker ps --format '{{.Names}}\t{{.Ports}}' | awk -F'\t' '$2 ~ /0\.0\.0\.0:3306/ {print $1; exit}')"
|
|
fi
|
|
|
|
HIT_COUNT="$(docker exec "$MARIADB_CONTAINER" mariadb -u"${DB_USER}" -p"${DB_PASS}" -N -e \
|
|
"SELECT COUNT(*) FROM redirect_stats rs JOIN redirects r ON r.id=rs.redirect_id WHERE r.cuid='lab-smoke-test';" \
|
|
moneyflix_lab 2>/dev/null || echo 0)"
|
|
|
|
if [[ "${HIT_COUNT:-0}" -ge 1 ]]; then
|
|
PASS=$((PASS + 1))
|
|
RESULTS+=("PASS MySQL analytics write (hits=$HIT_COUNT)")
|
|
echo "PASS MySQL analytics write (hits=$HIT_COUNT)"
|
|
else
|
|
FAIL=$((FAIL + 1))
|
|
RESULTS+=("FAIL MySQL analytics write")
|
|
echo "FAIL MySQL analytics write (hits=$HIT_COUNT)"
|
|
fi
|
|
|
|
echo
|
|
echo "=== Summary: $PASS passed, $FAIL failed ==="
|
|
printf '%s\n' "${RESULTS[@]}"
|
|
|
|
if [[ "$FAIL" -gt 0 ]]; then
|
|
exit 1
|
|
fi
|
|
|
|
echo "All smoke checks passed."
|