68 lines
2.5 KiB
Bash
68 lines
2.5 KiB
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
ENV_FILE="$SCRIPT_DIR/../../.env.memory"
|
|
[[ -f "$ENV_FILE" ]] && source <(grep -E '^[A-Z_]+=.+' "$ENV_FILE" | sed 's/^/export /')
|
|
|
|
PASS=0
|
|
FAIL=0
|
|
|
|
check() {
|
|
local label="$1" result="$2"
|
|
if [[ "$result" == "ok" ]]; then
|
|
echo "✅ $label"
|
|
((PASS++)) || true
|
|
else
|
|
echo "❌ $label: $result"
|
|
((FAIL++)) || true
|
|
fi
|
|
}
|
|
|
|
# 1. .env.memory 存在且关键字段非空
|
|
if [[ -f "$ENV_FILE" ]]; then
|
|
missing=""
|
|
for key in PG_DSN VAULT_DIR OPENROUTER_API_KEY OPENROUTER_EMBED_MODEL; do
|
|
val="$(grep "^${key}=" "$ENV_FILE" | cut -d= -f2- | tr -d '"' | tr -d "'" | xargs)"
|
|
[[ -z "$val" ]] && missing="$missing $key"
|
|
done
|
|
[[ -z "$missing" ]] && check ".env.memory 关键字段" "ok" || check ".env.memory 关键字段" "缺少:$missing"
|
|
else
|
|
check ".env.memory 存在" "文件不存在: $ENV_FILE"
|
|
fi
|
|
|
|
# 2. PostgreSQL 可连接
|
|
if command -v psql &>/dev/null; then
|
|
result="$(psql "$PG_DSN" -c "SELECT 1;" -t 2>&1 | xargs)"
|
|
[[ "$result" == "1" ]] && check "PostgreSQL 连通" "ok" || check "PostgreSQL 连通" "$result"
|
|
elif command -v docker &>/dev/null; then
|
|
result="$(docker exec pgvector psql -U postgres -d memory -c "SELECT 1;" -t 2>&1 | xargs)"
|
|
[[ "$result" == "1" ]] && check "PostgreSQL 连通" "ok" || check "PostgreSQL 连通" "$result"
|
|
else
|
|
check "PostgreSQL 连通" "psql/docker 均不可用"
|
|
fi
|
|
|
|
# 3. memory_primary 条数 > 0
|
|
if command -v psql &>/dev/null; then
|
|
count="$(psql "$PG_DSN" -c "SELECT count(*) FROM memory_primary;" -t 2>&1 | xargs)"
|
|
elif command -v docker &>/dev/null; then
|
|
count="$(docker exec pgvector psql -U postgres -d memory -c "SELECT count(*) FROM memory_primary;" -t 2>&1 | xargs)"
|
|
else
|
|
count="0"
|
|
fi
|
|
[[ "$count" -gt 0 ]] 2>/dev/null && check "memory_primary 条数 ($count)" "ok" || check "memory_primary 条数" "为空或查询失败: $count"
|
|
|
|
# 4. 最近 updated_at 在 24h 内
|
|
if command -v psql &>/dev/null; then
|
|
fresh="$(psql "$PG_DSN" -c "SELECT count(*) FROM memory_primary WHERE updated_at > now() - interval '24 hours';" -t 2>&1 | xargs)"
|
|
elif command -v docker &>/dev/null; then
|
|
fresh="$(docker exec pgvector psql -U postgres -d memory -c "SELECT count(*) FROM memory_primary WHERE updated_at > now() - interval '24 hours';" -t 2>&1 | xargs)"
|
|
else
|
|
fresh="0"
|
|
fi
|
|
[[ "$fresh" -gt 0 ]] 2>/dev/null && check "24h 内有更新 ($fresh 条)" "ok" || check "24h 内有更新" "无近期更新"
|
|
|
|
echo ""
|
|
echo "结果: ${PASS} 通过 / ${FAIL} 失败"
|
|
[[ "$FAIL" -eq 0 ]] && exit 0 || exit 1
|