Files
kima-hub/scripts/run-enrichment-memory-test.sh
Your Name 9083835bfd chore: v1.7.0 -- vibe galaxy, CI pipeline, enrichment hardening, PWA, preprod sweep
- Bump frontend and backend to 1.7.0
- Update CHANGELOG with full 1.7.0 release notes
- Remove vibe-test dev prototype page and unused R3F components
  (VibeUniverse, TrackCloud, TrackTooltip, universeUtils)
- Fix stale audio.completed counter: flush live DB count at isFullyComplete
  transition -- counter was frozen at last audioQueued > 0 cycle value
- Add GitHub Actions CI pipeline: lint/typecheck, unit tests, security scan,
  E2E predeploy, nightly Docker build and push to Hub + GHCR
- Add E2E enrichment cycle spec with 55-min timeout and memory monitoring script
- Add E2E vibe spec covering map, song path, search, alchemy, similar tracks
- PWA hardening: offline fallback, update banner, WCO, manifest fixes
- Production readiness: OOM memory caps in both compose files, DoS/SSRF/auth fixes
- Remove double-auth in systemSettings (requireAdmin already enforces auth)
- Fix mobile vibe page full-height rendering, vibe map timer leak, abort signal wiring
- Fix E2E test helpers: graceful skip with waitFor + try/catch for empty-library CI
- Fix create-e2e-user.sh: admin role, bcrypt shell expansion, psql heredoc quoting
2026-03-16 18:25:08 -05:00

112 lines
4.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# Run the enrichment-cycle Playwright test with before/after host memory monitoring.
#
# Usage:
# bash scripts/run-enrichment-memory-test.sh [container-name]
#
# Environment:
# KIMA_TEST_USERNAME -- E2E test user (default: kima_e2e)
# KIMA_TEST_PASSWORD -- E2E test password (required)
# KIMA_UI_BASE_URL -- Base URL (default: http://127.0.0.1:3030)
# KIMA_CONTAINER -- Docker container name (default: kima-test)
# SUNRECLAIM_LIMIT_MB -- Fail if SUnreclaim grows by more than this (default: 1024)
set -euo pipefail
CONTAINER="${KIMA_CONTAINER:-kima-test}"
BASE_URL="${KIMA_UI_BASE_URL:-http://127.0.0.1:3030}"
SUNRECLAIM_LIMIT="${SUNRECLAIM_LIMIT_MB:-1024}"
# ---------------------------------------------------------------------------
# Helpers
# ---------------------------------------------------------------------------
sunreclaim_mb() {
awk '/^SUnreclaim:/ { printf "%d", $2 / 1024 }' /proc/meminfo
}
container_mem_mb() {
docker stats --no-stream --format "{{.MemUsage}}" "${CONTAINER}" 2>/dev/null \
| awk '{ match($0, /^([0-9.]+)([GMkB]+)/, arr); v=arr[1]; u=arr[2]; if(u~/GiB/) printf "%d", v*1024; else if(u~/MiB/) printf "%d", v; else printf "%d", v/1024 }'
}
# ---------------------------------------------------------------------------
# Pre-flight
# ---------------------------------------------------------------------------
if ! docker ps --format "{{.Names}}" | grep -q "^${CONTAINER}$"; then
echo "[error] Container '${CONTAINER}' is not running."
echo " Start it first: see MEMORY.md for the build+run command."
exit 1
fi
if [[ -z "${KIMA_TEST_PASSWORD:-}" ]]; then
echo "[error] KIMA_TEST_PASSWORD is not set."
exit 1
fi
echo "[memory-test] Waiting for health check..."
timeout 30 bash -c "until curl -sf ${BASE_URL}/api/health > /dev/null; do sleep 2; done"
# ---------------------------------------------------------------------------
# Baseline memory snapshot
# ---------------------------------------------------------------------------
SUNRECLAIM_BEFORE=$(sunreclaim_mb)
CONTAINER_MEM_BEFORE=$(container_mem_mb)
echo ""
echo "=========================================================="
echo " Memory baseline"
echo " Host SUnreclaim: ${SUNRECLAIM_BEFORE} MB"
echo " Container RSS: ${CONTAINER_MEM_BEFORE} MB"
echo "=========================================================="
echo ""
# ---------------------------------------------------------------------------
# Run the Playwright enrichment-cycle spec
# ---------------------------------------------------------------------------
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
FRONTEND_DIR="${SCRIPT_DIR}/../frontend"
echo "[memory-test] Running enrichment-cycle spec..."
npx --prefix "${FRONTEND_DIR}" playwright test \
tests/e2e/enrichment-cycle.spec.ts \
--reporter=list
TEST_EXIT=$?
# ---------------------------------------------------------------------------
# Post-test memory snapshot
# ---------------------------------------------------------------------------
SUNRECLAIM_AFTER=$(sunreclaim_mb)
CONTAINER_MEM_AFTER=$(container_mem_mb)
SUNRECLAIM_DELTA=$(( SUNRECLAIM_AFTER - SUNRECLAIM_BEFORE ))
CONTAINER_MEM_DELTA=$(( CONTAINER_MEM_AFTER - CONTAINER_MEM_BEFORE ))
echo ""
echo "=========================================================="
echo " Memory after enrichment cycle"
echo " Host SUnreclaim: ${SUNRECLAIM_AFTER} MB (delta: +${SUNRECLAIM_DELTA} MB)"
echo " Container RSS: ${CONTAINER_MEM_AFTER} MB (delta: +${CONTAINER_MEM_DELTA} MB)"
echo "=========================================================="
echo ""
# ---------------------------------------------------------------------------
# Fail if slab growth exceeds threshold
# ---------------------------------------------------------------------------
if (( SUNRECLAIM_DELTA > SUNRECLAIM_LIMIT )); then
echo "[FAIL] Host SUnreclaim grew by ${SUNRECLAIM_DELTA} MB -- exceeds limit of ${SUNRECLAIM_LIMIT} MB."
echo " This indicates kernel slab (anon_vma_chain) accumulation from the enrichment pipeline."
echo " Check: /proc/slabinfo | grep anon_vma -- if anon_vma_chain is large, suspect"
echo " excessive process forks or repeated VMA splits during audio processing."
exit 1
fi
echo "[memory-test] Slab growth within acceptable range (${SUNRECLAIM_DELTA} MB < ${SUNRECLAIM_LIMIT} MB limit)."
# Propagate Playwright exit code
exit "${TEST_EXIT}"