Files
ai-agent/test-integration.sh
Christoph K. b1a576f61e tests
2026-03-20 07:08:00 +01:00

135 lines
5.0 KiB
Bash
Executable File
Raw 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.
#!/usr/bin/env bash
# test-integration.sh Prüft Erreichbarkeit aller externen Dienste
# Kann manuell oder automatisch beim Bot-Start aufgerufen werden.
#
# Exit-Code: 0 = alle Dienste OK, 1 = mindestens ein Dienst nicht erreichbar
set -euo pipefail
CONFIG_FILE="${1:-./config.yml}"
TIMEOUT=5
ERRORS=0
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
ok() { echo -e " ${GREEN}${NC} $*"; }
fail() { echo -e " ${RED}${NC} $*"; ((ERRORS++)); }
warn() { echo -e " ${YELLOW}${NC} $*"; }
# ── Konfiguration lesen ──────────────────────────────────────────────────────
if [[ ! -f "$CONFIG_FILE" ]]; then
echo "❌ config.yml nicht gefunden: $CONFIG_FILE"
exit 1
fi
read_yaml() {
python3 -c "
import yaml, sys
with open('$CONFIG_FILE') as f:
cfg = yaml.safe_load(f)
keys = '$1'.split('.')
val = cfg
for k in keys:
val = val.get(k, '') if isinstance(val, dict) else ''
print(val or '')
" 2>/dev/null || echo ""
}
QDRANT_HOST=$(read_yaml qdrant.host)
QDRANT_PORT=$(read_yaml qdrant.port)
CHAT_URL=$(read_yaml chat.url)
EMB_URL=$(read_yaml embedding.url)
IMAP_HOST=$(read_yaml email.host)
IMAP_PORT=$(read_yaml email.port)
echo ""
echo "🔍 Integrations-Diagnose"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
# ── Qdrant ───────────────────────────────────────────────────────────────────
echo ""
echo "📦 Qdrant (${QDRANT_HOST}:${QDRANT_PORT})"
if nc -z -w "$TIMEOUT" "$QDRANT_HOST" "$QDRANT_PORT" 2>/dev/null; then
ok "TCP-Verbindung erfolgreich"
else
fail "TCP-Verbindung fehlgeschlagen (${QDRANT_HOST}:${QDRANT_PORT})"
fi
# ── LocalAI (Chat) ───────────────────────────────────────────────────────────
echo ""
echo "🤖 LocalAI Chat (${CHAT_URL})"
if [[ -n "$CHAT_URL" ]]; then
MODELS_URL="${CHAT_URL%/v1*}/v1/models"
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" --max-time "$TIMEOUT" "$MODELS_URL" 2>/dev/null || echo "000")
if [[ "$HTTP_CODE" == "200" ]]; then
ok "HTTP ${HTTP_CODE} erreichbar"
elif [[ "$HTTP_CODE" == "000" ]]; then
fail "Keine Verbindung (Timeout/Refused)"
else
warn "HTTP ${HTTP_CODE} unerwartet aber erreichbar"
fi
else
warn "chat.url nicht konfiguriert"
fi
# ── LocalAI (Embedding) ──────────────────────────────────────────────────────
echo ""
echo "🔢 LocalAI Embedding (${EMB_URL})"
if [[ -n "$EMB_URL" && "$EMB_URL" != "$CHAT_URL" ]]; then
MODELS_URL="${EMB_URL%/v1*}/v1/models"
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" --max-time "$TIMEOUT" "$MODELS_URL" 2>/dev/null || echo "000")
if [[ "$HTTP_CODE" == "200" ]]; then
ok "HTTP ${HTTP_CODE} erreichbar"
elif [[ "$HTTP_CODE" == "000" ]]; then
fail "Keine Verbindung (Timeout/Refused)"
else
warn "HTTP ${HTTP_CODE}"
fi
else
ok "Gleicher Endpunkt wie Chat übersprungen"
fi
# ── IMAP ────────────────────────────────────────────────────────────────────
echo ""
echo "📧 IMAP (${IMAP_HOST}:${IMAP_PORT})"
if [[ -n "$IMAP_HOST" && -n "$IMAP_PORT" ]]; then
if nc -z -w "$TIMEOUT" "$IMAP_HOST" "$IMAP_PORT" 2>/dev/null; then
ok "TCP-Verbindung erfolgreich"
else
fail "TCP-Verbindung fehlgeschlagen (${IMAP_HOST}:${IMAP_PORT})"
fi
else
warn "IMAP nicht konfiguriert übersprungen"
fi
# ── Unit-Tests ───────────────────────────────────────────────────────────────
echo ""
echo "🧪 Go Unit-Tests"
if go test ./... -count=1 -timeout 30s 2>&1 | grep -E "^(ok|FAIL|---)" | while read -r line; do
if echo "$line" | grep -q "^ok"; then
ok "$line"
elif echo "$line" | grep -q "^FAIL\|^--- FAIL"; then
fail "$line"
fi
done; then
:
fi
# Prüfe Exit-Code der Tests separat
if ! go test ./... -count=1 -timeout 30s > /dev/null 2>&1; then
((ERRORS++))
fi
# ── Ergebnis ────────────────────────────────────────────────────────────────
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
if [[ "$ERRORS" -eq 0 ]]; then
echo -e "${GREEN}✅ Alle Checks bestanden${NC}"
exit 0
else
echo -e "${RED}${ERRORS} Check(s) fehlgeschlagen${NC}"
exit 1
fi