test(android): add auto-reset for TEST 1 and create golden run documentation

Add automatic app state reset for TEST 1 to ensure clean starting state when
lingering alarms from TEST 0 are detected. Create PHASE1_TEST1_GOLDEN.md with
actual values from successful run.

TEST 1 Auto-Reset:
- Detect lingering plugin alarms before TEST 1 starts
- Automatically uninstall/reinstall app to clear alarms
- Verify clean state (0 alarms) before proceeding
- Gracefully skip TEST 1 if clean state cannot be achieved
- Take failure screenshots when reset fails
- Wrap all TEST 1 steps in conditional to skip on reset failure

Documentation:
- Create PHASE1_TEST1_GOLDEN.md with actual values from passing run
- Document auto-reset behavior in golden run steps
- Add cross-references between TEST 0 and TEST 1 golden docs
- Include actual timestamps, scheduleIds, and recovery metrics

This ensures TEST 1 always starts from a known clean state, making test
results reliable and reproducible. The golden doc serves as a baseline for
comparing future TEST 1 runs.
This commit is contained in:
Matthew Raymer
2025-12-04 10:22:35 +00:00
parent 1103513db3
commit ca194952e4
3 changed files with 410 additions and 6 deletions

View File

@@ -434,16 +434,87 @@ main() {
print_step "1" "Clean start - checking for lingering alarms..."
LINGERING_COUNT=$(get_plugin_alarm_count)
SYSTEM_COUNT=$(get_system_alarm_count)
print_info "Current plugin notification alarms: ${LINGERING_COUNT}"
print_info "System/other alarms: ${SYSTEM_COUNT} (for context)"
if [ "${LINGERING_COUNT}" -gt "0" ] 2>/dev/null; then
print_warn "Found ${LINGERING_COUNT} lingering plugin alarm(s) - these may interfere with test"
print_info "System/other alarms: ${SYSTEM_COUNT} (for context)"
print_info "Consider uninstalling/reinstalling app for clean state"
wait_for_user
print_warn "Found ${LINGERING_COUNT} lingering plugin alarm(s) - these will interfere with TEST 1."
print_info "TEST 1 needs a clean state (no existing plugin alarms)."
print_info "Resetting app state via uninstall + reinstall..."
# Uninstall existing app
print_info "Uninstalling existing app..."
set +e
uninstall_output="$($ADB_BIN uninstall "$APP_ID" 2>&1)"
uninstall_status=$?
set -e
if [ $uninstall_status -eq 0 ]; then
print_success "App uninstall succeeded (clean slate)."
else
if grep -q "DELETE_FAILED_INTERNAL_ERROR" <<<"$uninstall_output"; then
print_info "No existing app to uninstall (continuing)"
else
print_warn "App uninstall reported an error: $uninstall_output (continuing anyway)"
fi
fi
# Reinstall APK
print_info "Reinstalling APK..."
if $ADB_BIN install -r "$APK_PATH" >/dev/null 2>&1; then
print_success "App reinstall succeeded."
else
print_error "App reinstall FAILED - cannot proceed with TEST 1."
print_warn "Marking TEST 1 as INCONCLUSIVE due to dirty starting state."
take_failure_screenshot "phase1_test1_force_stop" "dirty_state_reinstall_failed"
wait_for_user
# Skip to end of TEST 1 block
goto_test1_end=true
fi
if [ "${goto_test1_end:-false}" != "true" ]; then
# Verify install
if ! $ADB_BIN shell pm list packages | grep -q "$APP_ID"; then
print_error "App not found in package list after reinstall - aborting TEST 1."
take_failure_screenshot "phase1_test1_force_stop" "dirty_state_verify_failed"
wait_for_user
goto_test1_end=true
fi
fi
if [ "${goto_test1_end:-false}" != "true" ]; then
# Clear logs
print_info "Clearing logcat buffer after reinstall..."
$ADB_BIN logcat -c || true
# Re-check plugin alarms
print_info "Rechecking plugin alarms after reset..."
sleep 2 # Give system time to clear alarms
LINGERING_COUNT=$(get_plugin_alarm_count)
print_info "Plugin alarms after reset: ${LINGERING_COUNT} (expected: 0)"
if [ "${LINGERING_COUNT}" -ne "0" ] 2>/dev/null; then
print_warn "TEST 1 starting with non-zero alarm count even after reset; treating as INCONCLUSIVE."
print_info "This may indicate device-specific behavior where alarms persist across uninstall."
take_failure_screenshot "phase1_test1_force_stop" "unexpected_alarms_after_reset"
wait_for_user
goto_test1_end=true
fi
fi
if [ "${goto_test1_end:-false}" = "true" ]; then
print_warn "TEST 1 skipped due to inability to achieve clean starting state."
wait_for_user
else
print_success "App state reset complete. TEST 1 starting from clean state."
fi
else
print_success "No lingering plugin alarms found (clean state)"
print_info "System/other alarms: ${SYSTEM_COUNT} (for context)"
fi
# Skip remaining TEST 1 steps if we couldn't achieve clean state
if [ "${goto_test1_end:-false}" != "true" ]; then
# ============================================
# Step 2: Schedule a known future alarm
# ============================================
@@ -664,8 +735,10 @@ main() {
print_info "Skipping fire verification (VERIFY_FIRE=false, set VERIFY_FIRE=true to enable)"
fi
fi # End of "if goto_test1_end != true" block (wraps all TEST 1 steps after clean state check)
wait_for_user
fi
fi # End of "if should_run_test 1" block
# ============================================
# TEST 2: Schedule Update (One-Per-Day Semantics)