#!/usr/bin/env bash
set -uo pipefail
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
HOOK="$DIR/../preference-consult-directive.sh"
PASS=0; FAIL=0; FAILED=()
OUT=$(printf '{"session_id":"x","prompt":"hi"}' | bash "$HOOK" 2>/dev/null); RC=$?
check() { if eval "$1"; then PASS=$((PASS+1)); else FAIL=$((FAIL+1)); FAILED+=("$2"); fi; }
check '[ "$RC" = "0" ]' "exit 0"
check 'printf "%s" "$OUT" | grep -q "hookSpecificOutput"' "emits envelope"
check 'printf "%s" "$OUT" | grep -q "profile-read"' "names profile-read"
check 'printf "%s" "$OUT" | grep -q "output/"' "names output scratch rule"
check '! printf "%s" "$OUT" | grep -q "—"' "no em-dash"
echo "----- $PASS passed, $FAIL failed -----"
for f in "${FAILED[@]:-}"; do [ -n "$f" ] && echo "  $f"; done
[ "$FAIL" -eq 0 ]
