#!/bin/bash
# filter-test-output.sh — pytest/npm test 실행 시 출력 최적화 안내
# PreToolUse 훅으로 Bash 매처에 등록
# 테스트 명령어 감지 시 --tb=short/-q 옵션 추가를 권장

INPUT=$(cat)
COMMAND=$(echo "$INPUT" | jq -r '.tool_input.command // empty' 2>/dev/null)

# pytest, npm test, jest 등 테스트 명령어 감지
if echo "$COMMAND" | grep -qE '(pytest|npm test|npx jest|python -m pytest)'; then
  # 이미 필터 옵션이 있으면 스킵
  if ! echo "$COMMAND" | grep -qE '(\| grep|\| tail|\| head|--tb=short|--tb=line|--tb=no|-q\b|--quiet)'; then
    echo "⚠️ 테스트 실행 시 --tb=short 또는 -q 옵션 추가를 권장합니다 (토큰 절감)" >&2
  fi
fi

exit 0
