#!/usr/bin/env bash
# task-135：nightly 可选 RPA probe；secrets 缺失时跳过
set -euo pipefail

ROOT="$(cd "$(dirname "$0")/.." && pwd)"
cd "$ROOT"
LOG="${PROBE_NIGHTLY_LOG:-probe-nightly.log}"

if [[ -z "${MOTHERSHIP_USERNAME:-}" || -z "${MOTHERSHIP_PASSWORD:-}" ]]; then
  echo "SKIP: 未配置 MOTHERSHIP_USERNAME / MOTHERSHIP_PASSWORD，跳过 probe"
  exit 0
fi

if [[ -z "${MOTHERSHIP_QUOTE_URLS:-}" ]]; then
  echo "SKIP: 未配置 MOTHERSHIP_QUOTE_URLS，跳过 probe"
  exit 0
fi

export RPA_MOCK_MODE=false

echo "=== nightly RPA probe 3/3 开始 ===" | tee "$LOG"
if bash scripts/probe-rpa-3x.sh 2>&1 | tee -a "$LOG"; then
  echo "=== probe 3/3 PASS ===" | tee -a "$LOG"
  exit 0
fi

echo "=== probe 3/3 FAIL ===" | tee -a "$LOG"
exit 1
