@@ -48,8 +48,8 @@ emergency_cleanup() {
4848 xcrun simctl shutdown " $SIMULATOR_UUID_TO_CLEAN " 2> /dev/null || true
4949 fi
5050
51- # Clean up any background processes
52- jobs -p | xargs -r kill 2> /dev/null || true
51+ # Clean up push monitor specifically (don't kill all background jobs)
52+ cleanup_push_monitoring
5353
5454 echo_warning " Emergency cleanup completed. Exiting with code $exit_code "
5555 exit $exit_code
@@ -349,14 +349,14 @@ prepare_test_environment() {
349349 if [[ -n " $CI " ]] || [[ -n " $GITHUB_ACTIONS " ]] || [[ -n " $JENKINS_URL " ]] || [[ -n " $BUILDKITE " ]]; then
350350 export CI=" 1"
351351 echo_info " 🤖 CI Environment detected - enabling mock push notifications"
352- # Update config.json with CI mode only when CI is detected
353- update_config_for_ci
354352 else
355353 export CI=" 0"
356354 echo_info " 📱 Local Environment - using real APNS push notifications"
357- # Don't override existing config for local runs
358355 fi
359356
357+ # Always update config.json to match detected environment
358+ update_config_for_ci
359+
360360 if [[ " $VERBOSE " == true ]]; then
361361 export ENABLE_DEBUG_LOGGING=" 1"
362362 fi
@@ -469,17 +469,7 @@ clear_screenshots_directory() {
469469# MARK: - Push Notification Support
470470
471471setup_push_monitoring () {
472- # Check both CI env var and config.json ciMode setting
473- local CI_MODE=" $CI "
474- if [[ -f " $LOCAL_CONFIG_FILE " ]] && command -v jq & > /dev/null; then
475- local CONFIG_CI_MODE=$( jq -r ' .testing.ciMode // false' " $LOCAL_CONFIG_FILE " )
476- if [[ " $CONFIG_CI_MODE " == " true" ]]; then
477- CI_MODE=" 1"
478- echo_info " 🔍 CI mode detected from config.json (ciMode: true)"
479- fi
480- fi
481-
482- if [[ " $CI_MODE " == " 1" ]]; then
472+ if [[ " $CI " == " 1" ]]; then
483473 echo_info " 🤖 Setting up push notification monitoring for CI environment"
484474
485475 # Create push queue directory
@@ -499,14 +489,29 @@ setup_push_monitoring() {
499489 echo " $MONITOR_PID " > " /tmp/push_monitor.pid"
500490
501491 # Give it a moment to start
502- sleep 0.5
492+ sleep 1
503493
504494 # Verify it's running
505495 if ps -p " $MONITOR_PID " > /dev/null 2>&1 ; then
506496 echo_info " ⚡ Push monitor started with PID: $MONITOR_PID "
497+
498+ # Verify it's actually watching the directory
499+ sleep 0.5
500+ if [[ -f " $PUSH_MONITOR_LOG " ]]; then
501+ if grep -q " Push monitor started" " $PUSH_MONITOR_LOG " 2> /dev/null; then
502+ echo_info " ✓ Push monitor is actively watching for commands"
503+ else
504+ echo_warning " ⚠️ Push monitor log exists but may not be working correctly"
505+ cat " $PUSH_MONITOR_LOG "
506+ fi
507+ fi
507508 else
508509 echo_error " ❌ Push monitor failed to start!"
509- cat " $PUSH_MONITOR_LOG "
510+ if [[ -f " $PUSH_MONITOR_LOG " ]]; then
511+ echo_error " Push monitor log:"
512+ cat " $PUSH_MONITOR_LOG "
513+ fi
514+ echo_error " Push monitoring will not work!"
510515 fi
511516 else
512517 echo_info " 📱 Local environment - push monitoring not needed"
@@ -517,35 +522,46 @@ start_push_monitor() {
517522 local PUSH_QUEUE_DIR=" $1 "
518523
519524 # Use plain echo since this runs in background process
520- echo " [$( date ' +%Y-%m-%d %H:%M:%S' ) ] 🔄 Push monitor started - watching: $PUSH_QUEUE_DIR "
525+ echo " [$( date ' +%Y-%m-%d %H:%M:%S' ) ] 🔄 Push monitor started - watching: $PUSH_QUEUE_DIR " >&2
526+ echo " [$( date ' +%Y-%m-%d %H:%M:%S' ) ] 🔄 Monitor PID: $$ " >&2
527+
528+ # Verify directory exists and is writable
529+ if [[ ! -d " $PUSH_QUEUE_DIR " ]]; then
530+ echo " [$( date ' +%Y-%m-%d %H:%M:%S' ) ] ❌ ERROR: Push queue directory does not exist: $PUSH_QUEUE_DIR " >&2
531+ exit 1
532+ fi
533+
534+ echo " [$( date ' +%Y-%m-%d %H:%M:%S' ) ] ✓ Directory verified: $PUSH_QUEUE_DIR " >&2
521535
522536 while true ; do
523537 # Look for new command files
524538 for COMMAND_FILE in " $PUSH_QUEUE_DIR " /command_* .txt; do
539+ # Skip if no files match the pattern
540+ [[ -e " $COMMAND_FILE " ]] || continue
525541 [[ -f " $COMMAND_FILE " ]] || continue
526542
527- echo " [$( date ' +%Y-%m-%d %H:%M:%S' ) ] 📋 Found command file: $COMMAND_FILE "
543+ echo " [$( date ' +%Y-%m-%d %H:%M:%S' ) ] 📋 Found command file: $COMMAND_FILE " >&2
528544
529545 # Read and execute the command
530546 local COMMAND=$( cat " $COMMAND_FILE " 2> /dev/null)
531547 if [[ -n " $COMMAND " ]]; then
532- echo " [$( date ' +%Y-%m-%d %H:%M:%S' ) ] 🚀 Executing push command: $COMMAND "
548+ echo " [$( date ' +%Y-%m-%d %H:%M:%S' ) ] 🚀 Executing push command: $COMMAND " >&2
533549
534550 # Execute the xcrun simctl command
535551 eval " $COMMAND " 2>&1
536552 local EXIT_CODE=$?
537553
538554 if [[ $EXIT_CODE -eq 0 ]]; then
539- echo " [$( date ' +%Y-%m-%d %H:%M:%S' ) ] ✅ Push notification sent successfully"
555+ echo " [$( date ' +%Y-%m-%d %H:%M:%S' ) ] ✅ Push notification sent successfully" >&2
540556 else
541- echo " [$( date ' +%Y-%m-%d %H:%M:%S' ) ] ❌ Push notification failed with exit code: $EXIT_CODE "
557+ echo " [$( date ' +%Y-%m-%d %H:%M:%S' ) ] ❌ Push notification failed with exit code: $EXIT_CODE " >&2
542558 fi
543559
544560 # Remove the command file after processing
545561 rm -f " $COMMAND_FILE "
546- echo " [$( date ' +%Y-%m-%d %H:%M:%S' ) ] 🗑️ Cleaned up command file: $COMMAND_FILE "
562+ echo " [$( date ' +%Y-%m-%d %H:%M:%S' ) ] 🗑️ Cleaned up command file: $COMMAND_FILE " >&2
547563 else
548- echo " [$( date ' +%Y-%m-%d %H:%M:%S' ) ] ⚠️ Empty command file: $COMMAND_FILE "
564+ echo " [$( date ' +%Y-%m-%d %H:%M:%S' ) ] ⚠️ Empty command file: $COMMAND_FILE " >&2
549565 rm -f " $COMMAND_FILE "
550566 fi
551567 done
0 commit comments