Monorepo for Aesthetic.Computer aesthetic.computer
at main 292 lines 7.7 kB view raw
1#!/usr/bin/env fish 2# Emacs Tab Unit Testing Script 3# Tests individual tabs to find which one causes freezes 4 5set -g LOG_DIR /workspaces/aesthetic-computer/.emacs-logs 6set -g TEST_LOG $LOG_DIR/tab-test.log 7 8function log 9 set msg "[$(date '+%Y-%m-%d %H:%M:%S')] $argv" 10 echo $msg 11 echo $msg >> $TEST_LOG 12end 13 14function check_daemon_responsive 15 timeout 3 emacsclient -e '(+ 1 1)' >/dev/null 2>&1 16 return $status 17end 18 19function get_daemon_cpu 20 ps aux | grep "emacs.*daemon" | grep -v grep | awk '{print $3}' | head -1 21end 22 23function start_fresh_daemon 24 log "🔄 Starting fresh emacs daemon..." 25 pkill -9 emacs 2>/dev/null 26 pkill -9 emacsclient 2>/dev/null 27 sleep 1 28 29 emacs -q --daemon -l /workspaces/aesthetic-computer/dotfiles/dot_config/emacs.el >/dev/null 2>&1 & 30 disown 31 32 # Wait for daemon to be ready 33 for i in (seq 1 10) 34 if check_daemon_responsive 35 log "✅ Daemon ready after $i seconds" 36 return 0 37 end 38 sleep 1 39 end 40 41 log "❌ Daemon failed to start" 42 return 1 43end 44 45function create_minimal_backend 46 log "Creating minimal backend (artery + fishy only)..." 47 emacsclient -e '(aesthetic-backend-minimal)' >/dev/null 2>&1 48 sleep 3 49end 50 51function add_single_tab 52 set tab_name $argv[1] 53 set -e argv[1] 54 set commands $argv 55 56 log "➕ Adding tab: $tab_name with commands: $commands" 57 58 # Start profiler before creating tab 59 emacsclient -e '(ac-profile-start)' >/dev/null 2>&1 60 61 # Create the tab 62 set cmd_list (string join " " (for c in $commands; echo "\"$c\""; end)) 63 emacsclient -e "(ac--create-split-tab \"$tab_name\" '($cmd_list))" >/dev/null 2>&1 64 65 return $status 66end 67 68function monitor_stability 69 set duration $argv[1] 70 set check_interval 5 71 set checks (math "$duration / $check_interval") 72 73 log "📊 Monitoring stability for $duration seconds..." 74 75 for i in (seq 1 $checks) 76 sleep $check_interval 77 78 set cpu (get_daemon_cpu) 79 set responsive "?" 80 81 if check_daemon_responsive 82 set responsive "✓" 83 else 84 set responsive "✗" 85 log "❌ FROZEN at check $i (CPU: $cpu%)" 86 87 # Stop profiler and get report 88 emacsclient -e '(ac-profile-stop)' 2>/dev/null 89 return 1 90 end 91 92 log " Check $i/$checks: CPU=$cpu% responsive=$responsive" 93 end 94 95 # Stop profiler 96 emacsclient -e '(ac-profile-stop)' >/dev/null 2>&1 97 98 log "✅ Stable for $duration seconds" 99 return 0 100end 101 102function run_diagnostics 103 log "🔍 Running diagnostics..." 104 emacsclient -e '(ac-diagnose-all)' >/dev/null 2>&1 105end 106 107function test_single_tab 108 set tab_name $argv[1] 109 set -e argv[1] 110 set commands $argv 111 112 echo "" 113 log "==========================================" 114 log "TESTING TAB: $tab_name" 115 log "Commands: $commands" 116 log "==========================================" 117 118 # Start fresh 119 if not start_fresh_daemon 120 log "❌ TEST FAILED: Could not start daemon" 121 return 1 122 end 123 124 # Create minimal backend first 125 create_minimal_backend 126 127 # Check baseline stability 128 log "Checking baseline (artery + fishy only)..." 129 if not monitor_stability 15 130 log "❌ TEST FAILED: Baseline unstable" 131 return 1 132 end 133 134 # Add the test tab 135 if not add_single_tab $tab_name $commands 136 log "❌ TEST FAILED: Could not create tab" 137 return 1 138 end 139 140 # Monitor after adding tab 141 log "Monitoring after adding $tab_name..." 142 if not monitor_stability 30 143 log "❌ TEST FAILED: Tab $tab_name caused instability" 144 run_diagnostics 145 return 1 146 end 147 148 run_diagnostics 149 log "✅ TEST PASSED: Tab $tab_name is stable" 150 return 0 151end 152 153function test_all_tabs_sequential 154 echo "" 155 log "==========================================" 156 log "SEQUENTIAL TAB TEST - Adding tabs one by one" 157 log "==========================================" 158 159 # Start fresh 160 if not start_fresh_daemon 161 log "❌ Could not start daemon" 162 return 1 163 end 164 165 # Create minimal backend 166 create_minimal_backend 167 168 # Check baseline 169 log "Checking baseline..." 170 if not monitor_stability 15 171 log "❌ Baseline unstable" 172 return 1 173 end 174 175 # Define tabs to test 176 set tabs \ 177 "status:url:tunnel" \ 178 "stripe:stripe-print:stripe-ticket" \ 179 "chat:chat-system:chat-sotce:chat-clock" \ 180 "web 1/2:site:session" \ 181 "web 2/2:redis:bookmarks:oven:media" \ 182 "tests:kidlisp" 183 184 for tab_spec in $tabs 185 set parts (string split ":" $tab_spec) 186 set tab_name $parts[1] 187 set -e parts[1] 188 set commands $parts 189 190 log "" 191 log "--- Adding: $tab_name ---" 192 193 if not add_single_tab $tab_name $commands 194 log "❌ Failed to create tab $tab_name" 195 return 1 196 end 197 198 # Wait for tab to settle 199 sleep 5 200 201 # Check stability 202 if not monitor_stability 20 203 log "❌ FOUND PROBLEM: Tab $tab_name caused instability" 204 run_diagnostics 205 return 1 206 end 207 208 log "✓ Tab $tab_name stable" 209 end 210 211 log "" 212 log "==========================================" 213 log "✅ ALL TABS PASSED SEQUENTIAL TEST" 214 log "==========================================" 215 return 0 216end 217 218function test_rapid_creation 219 echo "" 220 log "==========================================" 221 log "RAPID CREATION TEST - All tabs at once" 222 log "==========================================" 223 224 # Start fresh 225 if not start_fresh_daemon 226 log "❌ Could not start daemon" 227 return 1 228 end 229 230 # Start profiler 231 emacsclient -e '(ac-profile-start)' >/dev/null 2>&1 232 233 # Run full aesthetic-backend 234 log "Starting full aesthetic-backend..." 235 emacsclient -e '(aesthetic-backend "artery")' >/dev/null 2>&1 236 237 # Monitor for 60 seconds 238 if not monitor_stability 60 239 log "❌ RAPID CREATION CAUSED INSTABILITY" 240 run_diagnostics 241 return 1 242 end 243 244 run_diagnostics 245 log "✅ RAPID CREATION TEST PASSED" 246 return 0 247end 248 249function show_help 250 echo "Emacs Tab Unit Testing" 251 echo "" 252 echo "Usage: test-emacs-tabs.fish <command>" 253 echo "" 254 echo "Commands:" 255 echo " single <tab> <cmds...> Test a single tab" 256 echo " sequential Test all tabs one by one" 257 echo " rapid Test rapid creation (all at once)" 258 echo " diagnose Run diagnostics on current daemon" 259 echo " profile-start Start CPU profiler" 260 echo " profile-stop Stop profiler and save report" 261 echo "" 262 echo "Examples:" 263 echo " test-emacs-tabs.fish single status url tunnel" 264 echo " test-emacs-tabs.fish sequential" 265 echo " test-emacs-tabs.fish rapid" 266end 267 268# Main 269switch $argv[1] 270 case single 271 set -e argv[1] 272 test_single_tab $argv 273 case sequential 274 test_all_tabs_sequential 275 case rapid 276 test_rapid_creation 277 case diagnose 278 emacsclient -e '(ac-diagnose-all)' 279 echo "Check $LOG_DIR/emacs-debug.log" 280 case profile-start 281 emacsclient -e '(ac-profile-start)' 282 echo "Profiler started" 283 case profile-stop 284 emacsclient -e '(ac-profile-stop)' 285 echo "Profiler stopped - check $LOG_DIR/emacs-profile.log" 286 case help --help -h '' 287 show_help 288 case '*' 289 echo "Unknown command: $argv[1]" 290 show_help 291 exit 1 292end