fix(android): enforce one-per-day semantics in scheduleDailyNotification
Fix duplicate alarm bug where updating schedule time created multiple schedules in database, violating "one notification per day" contract. Plugin Changes: - Use stable scheduleId "daily_notification" instead of timestamp-based IDs - Delete all existing notification schedules before creating new one - Cancel alarms in AlarmManager before database deletion - Add detailed logging for cleanup operations - Make scheduleDailyReminder delegate to scheduleDailyNotification Test Harness Changes: - Make TEST 2 fail when alarm count > 1 after schedule update - Make TEST 2 fail when alarm count > 1 after recovery - Add clear failure messages explaining "one per day" violation - Add final verdict section with detailed failure summary Results: - Before: 2-3 alarms, 2 schedules in DB, "Pending: 2" in UI - After: 1 alarm, 1 schedule in DB, "Pending: 1" in UI - TEST 2 now correctly passes with proper validation This ensures that updating schedule time maintains exactly one alarm per day, preventing duplicate notifications and database bloat.
This commit is contained in:
@@ -794,11 +794,13 @@ main() {
|
||||
|
||||
if [ "${UPDATED_ALARM_COUNT}" -eq "1" ] 2>/dev/null; then
|
||||
print_success "✅ Single alarm confirmed after schedule update (one per day maintained)"
|
||||
elif [ "${UPDATED_ALARM_COUNT}" -gt "1" ] 2>/dev/null; then
|
||||
print_error "❌ TEST 2 FAILED: Found ${UPDATED_ALARM_COUNT} plugin alarms after update (expected: 1)"
|
||||
print_error " Old alarm was NOT canceled - violates 'one per day' semantics"
|
||||
print_info " This indicates the plugin did not clean up existing schedules before creating new one"
|
||||
TEST2_FAILED=true
|
||||
else
|
||||
print_warn "⚠️ Found ${UPDATED_ALARM_COUNT} plugin alarms (expected: 1)"
|
||||
if [ "${UPDATED_ALARM_COUNT}" -gt "1" ] 2>/dev/null; then
|
||||
print_warn "⚠️ Multiple alarms detected - old alarm may not have been canceled"
|
||||
fi
|
||||
print_warn "⚠️ Found ${UPDATED_ALARM_COUNT} plugin alarms (expected: 1) - no alarm scheduled after update"
|
||||
fi
|
||||
|
||||
print_step "3" "Killing app and relaunching (triggers recovery)..."
|
||||
@@ -827,33 +829,58 @@ main() {
|
||||
ALARM_COUNT_AFTER_RECOVERY=$(get_plugin_alarm_count)
|
||||
print_info "Plugin alarms after recovery: ${ALARM_COUNT_AFTER_RECOVERY} (expected: 1)"
|
||||
|
||||
# CRITICAL: Test fails if alarm count > 1 after recovery (violates "one per day")
|
||||
if [ "${ALARM_COUNT_AFTER_RECOVERY}" -gt "1" ] 2>/dev/null; then
|
||||
print_error "❌ TEST 2 FAILED: Found ${ALARM_COUNT_AFTER_RECOVERY} plugin alarms after recovery (expected: 1)"
|
||||
print_error " Multiple schedules in database caused recovery to reschedule duplicates"
|
||||
print_error " This violates 'one per day' semantics - only one notification per day should exist"
|
||||
TEST2_FAILED=true
|
||||
fi
|
||||
|
||||
if [ "${RESCHEDULED_COUNT}" -gt "0" ] 2>/dev/null; then
|
||||
print_success "✅ TEST 2 PASSED: Missing alarm was detected and rescheduled (rescheduled=${RESCHEDULED_COUNT})!"
|
||||
if [ "${ALARM_COUNT_AFTER_RECOVERY}" -eq "1" ] 2>/dev/null; then
|
||||
print_success "✅ TEST 2 PASSED: Missing alarm was detected and rescheduled (rescheduled=${RESCHEDULED_COUNT})!"
|
||||
print_success "✅ Single alarm confirmed after recovery (one per day maintained)"
|
||||
else
|
||||
print_warn "⚠️ Alarm count is ${ALARM_COUNT_AFTER_RECOVERY} (expected: 1)"
|
||||
elif [ "${TEST2_FAILED:-false}" != "true" ]; then
|
||||
print_warn "⚠️ Recovery rescheduled ${RESCHEDULED_COUNT} alarm(s), but alarm count is ${ALARM_COUNT_AFTER_RECOVERY} (expected: 1)"
|
||||
fi
|
||||
elif [ "${VERIFIED_COUNT}" -gt "0" ] 2>/dev/null; then
|
||||
print_success "✅ TEST 2 PASSED: Alarm verified in AlarmManager (verified=${VERIFIED_COUNT})!"
|
||||
if [ "${ALARM_COUNT_AFTER_RECOVERY}" -eq "1" ] 2>/dev/null; then
|
||||
print_success "✅ TEST 2 PASSED: Alarm verified in AlarmManager (verified=${VERIFIED_COUNT})!"
|
||||
print_success "✅ Single alarm confirmed after recovery (one per day maintained)"
|
||||
else
|
||||
print_warn "⚠️ Alarm count is ${ALARM_COUNT_AFTER_RECOVERY} (expected: 1)"
|
||||
elif [ "${TEST2_FAILED:-false}" != "true" ]; then
|
||||
print_warn "⚠️ Recovery verified ${VERIFIED_COUNT} alarm(s), but alarm count is ${ALARM_COUNT_AFTER_RECOVERY} (expected: 1)"
|
||||
fi
|
||||
elif [ "${RESCHEDULED_COUNT}" -eq "0" ] 2>/dev/null && [ "${VERIFIED_COUNT}" -eq "0" ] 2>/dev/null; then
|
||||
print_warn "⚠️ TEST 2: No verification/rescheduling needed (both verified=0 and rescheduled=0)"
|
||||
print_info "This might mean:"
|
||||
echo " - Alarm was already properly scheduled and didn't need recovery"
|
||||
echo " - Recovery didn't detect any issues"
|
||||
if [ "${ALARM_COUNT_AFTER_RECOVERY}" -eq "1" ] 2>/dev/null; then
|
||||
print_success "✅ Single alarm still present - recovery may have verified it silently"
|
||||
print_success "✅ TEST 2 PASSED: No recovery needed - alarm already properly scheduled"
|
||||
print_success "✅ Single alarm confirmed (one per day maintained)"
|
||||
else
|
||||
print_warn "⚠️ TEST 2: No verification/rescheduling needed (both verified=0 and rescheduled=0)"
|
||||
print_info "This might mean:"
|
||||
echo " - Alarm was already properly scheduled and didn't need recovery"
|
||||
echo " - Recovery didn't detect any issues"
|
||||
if [ "${ALARM_COUNT_AFTER_RECOVERY}" -eq "1" ] 2>/dev/null; then
|
||||
print_success "✅ Single alarm still present - recovery may have verified it silently"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
print_error "TEST 2 INCONCLUSIVE: Could not find recovery result"
|
||||
print_info "Recovery result: ${RECOVERY_RESULT}"
|
||||
fi
|
||||
|
||||
# Final verdict
|
||||
if [ "${TEST2_FAILED:-false}" = "true" ]; then
|
||||
print_error ""
|
||||
print_error "════════════════════════════════════════════════════════════"
|
||||
print_error "TEST 2 FINAL RESULT: ❌ FAILED"
|
||||
print_error "════════════════════════════════════════════════════════════"
|
||||
print_error "Reason: Multiple alarms detected - violates 'one per day' semantics"
|
||||
print_error "Expected: 1 alarm after update and after recovery"
|
||||
print_error "Actual: ${UPDATED_ALARM_COUNT} after update, ${ALARM_COUNT_AFTER_RECOVERY} after recovery"
|
||||
print_error "════════════════════════════════════════════════════════════"
|
||||
fi
|
||||
|
||||
print_step "5" "Verifying alarms are still scheduled in AlarmManager..."
|
||||
check_alarm_status
|
||||
|
||||
|
||||
Reference in New Issue
Block a user