#!/bin/bash
set -euo pipefail

PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
BUNDLED_NODE="$HOME/.cache/codex-runtimes/codex-primary-runtime/dependencies/node/bin/node"
BUNDLED_NODE_MODULES="$HOME/.cache/codex-runtimes/codex-primary-runtime/dependencies/node/node_modules"

if [ -z "${NODE_BIN:-}" ] && [ -x "$BUNDLED_NODE" ]; then
  NODE_BIN="$BUNDLED_NODE"
fi

if [ -z "${NODE_BIN:-}" ]; then
  NODE_BIN="node"
fi

if [ -d "$BUNDLED_NODE_MODULES" ] && [ -z "${NODE_PATH:-}" ]; then
  export NODE_PATH="$BUNDLED_NODE_MODULES"
fi

exec "$NODE_BIN" "$PROJECT_ROOT/scripts/check_observability_visual_contract.js" "$@"
