From aa4c66cdfabea17210abe0a04a7b0ecff9723edf Mon Sep 17 00:00:00 2001 From: Beth Rennie Date: Sat, 6 Jun 2026 14:18:57 -0400 Subject: [PATCH] Bug 2045161 - Do not opt-out of unenrolled enrollments --- CHANGELOG.md | 1 + components/nimbus/src/enrollment.rs | 9 ++------- components/nimbus/src/tests/test_enrollment.rs | 16 ++++------------ 3 files changed, 7 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 60d90a35c7..8c3fa41722 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Enrollment change events (visible to the UDL) now include the feature IDs of the features involved when possible. ([#7391](https://github.com/mozilla/application-services/pull/7391/)) - Fixed a bug where enrollment change events were not emitted for rollouts that re-enrolled after previously unenrolling. ([#7391](https://github.com/mozilla/application-services/pull/7391/)) +- Attempting to opt-out from an experiment that is not currently enrolled is now a no-op. ([#7399](https://github.com/mozilla/application-services/pull/7399)) [Full Changelog](In progress) diff --git a/components/nimbus/src/enrollment.rs b/components/nimbus/src/enrollment.rs index 32eca71a5c..1f1f2791ba 100644 --- a/components/nimbus/src/enrollment.rs +++ b/components/nimbus/src/enrollment.rs @@ -484,13 +484,8 @@ impl ExperimentEnrollment { out_enrollment_events.push(enrollment.get_change_event(experiment)); enrollment } - EnrollmentStatus::NotEnrolled { .. } => Self { - slug: self.slug.to_string(), - status: EnrollmentStatus::NotEnrolled { - reason: NotEnrolledReason::OptOut, // Explicitly set the reason to OptOut. - }, - }, - EnrollmentStatus::Disqualified { .. } + EnrollmentStatus::NotEnrolled { .. } + | EnrollmentStatus::Disqualified { .. } | EnrollmentStatus::WasEnrolled { .. } | EnrollmentStatus::Error { .. } => { // Nothing to do here. diff --git a/components/nimbus/src/tests/test_enrollment.rs b/components/nimbus/src/tests/test_enrollment.rs index b787c92b8a..88720ed5e8 100644 --- a/components/nimbus/src/tests/test_enrollment.rs +++ b/components/nimbus/src/tests/test_enrollment.rs @@ -3749,11 +3749,9 @@ fn test_enrollment_enrolled_explicit_opt_out() { #[cfg(feature = "stateful")] None, ); - if let EnrollmentStatus::Disqualified { branch, .. } = enrollment.status { - assert_eq!(branch, "control"); - } else { - panic!("Wrong variant!"); - } + assert!( + matches!(enrollment.status, EnrollmentStatus::Disqualified { branch, .. } if branch == "control") + ); assert_eq!( &events, &[EnrollmentChangeEvent { @@ -3782,13 +3780,7 @@ fn test_enrollment_not_enrolled_explicit_opt_out() { #[cfg(feature = "stateful")] None, ); - assert!(matches!( - enrollment.status, - EnrollmentStatus::NotEnrolled { - reason: NotEnrolledReason::OptOut, - .. - } - )); + assert_eq!(enrollment, existing_enrollment); assert_eq!(&events, &[]); }