#!/bin/bash # Test Webapp-Orchestrator Communication # Verifies that the webapp can communicate with the orchestrator echo -e "\n========================================" echo -e " WEBAPP-ORCHESTRATOR COMMUNICATION TEST" echo -e "========================================\n" # Colors GREEN='\033[0;32m' RED='\033[0;31m' YELLOW='\033[0;33m' CYAN='\033[0;36m' NC='\033[0m' PASSED=0 FAILED=0 # Get orchestrator URL if [ -f "webapp/.env.local" ]; then ORCH_URL=$(grep "NEXT_PUBLIC_ORCH_URL" webapp/.env.local | cut -d'=' -f2 | tr -d '"' | tr -d "'" | tr -d ' ') else ORCH_URL="http://localhost:8080" fi echo -e "${CYAN}Orchestrator URL: $ORCH_URL${NC}\n" # Test 1: Orchestrator health echo -e "1. Testing orchestrator health endpoint..." if curl -s "$ORCH_URL/health" > /dev/null 2>&1; then HEALTH=$(curl -s "$ORCH_URL/health" --max-time 5) if echo "$HEALTH" | grep -q "healthy\|status"; then echo -e " ${GREEN}✅ Orchestrator health endpoint accessible${NC}" if command -v jq &> /dev/null; then STATUS=$(echo "$HEALTH" | jq -r '.status // "unknown"' 2>/dev/null) DB_STATUS=$(echo "$HEALTH" | jq -r '.checks.database // "unknown"' 2>/dev/null) echo -e " Status: $STATUS" echo -e " Database: $DB_STATUS" fi ((PASSED++)) else echo -e " ${RED}❌ Health endpoint returned unexpected response${NC}" ((FAILED++)) fi else echo -e " ${RED}❌ Orchestrator not accessible${NC}" echo -e " Make sure orchestrator is running: cd orchestrator && npm run dev" ((FAILED++)) fi # Test 2: CORS headers echo -e "\n2. Testing CORS headers..." CORS_HEADERS=$(curl -s -I "$ORCH_URL/health" --max-time 5 | grep -i "access-control") if [ -n "$CORS_HEADERS" ]; then echo -e " ${GREEN}✅ CORS headers present${NC}" echo "$CORS_HEADERS" | sed 's/^/ /' ((PASSED++)) else echo -e " ${YELLOW}⚠️ CORS headers not found (may cause webapp issues)${NC}" fi # Test 3: API endpoints echo -e "\n3. Testing API endpoints..." # Test compliance status endpoint echo -e " Testing /api/compliance/status..." COMPLIANCE_RESPONSE=$(curl -s -w "\n%{http_code}" "$ORCH_URL/api/compliance/status" --max-time 5 2>&1) COMPLIANCE_CODE=$(echo "$COMPLIANCE_RESPONSE" | tail -n1) if [ "$COMPLIANCE_CODE" = "200" ] || [ "$COMPLIANCE_CODE" = "404" ]; then echo -e " ${GREEN}✅ Compliance endpoint accessible (HTTP $COMPLIANCE_CODE)${NC}" ((PASSED++)) else echo -e " ${YELLOW}⚠️ Compliance endpoint returned HTTP $COMPLIANCE_CODE${NC}" fi # Test plans endpoint (GET) echo -e " Testing GET /api/plans..." PLANS_RESPONSE=$(curl -s -w "\n%{http_code}" "$ORCH_URL/api/plans" --max-time 5 2>&1) PLANS_CODE=$(echo "$PLANS_RESPONSE" | tail -n1) if [ "$PLANS_CODE" = "200" ] || [ "$PLANS_CODE" = "404" ] || [ "$PLANS_CODE" = "405" ]; then echo -e " ${GREEN}✅ Plans endpoint accessible (HTTP $PLANS_CODE)${NC}" ((PASSED++)) else echo -e " ${YELLOW}⚠️ Plans endpoint returned HTTP $PLANS_CODE${NC}" fi # Test 4: Create plan (POST) echo -e "\n4. Testing plan creation..." TEST_PLAN='{ "creator": "test-user", "steps": [ { "type": "borrow", "adapter": "aave", "params": { "asset": "USDC", "amount": "1000" } } ], "maxRecursion": 3, "maxLtv": 0.6 }' CREATE_RESPONSE=$(curl -s -X POST "$ORCH_URL/api/plans" \ -H "Content-Type: application/json" \ -d "$TEST_PLAN" \ -w "\n%{http_code}" \ --max-time 10 2>&1) CREATE_CODE=$(echo "$CREATE_RESPONSE" | tail -n1) CREATE_BODY=$(echo "$CREATE_RESPONSE" | sed '$d') if [ "$CREATE_CODE" = "201" ] || [ "$CREATE_CODE" = "200" ]; then echo -e " ${GREEN}✅ Plan creation successful (HTTP $CREATE_CODE)${NC}" if command -v jq &> /dev/null && [ -n "$CREATE_BODY" ]; then PLAN_ID=$(echo "$CREATE_BODY" | jq -r '.plan_id // .id // empty' 2>/dev/null) if [ -n "$PLAN_ID" ] && [ "$PLAN_ID" != "null" ]; then echo -e " Plan ID: $PLAN_ID" fi fi ((PASSED++)) else echo -e " ${YELLOW}⚠️ Plan creation returned HTTP $CREATE_CODE${NC}" if [ -n "$CREATE_BODY" ]; then echo -e " Response: $(echo "$CREATE_BODY" | head -3)" fi fi # Test 5: Webapp can reach orchestrator echo -e "\n5. Testing webapp-orchestrator connectivity..." if nc -z localhost 3000 2>/dev/null; then echo -e " ${GREEN}✅ Webapp is running${NC}" # Test if webapp can make requests to orchestrator # This is a proxy test - we check if the webapp's API routes work WEBAPP_API=$(curl -s http://localhost:3000/api/health 2>/dev/null || echo "") if [ -n "$WEBAPP_API" ]; then echo -e " ${GREEN}✅ Webapp API routes accessible${NC}" ((PASSED++)) else echo -e " ${YELLOW}⚠️ Webapp API routes may not be configured${NC}" fi else echo -e " ${YELLOW}⚠️ Webapp not running${NC}" echo -e " Start with: cd webapp && npm run dev" fi # Summary echo -e "\n========================================" echo -e " TEST SUMMARY" echo -e "========================================\n" echo -e "${GREEN}✅ Passed: $PASSED${NC}" echo -e "${RED}❌ Failed: $FAILED${NC}" if [ $FAILED -eq 0 ]; then echo -e "\n${GREEN}✅ Webapp-orchestrator communication verified!${NC}\n" exit 0 else echo -e "\n${RED}❌ Some communication tests failed.${NC}\n" exit 1 fi