/ .github / scripts / test-claude-code-integration.sh
test-claude-code-integration.sh
 1  #!/bin/bash
 2  # Quick test to verify Claude Code CLI integration works.
 3  # Run this OUTSIDE of a Claude Code session.
 4  # Usage: bash .github/scripts/test-claude-code-integration.sh
 5  
 6  set -e
 7  
 8  echo "=== Testing Claude Code CLI integration ==="
 9  
10  # 1. Verify claude CLI is available
11  if ! command -v claude &> /dev/null; then
12      echo "❌ claude CLI not found. Install Claude Code first."
13      exit 1
14  fi
15  echo "✅ claude CLI found: $(which claude)"
16  
17  # 2. Test JSON output format with minimal context
18  echo ""
19  echo "--- Testing --output-format json (minimal context) ---"
20  RESULT=$(claude -p "Reply with exactly: enhanced-summary-test" \
21      --output-format json \
22      --model sonnet \
23      --max-turns 1 \
24      --no-chrome \
25      --disallowedTools '*' \
26      2>/dev/null)
27  
28  # 3. Extract from the array format: find the assistant message
29  EXTRACTED=$(echo "$RESULT" | python3 -c "
30  import sys, json
31  data = json.load(sys.stdin)
32  for item in data:
33      if item.get('type') == 'assistant':
34          text = item['message']['content'][0]['text']
35          print(text)
36          sys.exit(0)
37  print('NO_ASSISTANT_MSG')
38  " 2>/dev/null || echo "PARSE_FAILED")
39  
40  echo "Extracted text: $EXTRACTED"
41  
42  # 4. Check cost
43  COST=$(echo "$RESULT" | python3 -c "
44  import sys, json
45  data = json.load(sys.stdin)
46  for item in data:
47      if item.get('type') == 'result':
48          print(f\"Cost: \${item.get('total_cost_usd', 'unknown')}\")
49          sys.exit(0)
50  " 2>/dev/null || echo "unknown")
51  echo "$COST"
52  
53  if [ "$EXTRACTED" = "NO_ASSISTANT_MSG" ] || [ "$EXTRACTED" = "PARSE_FAILED" ]; then
54      echo "❌ Could not extract result from Claude Code output"
55      exit 1
56  fi
57  
58  echo "✅ Claude Code CLI integration working correctly"
59  
60  # 5. Optionally test the full enhancer
61  if [ "${1}" = "--full" ]; then
62      echo ""
63      echo "--- Testing full enhancer with Claude Code backend ---"
64      cd "$(dirname "$0")"
65      unset ANTHROPIC_API_KEY
66      USE_CLAUDE_CODE=true ACTIVITY_SCORE=100 node claude-enhancer.js 2>&1
67  fi
68  
69  echo ""
70  echo "=== Done ==="