#!/bin/bash
# Run from a current-main checkout after vp i. Requires Linux, sudo and mount namespaces.
# Place wait-load.c and idle-cpu-high-load.e2e.ts alongside this script first.
set -eu
if [ "${1:-}" != namespace ]; then
  cc "$(dirname "$0")/wait-load.c" -o "$(dirname "$0")/wait-load"
  export IDLE_LOAD_BIN="$(realpath "$(dirname "$0")/wait-load")"
  export IDLE_LOAD_METRICS="$(realpath "$(dirname "$0")")/metrics.jsonl"
  cp "$(dirname "$0")/idle-cpu-high-load.e2e.ts" scripts/scenarios/
  exec sudo --preserve-env=PATH,IDLE_LOAD_BIN,IDLE_LOAD_METRICS unshare -m bash "$0" namespace
fi
mount --make-rprivate /
mount --bind /dev/null /proc/pressure/cpu
exec sudo -u "${SUDO_USER:?}" --preserve-env=PATH,IDLE_LOAD_BIN,IDLE_LOAD_METRICS env T3CODE_DEV_SEED=0 T3_SCENARIO_INHERIT_ENV=T3CODE_DEV_SEED vp run scenarios:prove scripts/scenarios/idle-cpu-high-load.e2e.ts --base fd8bb222c11efa7e078d16116ca54fd1d182e263 --head 563bff838681fde4bff35f734bc919646cdb8399 --upload-command 'ghdrop upload'
