#!/usr/bin/env bash # /workspace/hyperstitionstudio-core/deploy/test-first-deployment.sh # End-to-end verification of the per-repository deployment layout (including haiperdohp-jemaytreeah). # # Mode 1 (Default — Local / Staging Self-Contained HTTP Smoke Test): # Hydrates LIVE_REPOS (default: /tmp/hyperstition-live-repos), starts a local HTTP server # on 127.0.0.1:18090, and verifies HTTP 200 OK across all 26 portal, graph, encyclopedia, # haiperdohp-jemaytreeah calculator, CI & schema routes. # # Mode 2 (Remote VPS Verification): # ./test-first-deployment.sh https://hyperstitionstud.io set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)" TARGET_BASE_URL="${1:-}" SERVER_PID="" MCP_PID="" cleanup() { if [[ -n "${SERVER_PID}" ]] && kill -0 "${SERVER_PID}" 2>/dev/null; then kill "${SERVER_PID}" 2>/dev/null || true fi if [[ -n "${MCP_PID}" ]] && kill -0 "${MCP_PID}" 2>/dev/null; then kill "${MCP_PID}" 2>/dev/null || true fi } trap cleanup EXIT if [[ -z "${TARGET_BASE_URL}" ]]; then export LIVE_REPOS="${LIVE_REPOS:-/tmp/hyperstition-live-repos}" export HYPERSTITION_TELEMETRY_DB_PATH="${HYPERSTITION_TELEMETRY_DB_PATH:-/tmp/hyperstition-deploy-test-telemetry.db}" rm -rf "${LIVE_REPOS}" "${HYPERSTITION_TELEMETRY_DB_PATH}" "${HYPERSTITION_TELEMETRY_DB_PATH}-wal" "${HYPERSTITION_TELEMETRY_DB_PATH}-shm" echo "[1/4] Hydrating per-repository webroot at ${LIVE_REPOS} via sync-vps-repos.sh --no-pull..." "${SCRIPT_DIR}/sync-vps-repos.sh" --no-pull PORT="${TEST_PORT:-18090}" MCP_PORT="${TEST_MCP_PORT:-18095}" echo "[2/4] Starting local HTTP server on http://127.0.0.1:${PORT} and MCP HTTP server on http://127.0.0.1:${MCP_PORT}/mcp..." python3 -m http.server "${PORT}" --bind 127.0.0.1 --directory "${LIVE_REPOS}" >/dev/null 2>&1 & SERVER_PID="$!" PYTHONPATH="${SCRIPT_DIR}/../src" python3 "${SCRIPT_DIR}/../src/hyperstitionstud_io/mcp/server.py" --transport http --host 127.0.0.1 --port "${MCP_PORT}" >/dev/null 2>&1 & MCP_PID="$!" sleep 0.6 TARGET_BASE_URL="http://127.0.0.1:${PORT}" MCP_URL="http://127.0.0.1:${MCP_PORT}/mcp" API_V1_URL="http://127.0.0.1:${MCP_PORT}/api/v1" else MCP_URL="${TARGET_BASE_URL%/}/mcp" API_V1_URL="${TARGET_BASE_URL%/}/api/v1" fi echo "[3/4] Verifying all active portal, /learn/, /quant/, graph, encyclopedia, haiperdohp-jemaytreeah (.gitignore artifacts), CI & schema routes against ${TARGET_BASE_URL}..." ROUTES=( "/" "/assets/hs-group3-basalt-chamfer.css" "/assets/hs-guile-scheme-repl.js" "/assets/hs-matrix-coderain.js" "/assets/hs-mobile-ui.js" "/assets/matrix-font.woff2" "/assets/closeups/quadrant-1-cybermemetics-calc-graph.png" "/assets/closeups/quadrant-1-tab-2-graph.png" "/assets/closeups/quadrant-2-esoteric-finance-quant.png" "/assets/closeups/quadrant-2-tab-2-bayesian-fred.png" "/assets/closeups/quadrant-2-tab-3-leaderboard-card.png" "/assets/closeups/quadrant-3-info-science-novice-learn-polyglot.png" "/assets/closeups/quadrant-3-tab-2-math-guile.png" "/assets/closeups/quadrant-3-tab-3-math-ts-rust.png" "/assets/closeups/quadrant-4-operators-deployment-vps.png" "/assets/closeups/quadrant-4-tab-2-mcp-etag.png" "/assets/closeups/quadrant-4-tab-3-ci-gates.png" "/donate/index.html" "/learn/index.html" "/learn/learn-app.js" "/quant/index.html" "/quant/quant-app.js" "/quant/quant-tutorials.js" "/quant/audio/voice-manifest.json" "/quant/audio/ep01-s1.wav" "/quant/audio/ep04-s1.wav" "/quant/quant-timeseries-data.js" "/quant/quant-timeseries.json" "/quant/real-market-history.json" "/quant/real-macro-indicators.json" "/quant/daily-brief-latest.json" "/quant/OPERATORS-MANUAL-QUANT-TIMESERIES-WORKBENCH.pdf" "/graph/index.html" "/graph/graph-data.js" "/graph/encyclopedia-graph.json" "/graph/OPERATORS-MANUAL-ENCYCLOPEDIA-KNOWLEDGE-GRAPH.pdf" "/graph/docs/specification-concentric-eti-tier-ring-radar-d-periphery.pdf" "/graph/docs/cross-repo-dependency-and-audit-flow-diagram.html" "/graph/docs/cross-repo-dependency-and-audit-flow-diagram.pdf" "/graph/docs/periodic-harvest-cicd-to-vps-flow-diagram.png" "/graph/docs/VPS-AND-GIT-OPERATOR-DEPLOYMENT-GUIDE.pdf" "/graph/docs/OPERATORS-MANUAL-LLM-TOKEN-DEPENDENT-DATA-PIPELINES.pdf" "/graph/docs/archive/archive-manifest.json" "/graph/docs/plans/inactive/inactive-archive-manifest.json" "/graph/docs/plans/inactive/PLAN-PIECEWISE-COMPLETE-SOFTWARE-ENGINEERING-EXPLICATION.pdf" "/graph/docs/plans/inactive/PLAN-PIECEWISE-COMPLETE-MATHEMATICS-AND-INFO-SCIENCE-EXPLICATION.pdf" "/graph/docs/plans/inactive/PLAN-LEXICAL-AND-ETYMOLOGICAL-SIMPLIFICATION.pdf" "/graph/docs/plans/inactive/PLAN-LLM-TOKEN-ECONOMIZER-AND-VARIANCE-ROUTING.pdf" "/graph/docs/plans/inactive/PLAN-LLM-TOKEN-ECONOMIZER-DATA-FIDELITY-AND-DEGRADATION-RISK-EVALUATION.pdf" "/encyclopedia/00-index-and-ontological-atlas/00-master-encyclopedia-index-a-to-z.pdf" "/technocapital-singularity-zoology/encyclopedia/00-index-and-ontological-atlas/00-master-encyclopedia-index-a-to-z.pdf" "/zoology/encyclopedia-of-technocapital-singularity-zoology-overview-and-manifest.pdf" "/zoology/technocapital-singularity-zoology-comprehensive-glossary.pdf" "/zoology/tier-list-technocapital-assemblage-builds.png" "/zoology/tier-list-technocapital-assemblage-builds.pdf" "/zoology/proposal-fund-manager-novel-investment-discovery.pdf" "/zoology/proposal-corporate-board-technocapital-allocation.pdf" "/zoology/m7-emergent-subclass-bidirectional-aq-nucleation.pdf" "/archive/00-index-and-methodology.md" "/calc/index.html" "/calc/config.js" "/calc/calc/ciphers.js" "/calc/calc/database.js" "/calc/db_lite.json" "/calc/db.json" "/ci/ONBOARDING-INGGLISH-AQ.pdf" "/ci/ci-audit-report.json" "/schemas/v1/encyclopedia-graph.schema.json" "/schemas/v1/learn-progress-state.schema.json" "/schemas/v1/financial-aq-harvest.schema.json" "/schemas/v1/quant-timeseries.schema.json" "/schemas/v1/ticker-stats-card.schema.json" ) # Dynamically append enabled /engineering/* and /math/* routes from their manifests so piecewise/reverted subsets work seamlessly for man_p in \ "${SCRIPT_DIR}/../site/engineering/engineering-manifest.json" \ "${SCRIPT_DIR}/../site/math/math-manifest.json"; do if [[ -f "${man_p}" ]]; then while IFS= read -r dyn_r; do if [[ -n "${dyn_r}" ]]; then ROUTES+=("${dyn_r}") fi done < <(python3 -c 'import json,sys; d=json.load(open(sys.argv[1])); print("\n".join(d.get("enabled_routes",[])))' "${man_p}") fi done PASS_COUNT=0 for route in "${ROUTES[@]}"; do url="${TARGET_BASE_URL}${route}" code="$(curl -s -o /dev/null -w "%{http_code}" "${url}")" if [[ "${code}" == "200" ]]; then PASS_COUNT=$((PASS_COUNT + 1)) echo " [200 OK] ${route}" else echo " [FAIL ${code}] ${url}" >&2 exit 1 fi done echo "[4/4] Verifying stateless read-only MCP Streamable HTTP endpoint (${MCP_URL})..." mcp_get_code="$(curl -s -o /dev/null -w "%{http_code}" "${MCP_URL}")" if [[ "${mcp_get_code}" != "200" ]]; then echo " [FAIL ${mcp_get_code}] GET ${MCP_URL}" >&2 exit 1 fi echo " [200 OK] GET ${MCP_URL} (MCP capability manifest)" mcp_post_out="$(curl -s -X POST "${MCP_URL}" -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"hs_evaluate_aq_and_ingglish","arguments":{"terms":["capital","capture","folds"]}}}')" if ! grep -q 'exact_gen1_singularity.*true' <<<"${mcp_post_out}"; then echo " [FAIL] POST ${MCP_URL} did not return exact_gen1_singularity=true" >&2 exit 1 fi echo " [200 OK] POST ${MCP_URL} (JSON-RPC 2.0 tools/call hs_evaluate_aq_and_ingglish verified)" echo "[4b/4] Verifying stateless REST API v1 & OpenAPI 3.1 endpoints (${API_V1_URL})..." for api_sub in "/status" "/openapi.json" "/quant/timeseries?symbol=NVDA" "/quant/instruments/NVDA" "/zoology/pokedex/NVDA" "/dossiers/71?highlight=envideea"; do api_code="$(curl -s -o /dev/null -w "%{http_code}" "${API_V1_URL}${api_sub}")" if [[ "${api_code}" != "200" ]]; then echo " [FAIL ${api_code}] GET ${API_V1_URL}${api_sub}" >&2 exit 1 fi echo " [200 OK] GET ${API_V1_URL}${api_sub}" done if [[ -n "${HYPERSTITION_TELEMETRY_DB_PATH:-}" ]] && [[ -f "${LIVE_REPOS}/hyperstitionstudio-core/deploy/logrotate.d/hyperstition-sqlite-meta" ]]; then echo "[4c/4] Verifying SQLite REST/MCP metadata DB population & quiescent logrotate.d compression + truncation..." PYTHONPATH="${SCRIPT_DIR}/../src" python3 - <<'PY' import os from pathlib import Path from hyperstitionstud_io.db.sqlite_meta import get_api_telemetry_summary, run_logrotate_directive tel_db = Path(os.environ["HYPERSTITION_TELEMETRY_DB_PATH"]) conf_p = Path(os.environ["LIVE_REPOS"]) / "hyperstitionstudio-core" / "deploy" / "logrotate.d" / "hyperstition-sqlite-meta" summary = get_api_telemetry_summary(tel_db) assert summary["total_requests"] >= 5, f"Expected >= 5 recorded MCP/REST calls, got {summary['total_requests']}" lr_out = run_logrotate_directive(conf_path=conf_p, telemetry_db_path=tel_db, max_bytes_override=1024) assert lr_out["truncated"] is True and lr_out["quiescent"] is True and lr_out["integrity_check"] == "ok", lr_out assert lr_out["compress_enabled"] is True and lr_out["compressed_archive_bytes"] > 0 and Path(lr_out["compressed_archive_path"]).is_file(), lr_out print(f" [OK] SQLite metadata DB populated ({summary['total_requests']} calls), compressed to {Path(lr_out['compressed_archive_path']).name} ({lr_out['compressed_archive_bytes']} B) & quiescently truncated via {conf_p.name} (default {lr_out['configured_size_directive']}).") PY fi echo "[4d/4] Running 6-Gate Ad-Hoc Public API & Surface Regression Suite (hs-public-smoke Gates P1-P6) against ${TARGET_BASE_URL}..." PYTHONPATH="${SCRIPT_DIR}/../src" python3 -m hyperstitionstud_io.ci.public_regression \ --base-url "${TARGET_BASE_URL}" \ --mcp-url "${MCP_URL}" \ --api-v1-url "${API_V1_URL}" echo "[OK] All ${PASS_COUNT}/${#ROUTES[@]} static routes + 2 MCP HTTP endpoints + 4 REST API v1 endpoints + 6 Public Regression Gates verified (HTTP 200 OK)."