tool-before 832 B

12345678910111213141516171819202122232425262728
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. command -v jq >/dev/null || { echo "jq required"; exit 127; }
  4. TOOL_A="$1"
  5. TOOL_B="$2"
  6. FILE="tool_calls.jsonl"
  7. IDX_A=$(jq -s 'to_entries | map(select(.value.tool == "'"$TOOL_A"'")) | first // empty | .key' "$FILE" 2>/dev/null)
  8. IDX_B=$(jq -s 'to_entries | map(select(.value.tool == "'"$TOOL_B"'")) | first // empty | .key' "$FILE" 2>/dev/null)
  9. if [ -z "$IDX_A" ] || [ "$IDX_A" = "null" ]; then
  10. echo "FAIL: $TOOL_A never called"
  11. exit 1
  12. fi
  13. if [ -z "$IDX_B" ] || [ "$IDX_B" = "null" ]; then
  14. echo "FAIL: $TOOL_B never called"
  15. exit 1
  16. fi
  17. if [ "$IDX_A" -lt "$IDX_B" ]; then
  18. echo "PASS: $TOOL_A (line $((IDX_A + 1))) before $TOOL_B (line $((IDX_B + 1)))"
  19. exit 0
  20. else
  21. echo "FAIL: $TOOL_A at line $((IDX_A + 1)) occurred after $TOOL_B at line $((IDX_B + 1))"
  22. exit 1
  23. fi