[skip ci] wip: preserve Hermes crank development checkpoint

Owner-authorized recovery of accumulated source changes.
Includes accepted work and in-progress changes; NOT a release or acceptance.
Parent baseline 1b6db09bd1. Runtime data, build caches and local credentials excluded.
This commit is contained in:
Hermes DevOps committed 2026-10-25 10:00:22 +00:00
1 parent 1b6db09bd1
commit 75fe5a123c
357 files changed
+118831 -5113

No files matched your search

+86 -26
View File
@@ -4,6 +4,15 @@ set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd)"
TMP_DIR="$ROOT_DIR/.tmp/ui-e2e"
LOG_DIR="$TMP_DIR/logs"
# This script deletes log files and (on a fresh database) the artifact root
# under $TMP_DIR. A symlinked .tmp or .tmp/ui-e2e would redirect that cleanup
# into an unrelated directory, so refuse before the first write through it.
if [[ -L "$ROOT_DIR/.tmp" || -L "$TMP_DIR" ]]; then
echo "refusing to use a symlinked E2E workspace: $TMP_DIR" >&2
exit 1
fi
POSTGRES_CONTAINER="crank-e2e-postgres"
POSTGRES_PORT="${CRANK_E2E_POSTGRES_PORT:-55433}"
ADMIN_PORT="${CRANK_E2E_ADMIN_PORT:-3301}"
@@ -218,7 +227,8 @@ export POSTGRES_USER="$POSTGRES_USER"
export POSTGRES_PASSWORD="$POSTGRES_PASSWORD"
export DATABASE_URL="postgres://$POSTGRES_USER:$POSTGRES_PASSWORD@$POSTGRES_HOST:$POSTGRES_PORT/$POSTGRES_DB"
export SQLX_OFFLINE="true"
export CRANK_STORAGE_ROOT="$TMP_DIR/storage"
STORAGE_ROOT="$TMP_DIR/storage"
export CRANK_STORAGE_ROOT="$STORAGE_ROOT"
export CRANK_ADMIN_BIND="0.0.0.0:$ADMIN_PORT"
export CRANK_MCP_BIND="0.0.0.0:$MCP_PORT"
export CRANK_MCP_REFRESH_MS="1000"
@@ -231,8 +241,19 @@ export CRANK_SESSION_TTL_HOURS="24"
export CRANK_BOOTSTRAP_ADMIN_EMAIL="$ADMIN_EMAIL"
export CRANK_BOOTSTRAP_ADMIN_DISPLAY_NAME="Crank E2E"
export CRANK_BASE_URL="http://127.0.0.1:$UI_PORT"
mkdir -p -m 700 "$CRANK_STORAGE_ROOT"
chmod 700 "$CRANK_STORAGE_ROOT"
# The artifact root is paired with the database lifecycle and is decided after
# the bootstrap step below: a database that was just bootstrapped is empty, so
# stale artifact files must not survive it. Files left from an earlier run have
# no owning database row, the reconciler claims them, and a Resource
# create/update with identical bytes then fails with
# `resource_storage_unavailable`.
# $TMP_DIR is verified above to be a real workspace-local directory, so this
# reference root is independent of the storage path being checked.
EXPECTED_STORAGE_ROOT="$(realpath -m -- "$TMP_DIR")/storage"
if [[ -L "$STORAGE_ROOT" || "$(realpath -m -- "$STORAGE_ROOT")" != "$EXPECTED_STORAGE_ROOT" ]]; then
echo "refusing to touch an unexpected artifact root: $STORAGE_ROOT" >&2
exit 1
fi
(
cd "$ROOT_DIR/apps/ui"
@@ -256,6 +277,14 @@ if ! (
exit 1
fi
# A disposable container is always a brand-new database; an external one is
# only known to be new once the bootstrap below creates its first admin.
FRESH_DATABASE=0
if [[ "$USE_EXTERNAL_POSTGRES" != "1" ]]; then
FRESH_DATABASE=1
fi
BOOTSTRAP_REUSED=0
if ! (
cd "$ROOT_DIR"
cargo run -p admin-api --bin crank-migrate -- admin-auth bootstrap-create \
@@ -263,37 +292,68 @@ if ! (
--display-name "Crank E2E" \
>"$LOG_DIR/bootstrap-create.log" 2>&1
); then
echo "Failed to create the E2E bootstrap contract" >&2
show_startup_log "$LOG_DIR/bootstrap-create.log"
exit 1
# A retained external PostgreSQL still holds the active bootstrap contract
# from the previous start, and its admin account keeps the same constant
# credentials, so a restart has nothing to bootstrap.
if [[ "$USE_EXTERNAL_POSTGRES" = "1" ]] \
&& grep -q '"code":"admin_bootstrap_unavailable"' "$LOG_DIR/bootstrap-create.log"; then
echo "reusing the existing bootstrap contract of the external PostgreSQL"
BOOTSTRAP_REUSED=1
else
echo "Failed to create the E2E bootstrap contract" >&2
show_startup_log "$LOG_DIR/bootstrap-create.log"
exit 1
fi
fi
BOOTSTRAP_JSON="$(tail -n 1 "$LOG_DIR/bootstrap-create.log")"
if ! BOOTSTRAP_TOKEN="$("$PYTHON_BIN" - <<'PY' "$BOOTSTRAP_JSON"
if [[ "$BOOTSTRAP_REUSED" = "0" ]]; then
BOOTSTRAP_JSON="$(tail -n 1 "$LOG_DIR/bootstrap-create.log")"
if ! BOOTSTRAP_TOKEN="$("$PYTHON_BIN" - <<'PY' "$BOOTSTRAP_JSON"
import json, sys
print(json.loads(sys.argv[1])["bootstrap_token"])
PY
)"; then
echo "Failed to parse the E2E bootstrap token" >&2
show_startup_log "$LOG_DIR/bootstrap-create.log"
exit 1
fi
printf '%s' "$BOOTSTRAP_TOKEN" >"$TMP_DIR/bootstrap-token.txt"
printf '%s' "$ADMIN_PASSWORD" >"$TMP_DIR/admin-password.txt"
printf '%s' "$CRANK_PASSWORD_PEPPER" >"$TMP_DIR/password-pepper.txt"
echo "Failed to parse the E2E bootstrap token" >&2
show_startup_log "$LOG_DIR/bootstrap-create.log"
exit 1
fi
printf '%s' "$BOOTSTRAP_TOKEN" >"$TMP_DIR/bootstrap-token.txt"
printf '%s' "$ADMIN_PASSWORD" >"$TMP_DIR/admin-password.txt"
printf '%s' "$CRANK_PASSWORD_PEPPER" >"$TMP_DIR/password-pepper.txt"
if ! (
cd "$ROOT_DIR"
cargo run -p admin-api --bin crank-migrate -- admin-auth bootstrap-complete \
--token-file "$TMP_DIR/bootstrap-token.txt" \
--password-file "$TMP_DIR/admin-password.txt" \
--password-pepper-file "$TMP_DIR/password-pepper.txt" \
>"$LOG_DIR/bootstrap-complete.log" 2>&1
); then
echo "Failed to complete the E2E admin bootstrap" >&2
show_startup_log "$LOG_DIR/bootstrap-complete.log"
exit 1
if ! (
cd "$ROOT_DIR"
cargo run -p admin-api --bin crank-migrate -- admin-auth bootstrap-complete \
--token-file "$TMP_DIR/bootstrap-token.txt" \
--password-file "$TMP_DIR/admin-password.txt" \
--password-pepper-file "$TMP_DIR/password-pepper.txt" \
>"$LOG_DIR/bootstrap-complete.log" 2>&1
); then
# `admin_bootstrap_rejected` on a retained external database means an admin
# account with the same constant password already exists.
if [[ "$USE_EXTERNAL_POSTGRES" = "1" ]] \
&& grep -q '"code":"admin_bootstrap_rejected"' "$LOG_DIR/bootstrap-complete.log"; then
echo "reusing the existing admin account of the external PostgreSQL"
else
echo "Failed to complete the E2E admin bootstrap" >&2
show_startup_log "$LOG_DIR/bootstrap-complete.log"
exit 1
fi
else
# No admin existed before this start, so the database is new.
FRESH_DATABASE=1
fi
fi
if [[ "$FRESH_DATABASE" = "1" ]]; then
rm -rf "$STORAGE_ROOT"
mkdir -p -m 700 "$STORAGE_ROOT"
else
echo "keeping the retained artifact root of the existing database: $STORAGE_ROOT"
mkdir -p -m 700 "$STORAGE_ROOT"
fi
chmod 700 "$STORAGE_ROOT"
# Launch the built executable directly so the test lifecycle controls the
# actual server PID, rather than a Cargo wrapper. This control exists only in
# the local Playwright harness and adds no application endpoint/configuration.