/ scripts / testing / test_agents.sh
test_agents.sh
  1  #!/bin/bash
  2  # Test script for ECHO agents - Validates MCP protocol communication
  3  
  4  set -e
  5  
  6  # Colors
  7  RED='\033[0;31m'
  8  GREEN='\033[0;32m'
  9  YELLOW='\033[1;33m'
 10  BLUE='\033[0;34m'
 11  CYAN='\033[0;36m'
 12  NC='\033[0m' # No Color
 13  
 14  echo -e "${BLUE}╺━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╸${NC}"
 15  echo -e "${BLUE}  ECHO Agent MCP Protocol Test${NC}"
 16  echo -e "${BLUE}╺━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╸${NC}"
 17  echo ""
 18  
 19  # Create test requests
 20  TEST_DIR=$(mktemp -d)
 21  trap "rm -rf $TEST_DIR" EXIT
 22  
 23  # Valid JSON-RPC initialize request
 24  cat > "$TEST_DIR/initialize.json" << 'EOF'
 25  {"jsonrpc":"2.0","method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test-client","version":"1.0.0"}},"id":1}
 26  EOF
 27  
 28  # Valid JSON-RPC tools/list request
 29  cat > "$TEST_DIR/tools_list.json" << 'EOF'
 30  {"jsonrpc":"2.0","method":"tools/list","params":{},"id":2}
 31  EOF
 32  
 33  # List of agents to test
 34  AGENTS=("ceo" "cto" "chro" "operations_head" "product_manager" "senior_architect" "senior_developer" "test_lead" "uiux_engineer")
 35  
 36  PASSED=0
 37  FAILED=0
 38  TOTAL=${#AGENTS[@]}
 39  
 40  echo -e "${CYAN}Testing ${TOTAL} agents...${NC}"
 41  echo ""
 42  
 43  for agent in "${AGENTS[@]}"; do
 44      AGENT_PATH="apps/$agent/$agent"
 45  
 46      if [[ ! -x "$AGENT_PATH" ]]; then
 47          echo -e "${RED}✗ $agent${NC} - executable not found"
 48          ((FAILED++))
 49          continue
 50      fi
 51  
 52      echo -e "${YELLOW}Testing $agent...${NC}"
 53  
 54      # Test 1: Initialize
 55      echo -n "  1. Initialize request... "
 56      RESPONSE=$(timeout 5s cat "$TEST_DIR/initialize.json" | ./"$AGENT_PATH" 2>/dev/null | head -1)
 57  
 58      if echo "$RESPONSE" | jq -e '.result.capabilities' > /dev/null 2>&1; then
 59          echo -e "${GREEN}✓${NC}"
 60          INIT_PASS=true
 61      else
 62          echo -e "${RED}✗${NC}"
 63          echo "     Response: $RESPONSE"
 64          INIT_PASS=false
 65      fi
 66  
 67      # Test 2: Tools list
 68      echo -n "  2. Tools list request... "
 69      if [[ "$INIT_PASS" == true ]]; then
 70          # Send both initialize and tools/list
 71          RESPONSE=$(timeout 5s bash -c "cat '$TEST_DIR/initialize.json'; echo ''; cat '$TEST_DIR/tools_list.json'" | ./"$AGENT_PATH" 2>/dev/null | tail -1)
 72  
 73          if echo "$RESPONSE" | jq -e '.result.tools[]' > /dev/null 2>&1; then
 74              TOOL_COUNT=$(echo "$RESPONSE" | jq '.result.tools | length')
 75              echo -e "${GREEN}✓${NC} ($TOOL_COUNT tools)"
 76              TOOLS_PASS=true
 77          else
 78              echo -e "${RED}✗${NC}"
 79              echo "     Response: $RESPONSE"
 80              TOOLS_PASS=false
 81          fi
 82      else
 83          echo -e "${YELLOW}skipped${NC} (init failed)"
 84          TOOLS_PASS=false
 85      fi
 86  
 87      # Summary for this agent
 88      if [[ "$INIT_PASS" == true && "$TOOLS_PASS" == true ]]; then
 89          echo -e "  ${GREEN}✓ $agent: PASSED${NC}"
 90          ((PASSED++))
 91      else
 92          echo -e "  ${RED}✗ $agent: FAILED${NC}"
 93          ((FAILED++))
 94      fi
 95      echo ""
 96  done
 97  
 98  echo -e "${BLUE}╺━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╸${NC}"
 99  echo -e "${CYAN}  Test Summary${NC}"
100  echo -e "${BLUE}╺━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╸${NC}"
101  echo ""
102  echo -e "  Total agents: ${TOTAL}"
103  echo -e "  ${GREEN}Passed: ${PASSED}${NC}"
104  echo -e "  ${RED}Failed: ${FAILED}${NC}"
105  echo ""
106  
107  if [[ $FAILED -eq 0 ]]; then
108      echo -e "${GREEN}✓ All agents are working correctly!${NC}"
109      echo ""
110      echo -e "${CYAN}Next steps:${NC}"
111      echo "  1. Run ./setup_claude_desktop.sh to configure Claude Desktop"
112      echo "  2. Restart Claude Desktop"
113      echo "  3. Start using ECHO agents!"
114      exit 0
115  else
116      echo -e "${RED}✗ Some agents failed tests${NC}"
117      echo ""
118      echo -e "${YELLOW}Troubleshooting:${NC}"
119      echo "  - Check if PostgreSQL is running: pg_isready"
120      echo "  - Check if Redis is running: redis-cli ping"
121      echo "  - Run migrations: cd shared && mix ecto.migrate"
122      echo "  - View detailed logs by running agent directly:"
123      echo "    echo '{\"jsonrpc\":\"2.0\",\"method\":\"initialize\",\"params\":{},\"id\":1}' | ./apps/ceo/ceo"
124      exit 1
125  fi