Files
wevads-platform/scripts/ethica-nonreg.sh
2026-03-13 15:25:58 +01:00

180 lines
13 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
###############################################################################
# ETHICA B2B PLATFORM — NON-REGRESSION COMPLETE v3
# bash /opt/wevads/scripts/ethica-nonreg.sh
# 12 sections, 100+ tests, AVANT+APRÈS chaque modif
###############################################################################
START=$(date +%s); PASS=0; FAIL=0; TOTAL=0; FAILS=""
BASE="http://127.0.0.1:5890"
CF="https://consent.wevup.app"
check() {
TOTAL=$((TOTAL+1))
if eval "$3" > /dev/null 2>&1; then PASS=$((PASS+1))
else FAIL=$((FAIL+1)); FAILS="$FAILS\n [$1] $2"; echo "$1: $2"; fi
}
check_http() {
TOTAL=$((TOTAL+1))
local resp=$(curl -s -o /tmp/nr_body.txt -w '%{http_code}|%{size_download}' -L --max-time 12 "$3" 2>/dev/null)
local code=$(echo "$resp" | cut -d'|' -f1); local size=$(echo "$resp" | cut -d'|' -f2)
local php_err=$(grep -c "Fatal error\|Parse error" /tmp/nr_body.txt 2>/dev/null)
if [ "$code" = "$4" ] && [ "${size%.*}" -gt "${5:-100}" ] && [ "$php_err" = "0" ]; then PASS=$((PASS+1))
else FAIL=$((FAIL+1)); FAILS="$FAILS\n [$1] $2 → HTTP=$code size=${size}B"; echo "$2 → HTTP=$code ${size}B"; fi
}
echo "╔══════════════════════════════════════════════════════════════╗"
echo "║ ETHICA NON-REGRESSION — $(date '+%Y-%m-%d %H:%M')"
echo "╚══════════════════════════════════════════════════════════════╝"
# ═══ 1. PAGES ═══
echo -e "\n▶ 1. PAGES HTTP"
for p in ethica-app-v3.html:5000 ethica-validation-monitor.html:1000 ethica-send-engine.html:1000 ethica-consent.php:1000 ethica-inscription.html:1000 ethica-campaign-creator.html:5000 ethica-consent-hub.html:1000 ethica-preferences.php:500 ethica-tokens.html:5000 ethica-audit.html:1000 ethica-real-scraper.html:5000; do
page=$(echo $p | cut -d: -f1); ms=$(echo $p | cut -d: -f2)
check_http "PAGE" "$page" "$BASE/$page" 200 $ms
done
# ═══ 2. APIs ═══
echo -e "\n▶ 2. APIs CORE"
for api in "ethica-api.php?action=dashboard:500" "ethica-api.php?action=sms_dashboard:200" "ethica-validation-api.php?action=status:500" "ethica-validation-api.php?action=run_validation:50" "ethica-send-api.php?action=dashboard:500" "ethica-send-api.php?action=templates:200" "ethica-send-api.php?action=senders:50" "ethica-sms-api.php?action=stats:200" "ethica-sentinel-playbook.php?action=status:200" "ethica-campaign-creator-api.php?action=brands:500"; do
path=$(echo $api | cut -d: -f1); ms=$(echo $api | cut -d: -f2)
check_http "API" "$path" "$BASE/api/$path" 200 $ms
done
# ═══ 3. TRACKING ═══
echo -e "\n▶ 3. TRACKING"
TID="nr_$(date +%s)"
check_http "TRACK" "Pixel open" "$BASE/api/ethica-track.php?t=${TID}_px&c=0" 200 30
check_http "TRACK" "Stats all" "$BASE/api/ethica-track.php?a=stats&c=0&channel=all" 200 50
check_http "TRACK" "WA delivery" "$BASE/api/ethica-track.php?a=wa_delivery&t=${TID}&s=delivered" 200 5
check_http "TRACK" "WA read" "$BASE/api/ethica-track.php?a=wa_read&t=${TID}" 200 5
TOTAL=$((TOTAL+1)); tg_code=$(curl -s -o /dev/null -w "%{http_code}" --max-time 8 "$BASE/api/ethica-track.php?a=tg_delivery&t=nr_tg&s=delivered" 2>/dev/null); if [ "$tg_code" = "200" ]; then PASS=$((PASS+1)); else FAIL=$((FAIL+1)); FAILS="$FAILS
[TRACK] TG delivery HTTP=$tg_code"; echo " ❌ TG delivery HTTP=$tg_code"; fi
check_http "TRACK" "WA reply" "$BASE/api/ethica-track.php?a=wa_reply&t=${TID}&msg=test" 200 5
check_http "TRACK" "SMS delivery" "$BASE/api/ethica-track.php?a=sms_delivery&t=${TID}&s=delivered" 200 5
check_http "TRACK" "Conversion" "$BASE/api/ethica-track.php?a=conv&t=${TID}&c=0&type=test" 200 5
# Redirects (302 expected)
for act in "click:url=https://t.co" "sms_click:url=https://t.co" "sms_consent:r=test" "unsub:"; do
a=$(echo $act | cut -d: -f1); p=$(echo $act | cut -d: -f2)
TOTAL=$((TOTAL+1))
code=$(curl -s -o /dev/null -w '%{http_code}' --max-time 8 "$BASE/api/ethica-track.php?a=$a&t=${TID}_$a&c=0&$p" 2>/dev/null)
if [ "$code" = "302" ] || [ "$code" = "200" ]; then PASS=$((PASS+1))
else FAIL=$((FAIL+1)); FAILS="$FAILS\n [TRACK] $a → HTTP=$code"; echo "$a → HTTP=$code"; fi
done
# ═══ 4. DATA INTEGRITY ═══
echo -e "\n▶ 4. DATA INTEGRITY"
check "DATA" "Total >40K" "curl -s '$BASE/api/ethica-validation-api.php?action=status' | python3 -c 'import json,sys;assert json.loads(sys.stdin.read())[\"total\"]>40000'"
check "DATA" "Active >30K" "curl -s '$BASE/api/ethica-validation-api.php?action=status' | python3 -c 'import json,sys;assert json.loads(sys.stdin.read())[\"quality\"][\"active\"]>30000'"
check "DATA" "Emails >20K" "curl -s '$BASE/api/ethica-send-api.php?action=dashboard' | python3 -c 'import json,sys;assert json.loads(sys.stdin.read())[\"with_email\"]>20000'"
check "DATA" "Phones >20K" "curl -s '$BASE/api/ethica-sms-api.php?action=stats' | python3 -c 'import json,sys;assert json.loads(sys.stdin.read())[\"contacts_with_phone\"]>20000'"
check "DATA" "Senders >=1" "curl -s '$BASE/api/ethica-send-api.php?action=dashboard' | python3 -c 'import json,sys;assert json.loads(sys.stdin.read())[\"senders_active\"]>=1'"
check "DATA" "Templates >=3" "curl -s '$BASE/api/ethica-send-api.php?action=templates' | python3 -c 'import json,sys;assert len(json.loads(sys.stdin.read())[\"templates\"])>=3'"
check "DATA" "18 Brands" "curl -s '$BASE/api/ethica-campaign-creator-api.php?action=brands' | python3 -c 'import json,sys;assert len(json.loads(sys.stdin.read())[\"brands\"])>=18'"
check "DATA" "Pipeline 6 steps" "curl -s '$BASE/api/ethica-validation-api.php?action=status' | python3 -c 'import json,sys;assert len(json.loads(sys.stdin.read())[\"pipeline\"])>=6'"
check "DATA" "3 Countries" "PGPASSWORD=admin123 psql -h localhost -U admin -d adx_system -tA -c \"SELECT COUNT(DISTINCT pays) FROM ethica.medecins_real WHERE status='active'\" | grep -q '3'"
check "DATA" "Gmail in ISP" "curl -s '$BASE/api/ethica-send-api.php?action=dashboard' | python3 -c 'import json,sys;assert any(i[\"isp\"]==\"Gmail\" for i in json.loads(sys.stdin.read())[\"isp_breakdown\"])'"
# ═══ 5. DB SCHEMA ═══
echo -e "\n▶ 5. DATABASE SCHEMA"
for tbl in medecins_real campaigns send_log sms_campaigns sms_log sms_providers consentements consent_tokens consent_log email_templates senders tracking_opens tracking_clicks tracking_conversions wa_campaigns wa_log wa_providers tg_campaigns tg_log tg_providers; do
check "SCHEMA" "$tbl" "PGPASSWORD=admin123 psql -h localhost -U admin -d adx_system -tA -c 'SELECT 1 FROM ethica.$tbl LIMIT 1' 2>/dev/null"
done
# ═══ 6. V3 UI ═══
echo -e "\n▶ 6. V3 UI NON-REGRESSION"
curl -s "$BASE/ethica-app-v3.html" > /tmp/nr_v3.html 2>/dev/null
check "V3" "9+ nav go() calls" "test \$(grep -o \"go('\" /tmp/nr_v3.html | wc -l) -ge 9"
for mod in dashboard scraping validation campaigns consent audit sentinel tokens exports; do
check "V3" "Module m-$mod" "grep -q \"m-$mod\" /tmp/nr_v3.html"
done
check "V3" "No go(sms) dup" "test \$(grep -c \"go('sms')\" /tmp/nr_v3.html) -eq 0"
check "V3" "No go(send) dup" "test \$(grep -c \"go('send')\" /tmp/nr_v3.html) -eq 0"
check "V3" "No m-sms orphan" "test \$(grep -c 'm-sms' /tmp/nr_v3.html) -eq 0"
check "V3" "Consent hub iframe" "grep -q 'ethica-consent-hub.html' /tmp/nr_v3.html"
check "V3" "Token iframe" "grep -q 'ethica-tokens.html' /tmp/nr_v3.html"
check "V3" "Campaign iframe" "grep -q 'ethica-campaign-creator.html' /tmp/nr_v3.html"
check "V3" "Validation iframe" "grep -q 'ethica-validation-monitor.html' /tmp/nr_v3.html"
# ═══ 7. CAMPAIGN CREATOR UX ═══
echo -e "\n▶ 7. CAMPAIGN CREATOR UX"
curl -s "$BASE/ethica-campaign-creator.html" > /tmp/nr_cc.html 2>/dev/null
check "CC" "4 tabs (email/sms/wa/tg)" "test $(grep -c "switchTab" /tmp/nr_cc.html) -ge 4"
check "CC" "Upload zone" "grep -q 'upload-zone' /tmp/nr_cc.html"
check "CC" "File input" "grep -q 'file-creative' /tmp/nr_cc.html"
check "CC" "handleCreativeFile x1" "test \$(grep -c 'function handleCreativeFile' /tmp/nr_cc.html) -eq 1"
check "CC" "handleDrop x1" "test \$(grep -c 'function handleDrop' /tmp/nr_cc.html) -eq 1"
for el in sms-pays sms-spec sms-budget sms-sender wa-pays wa-type wa-from-name wa-preview wa-budget preview-iframe brands-wa; do
check "CC" "Element $el" "grep -q '$el' /tmp/nr_cc.html"
done
check "CC" "Var chips" "grep -q 'var-chip' /tmp/nr_cc.html"
check "CC" "WA templates >=5" "test \$(grep -c 'option.*value=' /tmp/nr_cc.html) -ge 10"
check "CC" "uploadedImage" "grep -q 'uploadedImage' /tmp/nr_cc.html"
# ═══ 8. EXTERNAL ═══
echo -e "\n▶ 8. EXTERNAL ENDPOINTS"
check_http "EXT" "CF inscription" "$CF/ethica-inscription.html" 200 1000
# ═══ 9. CONSENT ═══
echo -e "\n▶ 9. CONSENT SYSTEM"
check "CONSENT" "API success=true" "curl -s '$CF/api/ethica-consent-api.php?action=stats' | python3 -c 'import json,sys;assert json.loads(sys.stdin.read())[\"success\"]==True'"
check "CONSENT" "Base >30K" "curl -s '$CF/api/ethica-consent-api.php?action=stats' | python3 -c 'import json,sys;assert json.loads(sys.stdin.read())[\"stats\"][\"total\"]>30000'"
check "CONSENT" "Phone >20K" "curl -s '$CF/api/ethica-consent-api.php?action=stats' | python3 -c 'import json,sys;assert json.loads(sys.stdin.read())[\"stats\"][\"phone_base\"]>20000'"
check "CONSENT" "3 countries" "curl -s '$CF/api/ethica-consent-api.php?action=stats' | python3 -c 'import json,sys;assert len(json.loads(sys.stdin.read())[\"stats\"][\"by_country\"])>=3'"
# ═══ 10. INFRA ═══
echo -e "\n▶ 10. SERVICES & INFRA"
check "INFRA" "PostgreSQL" "PGPASSWORD=admin123 psql -h localhost -U admin -d adx_system -tA -c 'SELECT 1' | grep -q '1'"
check "INFRA" "Apache2" "systemctl is-active --quiet apache2"
check "INFRA" "PHP-FPM" "pgrep -f php-fpm > /dev/null"
check "INFRA" "Cron enrich" "crontab -l 2>/dev/null | grep -q 'ethica-cron-enrich'"
check "INFRA" "Cron fallback" "crontab -l 2>/dev/null | grep -q 'ethica-source-fallback'"
check "INFRA" "Cron classify" "crontab -l 2>/dev/null | grep -q 'classify-medecin'"
# ═══ 11. PERFORMANCE ═══
echo -e "\n▶ 11. PERFORMANCE"
for ep in "Dashboard:api/ethica-api.php?action=dashboard" "Validation:api/ethica-validation-api.php?action=status" "Send:api/ethica-send-api.php?action=dashboard" "V3:ethica-app-v3.html" "CampaignCreator:ethica-campaign-creator.html" "Tracking:api/ethica-track.php?t=perf&c=0"; do
name=$(echo $ep | cut -d: -f1); path=$(echo $ep | cut -d: -f2-)
TOTAL=$((TOTAL+1))
ms=$(curl -s -o /dev/null -w '%{time_total}' --max-time 10 "$BASE/$path" 2>/dev/null | awk '{printf "%d",$1*1000}')
if [ "$ms" -lt 2000 ]; then PASS=$((PASS+1))
else FAIL=$((FAIL+1)); FAILS="$FAILS\n [PERF] $name${ms}ms"; echo "$name${ms}ms"; fi
done
# ═══ 12. PHP SYNTAX ═══
echo -e "\n▶ 12. PHP SYNTAX"
for f in /opt/wevads-arsenal/public/api/ethica-*.php /opt/wevads-arsenal/public/api/ovh-sms-setup.php /opt/wevads-arsenal/public/api/wa-setup.php; do
[ -f "$f" ] && check "PHP" "$(basename $f)" "php -l '$f' 2>&1 | grep -q 'No syntax errors'"
done
# ═══ 13. TELEGRAM ENRICHMENT ═══
echo -e '
▶ 13. TELEGRAM ENRICHMENT'
TOTAL=$((TOTAL+1)); tg_col=$(PGPASSWORD=admin123 psql -h localhost -U admin -d adx_system -tA -c "SELECT count(*) FROM ethica.medecins_real WHERE telegram_username IS NOT NULL" 2>/dev/null); if echo "$tg_col" | grep -qE "^[0-9]"; then PASS=$((PASS+1)); else FAIL=$((FAIL+1)); FAILS="$FAILS\n [TG] telegram_username column"; echo " ❌ TG column"; fi
check 'TG' 'Scraper exists' 'test -f /opt/wevads/scripts/ethica/scraper-telegram.py'
check 'TG' 'Mass scraper exists' 'test -f /opt/wevads/scripts/ethica/scraper-telegram-mass.py'
check 'TG' 'TG cron active' 'crontab -l 2>/dev/null | grep -q scraper-telegram'
check 'TG' 'TG tables exist' 'PGPASSWORD=admin123 psql -h localhost -U admin -d adx_system -tA -c "SELECT 1 FROM ethica.tg_providers LIMIT 1" 2>/dev/null'
check 'TG' 'Bot token in DB' 'PGPASSWORD=admin123 psql -h localhost -U admin -d adx_system -tA -c "SELECT bot_token FROM ethica.tg_providers LIMIT 1" | grep -q "^[0-9]"'
# ═══ SUMMARY ═══
SEC=$(( $(date +%s) - START ))
if [ "$FAIL" = "0" ]; then SIG="6σ"
elif [ "$FAIL" -lt 2 ]; then SIG="5σ"
elif [ "$FAIL" -lt 8 ]; then SIG="4σ"
elif [ "$FAIL" -lt 30 ]; then SIG="3σ"
else SIG="2σ"; fi
echo ""
echo "══════════════════════════════════════════════════════════════"
if [ "$FAIL" = "0" ]; then
echo " ✅ ALL PASSED: $PASS/$TOTAL | ${SEC}s | $SIG"
else
echo "$PASS/$TOTAL PASSED | $FAIL FAILED | ${SEC}s | $SIG"
echo -e " FAILURES:$FAILS"
fi
echo "══════════════════════════════════════════════════════════════"
echo "$(date -Iseconds) P=$PASS F=$FAIL T=$TOTAL S=$SIG ${SEC}s" >> /var/log/ethica-nonreg.log
exit $FAIL