120 lines
7.5 KiB
Bash
Executable File
120 lines
7.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -Eeuo pipefail
|
|
|
|
ROOT="${ROOT:-/var/www/dhv2.korexlabs.com}"
|
|
API_URL="${API_URL:-http://127.0.0.1:3101/api/v3}"
|
|
TMP_MIGRATION="/tmp/dhv2-d5325-accept-migration-$$.log"
|
|
trap 'rm -f "$TMP_MIGRATION"' EXIT
|
|
cd "$ROOT"
|
|
|
|
echo "========== D5.3.25 · VERSIONES =========="
|
|
[[ "$(node -p "require('./api-v3/package.json').version")" == "0.19.3-25" ]]
|
|
[[ "$(node -p "require('./web-v2/package.json').version")" == "0.19.3-25" ]]
|
|
grep -Fq "API_PHASE = 'D5.3.25'" api-v3/src/version.ts
|
|
grep -Fq "APP_PHASE = 'Fase D5.3.25 · Historial de verificaciones'" web-v2/src/config/version.ts
|
|
echo "API: 0.19.3-25"
|
|
echo "WEB: 0.19.3-25"
|
|
|
|
echo
|
|
echo "========== D5.3.25 · DB Y MIGRACIONES =========="
|
|
[[ "$(docker inspect dhv2-db --format '{{.State.Health.Status}}')" == "healthy" ]]
|
|
docker compose exec -T db sh -lc 'pg_isready -U "$POSTGRES_USER" -d "$POSTGRES_DB"'
|
|
docker compose --profile tools run --rm migrate npm run migration:show 2>&1 | tee "$TMP_MIGRATION"
|
|
grep -Fq 'Pending migrations: no' "$TMP_MIGRATION"
|
|
docker compose exec -T db sh -lc 'psql -U "$POSTGRES_USER" -d "$POSTGRES_DB" -Atc "SELECT to_regclass('"'"'public.inspection_finding_verification_events'"'"');"' | grep -Fxq 'inspection_finding_verification_events'
|
|
for column in finding_id verification_visit_id event_type occurred_at target_control_on previous_control_on next_control_on outcome notes actor_user_id actor_username created_at; do
|
|
docker compose exec -T db sh -lc "psql -U \"\$POSTGRES_USER\" -d \"\$POSTGRES_DB\" -Atc \"SELECT column_name FROM information_schema.columns WHERE table_name='inspection_finding_verification_events' AND column_name='$column';\"" | grep -Fxq "$column"
|
|
done
|
|
TRIGGER_COUNT="$(docker compose exec -T db sh -lc 'psql -U "$POSTGRES_USER" -d "$POSTGRES_DB" -Atc "SELECT COUNT(*) FROM pg_trigger WHERE tgname='"'"'trg_inspection_verification_result_immutable'"'"' AND NOT tgisinternal;"')"
|
|
[[ "$TRIGGER_COUNT" == "1" ]]
|
|
echo "Ledger append-only y protección de resultados presentes: OK"
|
|
|
|
echo
|
|
echo "========== D5.3.25 · BACKFILL HISTÓRICO =========="
|
|
LINK_COUNT="$(docker compose exec -T db sh -lc 'psql -U "$POSTGRES_USER" -d "$POSTGRES_DB" -Atc "SELECT COUNT(*) FROM inspection_finding_verification_visits;"')"
|
|
PLANNED_EVENT_COUNT="$(docker compose exec -T db sh -lc 'psql -U "$POSTGRES_USER" -d "$POSTGRES_DB" -Atc "SELECT COUNT(*) FROM inspection_finding_verification_events WHERE event_type='"'"'VISIT_PLANNED'"'"';"')"
|
|
RESULT_LINK_COUNT="$(docker compose exec -T db sh -lc 'psql -U "$POSTGRES_USER" -d "$POSTGRES_DB" -Atc "SELECT COUNT(*) FROM inspection_finding_verification_visits WHERE outcome IS NOT NULL;"')"
|
|
RESULT_EVENT_COUNT="$(docker compose exec -T db sh -lc 'psql -U "$POSTGRES_USER" -d "$POSTGRES_DB" -Atc "SELECT COUNT(*) FROM inspection_finding_verification_events WHERE event_type='"'"'RESULT_RECORDED'"'"';"')"
|
|
(( PLANNED_EVENT_COUNT >= LINK_COUNT ))
|
|
(( RESULT_EVENT_COUNT >= RESULT_LINK_COUNT ))
|
|
echo "Antecedentes de visitas y resultados reconstruidos sin borrar historia: OK"
|
|
|
|
echo
|
|
echo "========== D5.3.25 · HEALTH =========="
|
|
HEALTH="$(curl -fsS "$API_URL/health")"
|
|
echo "$HEALTH"
|
|
grep -Fq '"version":"0.19.3-25"' <<<"$HEALTH"
|
|
grep -Fq '"phase":"D5.3.25"' <<<"$HEALTH"
|
|
grep -Fq '"database":"ok"' <<<"$HEALTH"
|
|
|
|
echo
|
|
echo "========== D5.3.25 · RESULTADOS INMUTABLES =========="
|
|
grep -Fq 'VERIFICATION_RESULT_IMMUTABLE' api-v3/src/inspection-verifications/inspection-verifications.service.ts
|
|
grep -Fq 'protect_inspection_verification_result_immutability' api-v3/src/database/migrations/1788890400000-phase-d5-3-25-verification-event-history.ts
|
|
grep -Fq 'InspectionFindingVerificationEventType.RESULT_RECORDED' api-v3/src/inspection-verifications/inspection-verifications.service.ts
|
|
echo "Un resultado de campo registrado no puede sobrescribirse: OK"
|
|
|
|
echo
|
|
echo "========== D5.3.25 · REPROGRAMACIONES APPEND-ONLY =========="
|
|
grep -Fq 'InspectionFindingVerificationEventType.CONTROL_DATE_DEFINED' api-v3/src/inspection-findings/inspection-findings.service.ts
|
|
grep -Fq 'InspectionFindingVerificationEventType.CONTROL_DATE_CHANGED' api-v3/src/inspection-findings/inspection-findings.service.ts
|
|
grep -Fq 'InspectionFindingVerificationEventType.CONTROL_DATE_CLEARED' api-v3/src/inspection-findings/inspection-findings.service.ts
|
|
if grep -Rnh 'DELETE FROM inspection_finding_verification_events' api-v3/src/inspection-findings api-v3/src/inspection-verifications; then exit 1; fi
|
|
echo "Cada cambio de fecha conserva la fecha anterior como evento: OK"
|
|
|
|
echo
|
|
echo "========== D5.3.25 · VERIFICACIONES SUCESIVAS =========="
|
|
grep -Fq 'InspectionFindingVerificationEventType.VISIT_PLANNED' api-v3/src/inspection-verifications/inspection-verifications.service.ts
|
|
grep -Fq "visit.status IN ('DRAFT', 'PLANNED', 'IN_PROGRESS')" api-v3/src/inspection-verifications/inspection-verifications.service.ts
|
|
if grep -Fq 'DELETE FROM inspection_finding_verification_visits' api-v3/src/inspection-verifications/inspection-verifications.service.ts; then exit 1; fi
|
|
echo "Múltiples verificaciones sucesivas quedan como intentos históricos independientes: OK"
|
|
|
|
echo
|
|
echo "========== D5.3.25 · EXPEDIENTE WEB =========="
|
|
grep -Fq "@Get(':id/verification-history')" api-v3/src/inspection-findings/inspection-findings.controller.ts
|
|
grep -Fq 'inspection_finding_verification_events event' api-v3/src/inspection-findings/inspection-findings.service.ts
|
|
grep -Fq 'Historial completo de verificaciones' web-v2/src/features/inspections/FindingOfficeWorkspace.tsx
|
|
grep -Fq 'verificationHistory.map' web-v2/src/features/inspections/FindingOfficeWorkspace.tsx
|
|
echo "Hallazgo muestra cronología completa de fechas, visitas y resultados: OK"
|
|
|
|
echo
|
|
echo "========== D5.3.25 · REGLAS PRESERVADAS =========="
|
|
grep -Fq 'INSPECTION_VISIT_ACT_ALREADY_EXISTS' api-v3/src/inspection-acts/inspection-acts.service.ts
|
|
grep -Fq 'INSPECTION_FINDING_RESPONSE_IMMUTABLE' api-v3/src/inspection-findings/inspection-findings.service.ts
|
|
if grep -Fq 'UPDATE inspection_findings SET asset_id' api-v3/src/asset-master/assets.service.ts; then exit 1; fi
|
|
echo "Una visita = una Acta; respuesta original, hallazgos y documentos históricos siguen protegidos: OK"
|
|
|
|
echo
|
|
echo "========== D5.3.25 · SMTP =========="
|
|
SMTP_STATE="$(docker compose exec -T api sh -lc 'if [ -n "$SMTP_HOST" ] && [ -n "$MAIL_FROM" ]; then echo configured; else echo pending; fi')"
|
|
if [[ "$SMTP_STATE" == "configured" ]]; then echo "SMTP configurado"; else echo "SMTP sigue pendiente y no bloquea esta fase"; fi
|
|
|
|
echo
|
|
echo "========== D5.3.25 · HIGIENE DE CÓDIGO =========="
|
|
if grep -RnhE --include='*.ts' --include='*.tsx' '^[[:space:]]*(//|/\*|\*)' api-v3/src web-v2/src; then
|
|
echo "ERROR: quedaron comentarios narrativos en código de producción"
|
|
exit 1
|
|
fi
|
|
if grep -nE '/\*|\*/' web-v2/src/styles.css; then
|
|
echo "ERROR: quedaron comentarios internos en estilos de producción"
|
|
exit 1
|
|
fi
|
|
echo "Código de producción preparado para revisión externa: OK"
|
|
|
|
echo
|
|
echo "========== D5.3.25 · SEGURIDAD HEREDADA =========="
|
|
STRONG_BACKUP="$(find /root/DH_V2_BACKUPS -maxdepth 1 -type d -name 'INVENTARIO_A_REVISAR_*' -printf '%T@ %p\n' | sort -nr | head -n1 | cut -d' ' -f2-)"
|
|
[[ -n "$STRONG_BACKUP" && -s "$STRONG_BACKUP/BACKUP_OK.txt" ]]
|
|
grep -Fq 'INVENTARIO A REVISAR' "$STRONG_BACKUP/BACKUP_OK.txt"
|
|
echo "Backup fuerte de referencia: $STRONG_BACKUP"
|
|
|
|
echo
|
|
echo "========== D5.3.25 · CONTENEDORES =========="
|
|
docker compose ps -a
|
|
[[ "$(docker inspect dhv2-db --format '{{.State.Health.Status}}')" == "healthy" ]]
|
|
[[ "$(docker inspect dhv2-api --format '{{.State.Status}}')" == "running" ]]
|
|
[[ "$(docker inspect dhv2-web --format '{{.State.Status}}')" == "running" ]]
|
|
|
|
echo
|
|
echo "ACEPTACIÓN DE FASE D5.3.25: OK"
|