# shellcheck shell=bash

# 이 lib 이 부르는 파이썬 검사 파일들의 위치. `validate-workflow.sh` 로 실행할
# 때든 계약 테스트가 함수만 source 할 때든 같은 값이 되도록, 호출자의 변수가
# 아니라 이 파일 자신의 경로에서 해결한다.
OKSTRA_VALIDATOR_CHECKS="$(cd -P "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)/checks"

step() {
  printf '\n[STEP] %s\n' "$1"
}

pass() {
  printf '[PASS] %s\n' "$1"
}

fail() {
  printf '[FAIL] %s\n' "$1" >&2
  exit 1
}

on_error() {
  fail "Unexpected error at line $1"
}

require_file() {
  local target_path="$1"

  if [[ ! -f "$target_path" ]]; then
    fail "Expected file not found: $target_path"
  fi
}

assert_contains() {
  local target_path="$1"
  local expected_text="$2"

  if ! grep -F -- "$expected_text" "$target_path" >/dev/null 2>&1; then
    fail "Expected to find [$expected_text] in $target_path"
  fi
}
