File size: 1,676 Bytes
21c7db9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env bash
set -euo pipefail

ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
source "$ROOT_DIR/scripts/venv_utils.sh"

RUNTIME_CHECK="false"
for arg in "$@"; do
  case "$arg" in
    --runtime-check) RUNTIME_CHECK="true" ;;
    --help|-h)
      cat <<'USAGE'
Usage: bash scripts/bootstrap_openenv.sh [--runtime-check]

Bootstraps OpenEnv CLI/runtime dependencies and validates the local environment
structure. Optionally performs a runtime contract check against a local server.
USAGE
      exit 0
      ;;
    *)
      echo "Unknown flag: $arg"
      exit 1
      ;;
  esac
done

echo "[bootstrap_openenv] syncing dependencies"
ensure_polyguard_venv
if ! sync_polyguard_requirements >/dev/null 2>&1; then
  echo "[bootstrap_openenv] dependency sync skipped (offline/restricted), continuing"
fi
activate_polyguard_path

if ! command -v openenv >/dev/null 2>&1; then
  echo "[bootstrap_openenv] openenv CLI not found in environment"
  exit 1
fi

echo "[bootstrap_openenv] validating local structure"
openenv validate "$ROOT_DIR"

if [[ "$RUNTIME_CHECK" == "true" ]]; then
  echo "[bootstrap_openenv] running runtime contract check"
  "$POLYGUARD_PYTHON_BIN" -m app.env.fastapi_app >/tmp/polyguard_openenv_bootstrap.log 2>&1 &
  ENV_PID="$!"
  cleanup() {
    if [[ -n "${ENV_PID:-}" ]] && kill -0 "$ENV_PID" >/dev/null 2>&1; then
      kill "$ENV_PID" >/dev/null 2>&1 || true
    fi
  }
  trap cleanup EXIT
  sleep 2
  if ! openenv validate --url "http://127.0.0.1:8100"; then
    echo "[bootstrap_openenv] runtime validation unavailable in current sandbox; continuing with local structure validation"
  fi
  cleanup
  trap - EXIT
fi

echo "openenv_ready"