139 lines
8.2 KiB
Bash
Executable File
139 lines
8.2 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-d541-accept-migration-$$.log"
|
||
trap 'rm -f "$TMP_MIGRATION"' EXIT
|
||
cd "$ROOT"
|
||
|
||
echo "========== D5.4.1 · VERSIONES =========="
|
||
[[ "$(node -p "require('./api-v3/package.json').version")" == "0.19.4-1" ]]
|
||
[[ "$(node -p "require('./web-v2/package.json').version")" == "0.19.4-1" ]]
|
||
grep -Fq "API_PHASE = 'D5.4.1'" api-v3/src/version.ts
|
||
grep -Fq "APP_PHASE = 'Fase D5.4.1 · Hallazgos aplicables al Inventario'" web-v2/src/config/version.ts
|
||
echo "API: 0.19.4-1"
|
||
echo "WEB: 0.19.4-1"
|
||
|
||
echo
|
||
echo "========== D5.4.1 · 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"
|
||
for table in finding_catalog_asset_type_profiles finding_catalog_item_asset_types finding_catalog_asset_overrides finding_catalog_proposals; do
|
||
docker compose exec -T db sh -lc "psql -U \"\$POSTGRES_USER\" -d \"\$POSTGRES_DB\" -Atc \"SELECT to_regclass('public.$table');\"" | grep -Fxq "$table"
|
||
done
|
||
for spec in 'finding_catalog_items:suggested_severity' 'inspection_findings:suggested_severity' 'inspection_findings:severity'; do
|
||
table="${spec%%:*}"; column="${spec##*:}"
|
||
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='$table' AND column_name='$column';\"" | grep -Fxq "$column"
|
||
done
|
||
echo "Aplicabilidad contextual, excepciones, propuestas y gravedad presentes: OK"
|
||
|
||
echo
|
||
echo "========== D5.4.1 · HEALTH =========="
|
||
HEALTH="$(curl -fsS "$API_URL/health")"
|
||
echo "$HEALTH"
|
||
grep -Fq '"version":"0.19.4-1"' <<<"$HEALTH"
|
||
grep -Fq '"phase":"D5.4.1"' <<<"$HEALTH"
|
||
grep -Fq '"database":"ok"' <<<"$HEALTH"
|
||
|
||
echo
|
||
echo "========== D5.4.1 · CATÁLOGO POR TIPO =========="
|
||
grep -Fq "@Get('asset-types/:assetTypeId/selection')" api-v3/src/inspection-findings/finding-catalog.controller.ts
|
||
grep -Fq "@Put('asset-types/:assetTypeId/selection')" api-v3/src/inspection-findings/finding-catalog.controller.ts
|
||
grep -Fq 'finding_catalog_asset_type_profiles' api-v3/src/inspection-findings/finding-catalog.service.ts
|
||
grep -Fq 'WHEN $2::boolean = false THEN true' api-v3/src/inspection-findings/finding-catalog.service.ts
|
||
grep -Fq 'FindingCatalogTypeApplicabilityPanel' web-v2/src/pages/FindingCatalogPage.tsx
|
||
echo "Catálogo configurable por tipo con fallback seguro para tipos aún no definidos: OK"
|
||
|
||
echo
|
||
echo "========== D5.4.1 · CONTRATO DE BUILD =========="
|
||
grep -Fq 'export interface AssetTypeSelectionView' api-v3/src/inspection-findings/finding-catalog.service.ts
|
||
grep -Fq 'export interface AssetSelectionView' api-v3/src/inspection-findings/finding-catalog.service.ts
|
||
echo "Tipos públicos usados por el controller son exportables por el build de Nest: OK"
|
||
|
||
echo
|
||
echo "========== D5.4.1 · EXCEPCIONES POR INVENTARIO =========="
|
||
grep -Fq "@Get('assets/:assetId/selection')" api-v3/src/inspection-findings/finding-catalog.controller.ts
|
||
grep -Fq "@Put('assets/:assetId/selection')" api-v3/src/inspection-findings/finding-catalog.controller.ts
|
||
grep -Fq 'finding_catalog_asset_overrides override' api-v3/src/inspection-findings/finding-catalog.service.ts
|
||
grep -Fq 'Hallazgos aplicables' web-v2/src/pages/AssetEditorPage.tsx
|
||
grep -Fq 'AssetFindingCatalogPanel' web-v2/src/pages/AssetEditorPage.tsx
|
||
echo "Cada objeto puede justificar excepciones sobre el default de su tipo: OK"
|
||
|
||
echo
|
||
echo "========== D5.4.1 · ENFORCEMENT EN CAMPO =========="
|
||
grep -Fq "@Get('applicable/:assetId')" api-v3/src/inspection-findings/finding-catalog.controller.ts
|
||
grep -Fq 'FINDING_CATALOG_ITEM_NOT_APPLICABLE' api-v3/src/inspection-findings/inspection-findings.service.ts
|
||
grep -Fq 'await this.requireCatalogItem(manager, finding.catalogItemId, dto.assetId)' api-v3/src/inspection-findings/inspection-findings.service.ts
|
||
echo "La API sólo acepta hallazgos habilitados para el elemento concreto: OK"
|
||
|
||
echo
|
||
echo "========== D5.4.1 · GRAVEDAD 1–10 =========="
|
||
grep -Fq 'chk_finding_catalog_items_suggested_severity' api-v3/src/database/migrations/1788976800000-phase-d5-4-contextual-finding-catalog.ts
|
||
grep -Fq 'chk_inspection_findings_severity' api-v3/src/database/migrations/1788976800000-phase-d5-4-contextual-finding-catalog.ts
|
||
grep -Fq 'severity: dto.severity ?? catalog?.suggestedSeverity ?? null' api-v3/src/inspection-findings/inspection-findings.service.ts
|
||
grep -Fq "table(['Código', 'Título', 'Descripción', 'Gravedad', 'Vencimiento']" api-v3/src/inspection-reports/inspection-report-word-builder.ts
|
||
echo "Gravedad sugerida y real quedan separadas y congeladas en históricos/documentos: OK"
|
||
|
||
echo
|
||
echo "========== D5.4.1 · OTROS Y PROPUESTAS =========="
|
||
grep -Fq 'INSERT INTO finding_catalog_proposals' api-v3/src/inspection-findings/inspection-findings.service.ts
|
||
grep -Fq "@Get('proposals')" api-v3/src/inspection-findings/finding-catalog.controller.ts
|
||
grep -Fq "@Patch('proposals/:id/review')" api-v3/src/inspection-findings/finding-catalog.controller.ts
|
||
grep -Fq 'FindingCatalogProposalsPanel' web-v2/src/pages/FindingCatalogPage.tsx
|
||
if grep -Fq 'UPDATE inspection_findings SET catalog_item_id' api-v3/src/inspection-findings/finding-catalog.service.ts; then exit 1; fi
|
||
echo "OTROS genera propuesta de oficina sin reescribir el hallazgo original: OK"
|
||
|
||
echo
|
||
echo "========== D5.4.1 · AUDITORÍA Y PERMISOS =========="
|
||
grep -Fq "@RequirePermissions('finding_catalog.manage')" api-v3/src/inspection-findings/finding-catalog.controller.ts
|
||
grep -Fq 'FINDING_CATALOG_TYPE_APPLICABILITY_UPDATED' api-v3/src/inspection-findings/finding-catalog.service.ts
|
||
grep -Fq 'FINDING_CATALOG_ASSET_SELECTION_UPDATED' api-v3/src/inspection-findings/finding-catalog.service.ts
|
||
grep -Fq 'FINDING_CATALOG_PROPOSAL_MATCHED' api-v3/src/inspection-findings/finding-catalog.service.ts
|
||
grep -Fq 'FINDING_CATALOG_PROPOSAL_REJECTED' api-v3/src/inspection-findings/finding-catalog.service.ts
|
||
echo "Configuración contextual y revisión de propuestas quedan en oficina y auditadas: OK"
|
||
|
||
echo
|
||
echo "========== D5.4.1 · 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
|
||
grep -Fq 'VERIFICATION_RESULT_IMMUTABLE' api-v3/src/inspection-verifications/inspection-verifications.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; hallazgos, respuestas y verificaciones históricas siguen protegidos: OK"
|
||
|
||
echo
|
||
echo "========== D5.4.1 · 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.4.1 · 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.4.1 · 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.4.1 · 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.4.1: OK"
|