#!/bin/bash
# Selfhost pipeline v2 (Hako) → MIR(JSON v0) S1/S2 repeat determinism (3x)
set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"; if ROOT_GIT=$(git -C "$SCRIPT_DIR" rev-parse --show-toplevel 2>/dev/null); then ROOT="$ROOT_GIT"; else ROOT="$(cd "$SCRIPT_DIR/../../../../../../../../.." && pwd)"; fi
source "$ROOT/tools/smokes/v2/lib/test_runner.sh"; require_env || exit 2

set +e
out=$(bash "$ROOT/tools/selfhost/bootstrap_s1_s2_s3_repeat.sh" 'bash tools/selfhost/gen_v0_from_selfhost_pipeline_min.sh' 2>&1)
rc=$?
set -e
if [ "$rc" -eq 0 ]; then
  echo "[PASS] selfhost_v0_s1s2_repeat_canary_vm"
  exit 0
fi
echo "[FAIL] selfhost_v0_s1s2_repeat_canary_vm (rc=$rc)" >&2
printf '%s\n' "$out" | sed -n '1,160p' >&2
exit 1

