@@ -2,6 +2,7 @@ version: "0.5"
22
33environment :
44 - " EMU_HEADLESS=${EMU_HEADLESS:-}"
5+ - " SUITE_NAME=android-e2e"
56 - " TEST_TIMEOUT=300"
67 - " BOOT_TIMEOUT=90"
78 - " TEST_TUI=${TEST_TUI:-false}"
@@ -14,130 +15,62 @@ is_strict: true
1415processes :
1516 # Phase 1: Build - runs first (no dependency)
1617 build-app :
17- command : |
18- echo '[BUILD-APP] Starting build process (PID=$$)...'
19- # Source Android environment to set ANDROID_SDK_ROOT
20- . ${ANDROID_RUNTIME_DIR}/scripts/init/setup.sh
21- echo '📦 Building Android app...'
22- gradle assembleDebug --info
23- echo '✓ Build complete'
18+ command : " android.sh build"
2419 availability :
2520 restart : " no"
2621
2722 # Phase 2a: Sync AVDs - ensure all AVDs match device definitions
2823 sync-avds :
29- command : " echo '[SYNC-AVDS] Starting (PID=$$)...' && echo '[SYNC-AVDS] About to source setup.sh...' && . ${ANDROID_RUNTIME_DIR}/scripts/init/setup.sh && echo '[SYNC-AVDS] setup.sh sourced' && echo '🔄 Syncing AVDs with device definitions...' && android.sh devices sync && echo '✓ Sync complete' "
24+ command : " android.sh devices sync"
3025 availability :
3126 restart : " no"
3227
3328 # Phase 2b: Start emulator (depends on sync completing)
34- # Reuses existing emulator if already running
35- # Max boot time: 5 minutes, 1 retry allowed, total timeout: 10 minutes
3629 android-emulator :
3730 depends_on :
3831 sync-avds :
3932 condition : process_completed_successfully
4033 environment :
41- - " ANDROID_EMULATOR_FOREGROUND=1" # Run emulator in foreground for process-compose monitoring
34+ - " ANDROID_EMULATOR_FOREGROUND=1"
4235 command : |
43- echo "[ANDROID-EMULATOR] Starting emulator in foreground mode..."
44- # Source Android environment
45- . ${ANDROID_RUNTIME_DIR}/scripts/init/setup.sh
46-
47- # Determine which device to start
36+ echo "[ANDROID-EMULATOR] Starting emulator..."
4837 device="${ANDROID_DEFAULT_DEVICE:-max}"
4938
50- # In pure mode, always start fresh
51- if [ "${IN_NIX_SHELL:-}" = "pure" ]; then
52- echo "🚀 Starting fresh Android emulator (pure mode): $device"
53- export ANDROID_EMULATOR_PURE=1
54-
55- # Write expected serial for readiness probe (emulator always starts on 5554 first)
56- echo "emulator-5554" > ${ANDROID_RUNTIME_DIR}/emulator-serial.txt
57-
58- # Start emulator in foreground - this blocks and runs the emulator
59- # Process-compose will monitor it and use readiness probe to check when ready
39+ if [ "${IN_NIX_SHELL:-}" = "pure" ] || [ "${DEVBOX_PURE_SHELL:-}" = "1" ]; then
40+ echo "Starting fresh Android emulator (pure mode): $device"
6041 android.sh emulator start "$device"
6142 else
62- echo "🚀 Verifying Android emulator is running: $device"
63-
64- # Write expected serial for readiness probe
65- serial="emulator-5554"
66- echo "$serial" > ${ANDROID_RUNTIME_DIR}/emulator-serial.txt
67-
68- # Check if emulator is already running
69- if adb devices | grep -q "$serial"; then
70- echo "✓ Emulator already running: $serial"
71- else
72- echo "Starting emulator in background: $device"
73- # Start emulator in background (no foreground mode for reuse)
74- unset ANDROID_EMULATOR_FOREGROUND
75- android.sh emulator start "$device" &
76- echo "✓ Emulator starting (PID: $!)"
77- fi
78-
79- # Wait for emulator to be fully booted
80- echo "Waiting for emulator to boot..."
81- max_attempts=60
82- attempt=0
83- while [ $attempt -lt $max_attempts ]; do
84- if adb -s $serial shell getprop sys.boot_completed 2>/dev/null | grep -q "1"; then
85- echo "✓ Emulator ready for testing"
86- break
87- fi
88- attempt=$((attempt + 1))
89- sleep 2
90- done
91-
92- if [ $attempt -ge $max_attempts ]; then
93- echo "ERROR: Emulator did not boot within timeout"
94- exit 1
95- fi
43+ echo "Starting Android emulator: $device"
44+ # In non-pure mode, don't run foreground - start in background and wait
45+ unset ANDROID_EMULATOR_FOREGROUND
46+ android.sh emulator start "$device"
9647
97- # Let process complete - emulator stays running in background
98- echo "✓ Emulator will remain running after tests complete"
48+ echo "Emulator will remain running after tests complete"
9949 exit 0
10050 fi
10151 availability :
10252 restart : " no"
10353 readiness_probe :
10454 exec :
105- command : |
106- serial=$(cat ${ANDROID_RUNTIME_DIR}/emulator-serial.txt 2>/dev/null || echo "")
107- [ -n "$serial" ] && adb -s $serial shell getprop sys.boot_completed 2>/dev/null | grep -q "1"
55+ command : " android.sh emulator ready"
10856 initial_delay_seconds : 10
10957 period_seconds : 10
11058 timeout_seconds : 180
11159 success_threshold : 1
11260 failure_threshold : 12
11361
114- # Phase 3: Run app - depends on both build and emulator being ready
115- run -app :
62+ # Phase 3: Deploy app - depends on both build and emulator being ready
63+ deploy -app :
11664 command : |
117- # Source Android environment
118- . ${ANDROID_RUNTIME_DIR}/scripts/init/setup.sh
119-
120- serial=$(cat ${ANDROID_RUNTIME_DIR}/emulator-serial.txt 2>/dev/null || echo emulator-5554)
121- export ANDROID_EMULATOR_SERIAL="$serial"
122-
123- echo "📲 Running app on emulator: $serial"
124- # Use already-built APK from build-app phase
125- android.sh run ${ANDROID_APP_APK:-app/build/outputs/apk/debug/app-debug.apk}
65+ android.sh deploy
12666
12767 echo ""
128- # Resolve app ID: env var > auto-detected from APK > fail
129- app_id="${ANDROID_APP_ID:-$(cat ${ANDROID_RUNTIME_DIR}/app-id.txt 2>/dev/null || true)}"
130- if [ -z "$app_id" ]; then
131- echo "ERROR: Cannot determine app ID. Set ANDROID_APP_ID or run deploy first." >&2
132- exit 1
133- fi
134-
135- echo "Waiting for app to start ($app_id)..."
68+ echo "Waiting for app to start..."
13669 max_attempts=10
13770 attempt=0
13871 while [ $attempt -lt $max_attempts ]; do
139- if adb -s $serial shell pidof "$app_id" >/dev/null 2>&1 ; then
140- echo "✓ App process running (PID: $(adb -s $serial shell pidof "$app_id")) "
72+ if android.sh app status ; then
73+ echo "App is running"
14174 mkdir -p reports
14275 touch reports/.e2e-passed
14376 exit 0
@@ -148,10 +81,6 @@ processes:
14881 done
14982
15083 echo "ERROR: App did not start within timeout" >&2
151- echo "Installed packages:" >&2
152- adb -s $serial shell pm list packages | grep -i devbox || true
153- echo "Running processes:" >&2
154- adb -s $serial shell ps | grep -i devbox || true
15584 exit 1
15685 depends_on :
15786 build-app :
@@ -164,24 +93,16 @@ processes:
16493 # Cleanup - stop everything in pure mode, keep running in dev mode
16594 cleanup-app :
16695 command : |
167- # Source Android environment
168- . ${ANDROID_RUNTIME_DIR}/scripts/init/setup.sh
169-
170- serial=$(cat ${ANDROID_RUNTIME_DIR}/emulator-serial.txt 2>/dev/null || echo emulator-5554)
171-
172- # In pure mode (CI), stop app and emulator for reproducibility
173- if [ "${IN_NIX_SHELL:-}" = "pure" ]; then
174- echo "🧹 Cleaning up (pure mode): stopping app and emulator..."
175- app_id="${ANDROID_APP_ID:-$(cat ${ANDROID_RUNTIME_DIR}/app-id.txt 2>/dev/null || true)}"
176- [ -n "$app_id" ] && adb -s $serial shell am force-stop "$app_id" 2>/dev/null || true
96+ if [ "${IN_NIX_SHELL:-}" = "pure" ] || [ "${DEVBOX_PURE_SHELL:-}" = "1" ]; then
97+ echo "Cleaning up (pure mode)..."
98+ android.sh app stop || true
17799 android.sh emulator stop || true
178- echo "✓ App stopped, emulator stopped"
100+ echo "App stopped, emulator stopped"
179101 else
180- # In dev mode, keep app and emulator running for interaction
181- echo "✓ Test complete - app and emulator still running"
102+ echo "Test complete - app and emulator still running"
182103 fi
183104 depends_on :
184- run -app :
105+ deploy -app :
185106 condition : process_completed
186107 availability :
187108 restart : " no"
0 commit comments