ops(dev): extend preflight with audit retention checks

Made-with: Cursor
This commit is contained in:
Apple
2026-03-02 09:59:22 -08:00
parent 1d18634c01
commit 6a0d2ff103

View File

@@ -23,6 +23,7 @@ FAIL=0
_pass() { echo -e "${GREEN}PASS${NC}: $1"; PASS=$((PASS+1)); }
_warn() { echo -e "${YELLOW}WARN${NC}: $1"; WARN=$((WARN+1)); }
_fail() { echo -e "${RED}FAIL${NC}: $1"; FAIL=$((FAIL+1)); }
_info() { echo "INFO: $1"; }
_section() { echo -e "\n-- $1 --"; }
for cmd in bash curl rg python3; do
@@ -100,7 +101,53 @@ else
_fail "Cannot create SOFIIA_DATA_DIR (${DATA_DIR})"
fi
_section "5) Redis connectivity (if redis backend enabled)"
_section "5) Audit DB checks"
RETENTION_RAW="${SOFIIA_AUDIT_RETENTION_DAYS:-}"
if [ -n "${RETENTION_RAW}" ]; then
if [[ "${RETENTION_RAW}" =~ ^[0-9]+$ ]] && [ "${RETENTION_RAW}" -gt 0 ] 2>/dev/null; then
_pass "SOFIIA_AUDIT_RETENTION_DAYS=${RETENTION_RAW} (valid)"
else
_warn "SOFIIA_AUDIT_RETENTION_DAYS must be integer > 0 (got: ${RETENTION_RAW})"
fi
else
_info "SOFIIA_AUDIT_RETENTION_DAYS not set; default 90 will apply"
fi
DB_PATH="${DATA_DIR}/sofiia.db"
if [ -f "${DB_PATH}" ]; then
db_size_bytes=""
if stat -f%z "${DB_PATH}" >/dev/null 2>&1; then
db_size_bytes="$(stat -f%z "${DB_PATH}")"
elif stat -c%s "${DB_PATH}" >/dev/null 2>&1; then
db_size_bytes="$(stat -c%s "${DB_PATH}")"
elif command -v du >/dev/null 2>&1; then
db_size_bytes="$(du -k "${DB_PATH}" | awk '{print $1 * 1024}')"
fi
if [ -n "${db_size_bytes}" ] && [[ "${db_size_bytes}" =~ ^[0-9]+$ ]]; then
threshold_bytes="${SOFIIA_AUDIT_DB_WARN_BYTES:-1073741824}" # 1GB default
if [[ "${threshold_bytes}" =~ ^[0-9]+$ ]] && [ "${db_size_bytes}" -gt "${threshold_bytes}" ]; then
_warn "sofiia.db size is high (${db_size_bytes} bytes > ${threshold_bytes} bytes)"
else
_pass "sofiia.db size check OK (${db_size_bytes} bytes)"
fi
else
_warn "Could not determine sofiia.db size (stat/du unavailable)"
fi
if command -v sqlite3 >/dev/null 2>&1; then
if sqlite3 "${DB_PATH}" "SELECT 1 FROM audit_events LIMIT 1;" >/dev/null 2>&1; then
_pass "audit_events table exists"
else
_warn "audit_events table check failed (table missing or DB not ready)"
fi
else
_warn "sqlite3 not installed; skipped audit_events table check"
fi
else
_warn "DB file not found at ${DB_PATH} (fresh instance or path mismatch)"
fi
_section "6) Redis connectivity (if redis backend enabled)"
if [ "${SOFIIA_IDEMPOTENCY_BACKEND:-inmemory}" = "redis" ] || [ "${SOFIIA_RATE_LIMIT_BACKEND:-inmemory}" = "redis" ]; then
REDIS_URL="${SOFIIA_REDIS_URL:-}"
if [ -z "${REDIS_URL}" ]; then