#!/bin/bash # Test Protocol for Phase 0.5 Control Mode Spike set -e SESSION="pi-cc" LOG_FILE="/tmp/spike-cc-test-$(date +%s).log" DURATION=300 # 5 minutes echo "=== Phase 0.5 Control Mode Test Protocol ===" echo "Session: $SESSION" echo "Log: $LOG_FILE" echo "Duration: ${DURATION}s (5 minutes)" echo "" # Clean up any existing session tmux kill-session -t "$SESSION" 2>/dev/null || true echo "[1/6] Starting spike-cc in background..." cd "$(dirname "$0")" npm run spike-cc > "$LOG_FILE" 2>&1 & SPIKE_PID=$! echo " Spike PID: $SPIKE_PID" sleep 3 # Check if spike is still running if ! kill -0 $SPIKE_PID 2>/dev/null; then echo " ERROR: Spike process died!" tail -50 "$LOG_FILE" exit 1 fi echo " ✓ Spike running" echo "" echo "[2/6] Verifying session exists..." if ! tmux has-session -t "$SESSION" 2>/dev/null; then echo " ERROR: Session $SESSION not found!" kill $SPIKE_PID 2>/dev/null exit 1 fi echo " ✓ Session exists" echo "" echo "[3/6] Testing parallel tmux attach (critical P-2 requirement)..." echo " Opening a 10-second tmux attach in background..." (tmux attach -t "$SESSION" 2>&1 | head -20 > /tmp/spike-parallel-attach.log) & ATTACH_PID=$! sleep 5 if ! kill -0 $ATTACH_PID 2>/dev/null; then echo " ✓ Attach completed (expected for non-interactive)" else echo " ✓ Attach still running" kill $ATTACH_PID 2>/dev/null || true fi # Check if spike is still running after parallel attach if ! kill -0 $SPIKE_PID 2>/dev/null; then echo " ERROR: Spike died during parallel attach!" tail -50 "$LOG_FILE" exit 1 fi echo " ✓ Control mode survived parallel attach" echo "" echo "[4/6] Triggering alternate-screen failure mode..." echo " Sending /settings command..." tmux send-keys -t "$SESSION" "/settings" Enter sleep 2 # Navigate in settings (arrow keys) echo " Navigating in settings menu..." tmux send-keys -t "$SESSION" Down Down Up sleep 1 # Exit settings (Escape or q) echo " Exiting settings..." tmux send-keys -t "$SESSION" Escape sleep 2 echo " ✓ Alternate-screen sequence complete" echo "" # Check if spike is still receiving output echo "[5/6] Verifying stream still active after alternate-screen..." echo " Sending test prompt..." tmux send-keys -t "$SESSION" "echo 'STREAM_TEST_AFTER_SETTINGS_$(date +%s)'" Enter sleep 2 # Check recent output for our test string if tail -100 "$LOG_FILE" | grep -q "STREAM_TEST_AFTER_SETTINGS"; then echo " ✓ Stream still active! Control mode survived alternate-screen." else echo " WARNING: Test string not found in recent output." echo " This could mean a lag or the test was too fast." echo " Checking if spike is still running..." if kill -0 $SPIKE_PID 2>/dev/null; then echo " ✓ Spike process still alive" else echo " ERROR: Spike process died!" tail -50 "$LOG_FILE" exit 1 fi fi echo "" echo "[6/6] Running for full 5-minute duration..." START_TIME=$(date +%s) NEXT_REPORT=$((START_TIME + 60)) while true; do CURRENT_TIME=$(date +%s) ELAPSED=$((CURRENT_TIME - START_TIME)) if [ $ELAPSED -ge $DURATION ]; then break fi # Check if spike is still running if ! kill -0 $SPIKE_PID 2>/dev/null; then echo " ERROR: Spike died at ${ELAPSED}s!" tail -50 "$LOG_FILE" exit 1 fi # Report every minute if [ $CURRENT_TIME -ge $NEXT_REPORT ]; then REMAINING=$((DURATION - ELAPSED)) echo " Still running... ${ELAPSED}s elapsed, ${REMAINING}s remaining" NEXT_REPORT=$((NEXT_REPORT + 60)) # Send a keepalive message tmux send-keys -t "$SESSION" "echo 'keepalive_${ELAPSED}s'" Enter fi sleep 5 done echo " ✓ Completed 5-minute test" echo "" echo "=== Test Complete ===" echo "Stopping spike..." kill $SPIKE_PID 2>/dev/null || true wait $SPIKE_PID 2>/dev/null || true echo "" echo "=== Results ===" echo "Log file: $LOG_FILE" echo "" echo "Statistics from log:" grep "\[spike-cc\].*Stats" "$LOG_FILE" | tail -5 echo "" OUTPUT_EVENTS=$(grep -c "handleOutputEvent\|%output" "$LOG_FILE" || echo "0") echo "Total output events (approx): $OUTPUT_EVENTS" echo "" if [ $OUTPUT_EVENTS -gt 10 ]; then echo "✅ VERDICT: Control mode appears to work reliably" echo " - Survived alternate-screen transition" echo " - Parallel attach did not interfere" echo " - Ran for full 5-minute duration" else echo "⚠️ VERDICT: Insufficient output events captured" echo " This may indicate a problem with the spike implementation" fi echo "" echo "Full log saved to: $LOG_FILE" echo "To review: cat $LOG_FILE"