test_session_persistence.sh
1 #!/bin/bash 2 # Test session persistence across separate Mix runs 3 4 set -euo pipefail 5 6 GREEN='\033[0;32m' 7 RED='\033[0;31m' 8 YELLOW='\033[1;33m' 9 NC='\033[0m' 10 11 echo -e "${YELLOW}Testing PostgreSQL Session Persistence Fix${NC}" 12 echo "" 13 14 # Test 1: Create session 15 echo -e "${YELLOW}Test 1: Creating new session...${NC}" 16 17 RESULT1=$(cd apps/ceo && timeout 180 mix run -e ' 18 alias EchoShared.LLM.DecisionHelper 19 20 case DecisionHelper.consult_session(:ceo, nil, "What is my role as CEO?") do 21 {:ok, result} -> 22 IO.puts("SUCCESS") 23 IO.puts("SESSION_ID:#{result.session_id}") 24 IO.puts("TURN:#{result.turn_count}") 25 IO.puts("TOKENS:#{result.total_tokens}") 26 {:error, reason} -> 27 IO.puts("FAILED:#{inspect(reason)}") 28 exit(1) 29 end 30 ' 2>&1) 31 32 if echo "$RESULT1" | grep -q "SUCCESS"; then 33 SESSION_ID=$(echo "$RESULT1" | grep "SESSION_ID:" | cut -d: -f2-) 34 TURN1=$(echo "$RESULT1" | grep "TURN:" | cut -d: -f2-) 35 TOKENS1=$(echo "$RESULT1" | grep "TOKENS:" | cut -d: -f2-) 36 37 echo -e "${GREEN}✅ Session created${NC}" 38 echo " Session ID: $SESSION_ID" 39 echo " Turn: $TURN1" 40 echo " Tokens: $TOKENS1" 41 echo "" 42 else 43 echo -e "${RED}❌ Session creation failed${NC}" 44 echo "$RESULT1" 45 exit 1 46 fi 47 48 # Test 2: Continue session (separate Mix run) 49 echo -e "${YELLOW}Test 2: Continuing session in separate Mix run...${NC}" 50 51 RESULT2=$(cd apps/ceo && timeout 180 mix run -e " 52 alias EchoShared.LLM.DecisionHelper 53 54 case DecisionHelper.consult_session(:ceo, \"$SESSION_ID\", \"What are my top priorities?\") do 55 {:ok, result} -> 56 IO.puts(\"SUCCESS\") 57 IO.puts(\"SESSION_ID:#{result.session_id}\") 58 IO.puts(\"TURN:#{result.turn_count}\") 59 IO.puts(\"TOKENS:#{result.total_tokens}\") 60 {:error, reason} -> 61 IO.puts(\"FAILED:#{inspect(reason)}\") 62 exit(1) 63 end 64 " 2>&1) 65 66 if echo "$RESULT2" | grep -q "SUCCESS"; then 67 TURN2=$(echo "$RESULT2" | grep "TURN:" | cut -d: -f2-) 68 TOKENS2=$(echo "$RESULT2" | grep "TOKENS:" | cut -d: -f2-) 69 70 echo -e "${GREEN}✅ Session continuation successful${NC}" 71 echo " Turn: $TURN2 (was $TURN1)" 72 echo " Tokens: $TOKENS2 (was $TOKENS1)" 73 echo "" 74 else 75 echo -e "${RED}❌ Session continuation failed${NC}" 76 echo "$RESULT2" 77 exit 1 78 fi 79 80 # Test 3: Verify turn count increased 81 if [ "$TURN2" -gt "$TURN1" ]; then 82 echo -e "${GREEN}✅ Turn count increased correctly${NC}" 83 else 84 echo -e "${RED}❌ Turn count did not increase${NC}" 85 exit 1 86 fi 87 88 # Test 4: Verify tokens increased (context grew) 89 if [ "$TOKENS2" -gt "$TOKENS1" ]; then 90 echo -e "${GREEN}✅ Token count increased (context preserved)${NC}" 91 else 92 echo -e "${RED}❌ Token count did not increase${NC}" 93 exit 1 94 fi 95 96 # Test 5: End session 97 echo "" 98 echo -e "${YELLOW}Test 3: Ending session...${NC}" 99 100 RESULT3=$(cd apps/ceo && timeout 60 mix run -e " 101 alias EchoShared.LLM.Session 102 103 case Session.end_session(\"$SESSION_ID\") do 104 {:ok, _conversation} -> 105 IO.puts(\"SESSION_ENDED\") 106 {:error, reason} -> 107 IO.puts(\"FAILED:#{inspect(reason)}\") 108 end 109 " 2>&1) 110 111 if echo "$RESULT3" | grep -q "SESSION_ENDED"; then 112 echo -e "${GREEN}✅ Session ended successfully${NC}" 113 else 114 echo -e "${RED}❌ Session end failed${NC}" 115 echo "$RESULT3" 116 exit 1 117 fi 118 119 echo "" 120 echo -e "${GREEN}═══════════════════════════════════════════${NC}" 121 echo -e "${GREEN}✅ All tests passed!${NC}" 122 echo -e "${GREEN}Session persistence is working correctly${NC}" 123 echo -e "${GREEN}═══════════════════════════════════════════${NC}" 124 125 exit 0