Files
geointel/scripts/verify_demo_export_workflow.sh
T
Codex 6ea3586a3e
GeoIntel CI / docs-smoke (push) Has been cancelled
GeoIntel CI / contract-smoke (push) Has been cancelled
Initial GeoIntel V1 foundation
2026-06-16 23:36:32 +02:00

132 lines
4.5 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
BASE_URL="${1:-http://localhost:1202}"
TMP_DIR="$(mktemp -d)"
trap 'rm -rf "${TMP_DIR}"' EXIT
if ! command -v curl >/dev/null 2>&1; then
echo "curl is required for demo/export workflow verification" >&2
exit 1
fi
if [ -n "${PYTHON_BIN:-}" ]; then
PYTHON_BIN="${PYTHON_BIN}"
else
PYTHON_BIN=""
for candidate in python3 python.exe python; do
if command -v "${candidate}" >/dev/null 2>&1 && "${candidate}" -c "import json, sys" >/dev/null 2>&1; then
PYTHON_BIN="${candidate}"
break
fi
done
fi
if [ -z "${PYTHON_BIN}" ]; then
echo "A Python interpreter is required for JSON parsing" >&2
exit 1
fi
json_field() {
local file_path="$1"
local expression="$2"
"${PYTHON_BIN}" - "$file_path" "$expression" <<'PY'
import json
import sys
path, expression = sys.argv[1], sys.argv[2]
with open(path, "r", encoding="utf-8") as handle:
payload = json.load(handle)
value = payload
for part in expression.split("."):
if part:
value = value[part]
print(value)
PY
}
require_json_data() {
local file_path="$1"
"${PYTHON_BIN}" - "$file_path" <<'PY'
import json
import sys
with open(sys.argv[1], "r", encoding="utf-8") as handle:
payload = json.load(handle)
if "data" not in payload:
raise SystemExit("Response is not a canonical GeoIntel data envelope")
PY
}
echo "== GeoIntel demo/export workflow verification =="
echo "Base URL: ${BASE_URL}"
curl -fsS "${BASE_URL%/}/health" > "${TMP_DIR}/health.json"
if ! grep -q '"status":"ok"' "${TMP_DIR}/health.json"; then
echo "Health endpoint did not return ok:" >&2
cat "${TMP_DIR}/health.json" >&2
exit 1
fi
curl -fsS -X POST "${BASE_URL%/}/api/v1/demo/workflow" > "${TMP_DIR}/demo.json"
require_json_data "${TMP_DIR}/demo.json"
project_id="$(json_field "${TMP_DIR}/demo.json" "data.project_id")"
candidate_dataset_id="$(json_field "${TMP_DIR}/demo.json" "data.candidate_dataset_id")"
curl -fsS "${BASE_URL%/}/api/v1/projects/${project_id}/quality-checks" > "${TMP_DIR}/quality_checks.json"
require_json_data "${TMP_DIR}/quality_checks.json"
quality_count="$(json_field "${TMP_DIR}/quality_checks.json" "data.total")"
if [ "${quality_count}" -lt 1 ]; then
echo "Expected at least one persisted QA/QC result after demo workflow" >&2
exit 1
fi
curl -fsS -X POST "${BASE_URL%/}/api/v1/exports/metadata" \
-H "Content-Type: application/json" \
-d "{\"project_id\":\"${project_id}\"}" > "${TMP_DIR}/metadata_export.json"
require_json_data "${TMP_DIR}/metadata_export.json"
metadata_export_id="$(json_field "${TMP_DIR}/metadata_export.json" "data.export_id")"
curl -fsS -X POST "${BASE_URL%/}/api/v1/exports/report" \
-H "Content-Type: application/json" \
-d "{\"project_id\":\"${project_id}\"}" > "${TMP_DIR}/report_export.json"
require_json_data "${TMP_DIR}/report_export.json"
report_export_id="$(json_field "${TMP_DIR}/report_export.json" "data.export_id")"
curl -fsS -X POST "${BASE_URL%/}/api/v1/exports/geojson" \
-H "Content-Type: application/json" \
-d "{\"export_kind\":\"dataset\",\"dataset_id\":\"${candidate_dataset_id}\"}" > "${TMP_DIR}/dataset_export.json"
require_json_data "${TMP_DIR}/dataset_export.json"
dataset_export_id="$(json_field "${TMP_DIR}/dataset_export.json" "data.export_id")"
curl -fsS "${BASE_URL%/}/api/v1/exports/projects/${project_id}/exports" > "${TMP_DIR}/exports.json"
require_json_data "${TMP_DIR}/exports.json"
export_count="$(json_field "${TMP_DIR}/exports.json" "data.total")"
if [ "${export_count}" -lt 3 ]; then
echo "Expected at least three exports after workflow smoke, found ${export_count}" >&2
exit 1
fi
curl -fsS "${BASE_URL%/}/api/v1/exports/${metadata_export_id}/content" > "${TMP_DIR}/metadata_content.json"
require_json_data "${TMP_DIR}/metadata_content.json"
if ! grep -q '"quality_checks"' "${TMP_DIR}/metadata_content.json"; then
echo "Metadata export content does not include QA/QC summary" >&2
exit 1
fi
curl -fsS "${BASE_URL%/}/api/v1/exports/${dataset_export_id}/download" > "${TMP_DIR}/dataset_download.geojson"
if ! grep -q '"FeatureCollection"' "${TMP_DIR}/dataset_download.geojson"; then
echo "Dataset GeoJSON download is not a FeatureCollection" >&2
exit 1
fi
curl -fsS "${BASE_URL%/}/api/v1/exports/${report_export_id}/download" > "${TMP_DIR}/report_download.html"
if ! grep -qi '<!doctype html>' "${TMP_DIR}/report_download.html"; then
echo "Report download is not an HTML artifact" >&2
exit 1
fi
echo "Demo/export workflow verification passed"
echo "Project: ${project_id}"
echo "Exports created: metadata=${metadata_export_id}, report=${report_export_id}, dataset=${dataset_export_id}"