Files
minerops/scripts/test-system-health.sh

71 lines
2.8 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "${repo_root}"
readonly source_files=(
backend/app/config.py
backend/app/frontend/static/system-health.css
backend/app/frontend/static/system-health.js
backend/app/frontend/system_health_view.py
backend/app/frontend/views.py
backend/app/main.py
backend/app/system_health/__init__.py
backend/app/system_health/adapters.py
backend/app/system_health/application.py
backend/app/system_health/dependencies.py
backend/app/system_health/frontend.py
backend/app/system_health/models.py
backend/app/system_health/repository.py
backend/app/system_health/router.py
backend/app/system_health/service.py
backend/tests/__init__.py
backend/tests/test_frontend_shell.py
backend/tests/test_system_health.py
)
for file in "${source_files[@]}"; do
[[ -r "${file}" ]] || { echo "Unreadable System Health input: ${file}" >&2; exit 1; }
[[ "$(stat -c '%a' "${file}")" == "644" ]] || {
echo "System Health source/test mode must be 0644: ${file}" >&2; exit 1;
}
done
[[ "$(stat -c '%a' scripts/test-system-health.sh)" == "755" ]] || {
echo "scripts/test-system-health.sh must have mode 0755." >&2; exit 1;
}
echo "System Health file-mode preflight passed."
python3 -m py_compile backend/app/config.py backend/app/frontend/system_health_view.py backend/app/frontend/views.py backend/app/main.py backend/app/system_health/*.py backend/tests/__init__.py backend/tests/test_frontend_shell.py backend/tests/test_system_health.py
node --check backend/app/frontend/static/system-health.js
bash -n scripts/test-system-health.sh
[[ -f .env.dev ]] || { echo "Missing .env.dev." >&2; exit 1; }
project_name="${MINEROPS_SYSTEM_HEALTH_TEST_PROJECT:-minerops-system-health-$$}"
compose=(docker compose --project-name "${project_name}" --env-file .env.dev -f compose.dev.yaml)
cleanup() {
status=$?
if (( status != 0 )); then
"${compose[@]}" logs --no-color --tail 100 postgres redis || true
fi
"${compose[@]}" down --volumes --remove-orphans >/dev/null 2>&1 || true
exit "${status}"
}
trap cleanup EXIT
"${compose[@]}" up --detach postgres redis
for attempt in $(seq 1 60); do
if "${compose[@]}" exec -T postgres sh -ec \
'pg_isready -U "$POSTGRES_USER" -d "$POSTGRES_DB"' >/dev/null 2>&1 \
&& "${compose[@]}" exec -T redis redis-cli ping 2>/dev/null | grep -qx PONG; then
break
fi
(( attempt < 60 )) || { echo "Dependencies did not become ready." >&2; exit 1; }
sleep 1
done
"${compose[@]}" build backend
"${compose[@]}" run --rm --no-deps backend alembic upgrade head
"${compose[@]}" run --rm --no-deps \
-v "${repo_root}/backend/tests:/app/tests:ro" \
backend python -m unittest -v tests.test_system_health tests.test_frontend_shell