Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

- Added `blocks: Vec<String>` to `ffi::MozAdsRequestOptions`, `AdsClient::request*_ads`, `MARSClient::fetch_ads`, `mars::AdRequest`, and `mars::AdRequest::try_new`. This is serialized and passed to MARS so that it can remove blocks server-side.

### Remote Settings

- Added an optional `distribution` field to `RemoteSettingsContext`, exposed as `env.distribution` in JEXL `filter_expression`s so records can be targeted at specific distributions (e.g. partner repacks). ([Bug 2068685](https://bugzilla.mozilla.org/show_bug.cgi?id=2068685))

# v156.0 (_2026-08-27_)

## ✨ What's Changed ✨
Expand Down
68 changes: 68 additions & 0 deletions components/remote_settings/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1187,6 +1187,74 @@ mod jexl_tests {
);
}

#[test]
fn test_jexl_filter_by_distribution() {
let mut api_client = MockApiClient::new();
let records = vec![RemoteSettingsRecord {
id: "record-0001".into(),
last_modified: 100,
deleted: false,
attachment: None,
fields: serde_json::json!({
"filter_expression": "env.distribution == \"firefox-001\""
})
.as_object()
.unwrap()
.clone(),
}];
let changeset = ChangesetResponse {
changes: records.clone(),
timestamp: 42,
metadata: CollectionMetadata::default(),
};
api_client.expect_collection_url().returning(|| {
"http://rs.example.com/v2/buckets/main/collections/test-collection".into()
});
api_client.expect_fetch_changeset().returning({
let changeset = changeset.clone();
move |timestamp| {
assert_eq!(timestamp, None);
Ok(changeset.clone())
}
});
api_client.expect_is_prod_server().returning(|| Ok(false));

let context = RemoteSettingsContext {
distribution: Some("firefox-001".to_string()),
..Default::default()
};

let mut storage = Storage::new(":memory:".into());
let _ = storage.insert_collection_content(
"http://rs.example.com/v2/buckets/main/collections/test-collection",
&records,
42,
CollectionMetadata::default(),
);

let rs_client = RemoteSettingsClient::new_from_parts(
"test-collection".into(),
storage,
JexlFilter::new(Some(context)),
api_client,
);

assert_eq!(
rs_client.get_records(false).expect("Error getting records"),
Some(records)
);

rs_client.inner.lock().jexl_filter = JexlFilter::new(Some(RemoteSettingsContext {
distribution: Some("default".to_string()),
..Default::default()
}));

assert_eq!(
rs_client.get_records(false).expect("Error getting records"),
Some(vec![])
);
}

// Test that we can't hit the deadlock described in
// https://bugzilla.mozilla.org/show_bug.cgi?id=2012955
#[test]
Expand Down
7 changes: 7 additions & 0 deletions components/remote_settings/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ pub struct RemoteSettingsContext {
/// for example `Region` on Desktop and `RegionMiddleware` on Android.
#[uniffi(default = None)]
pub country: Option<String>,
#[uniffi(default = None)]
pub distribution: Option<String>,
/// Extra attributes to add to the env for JEXL filtering.
///
/// Use this for prototyping / testing new features. In the long-term, new fields should be
Expand Down Expand Up @@ -94,6 +96,9 @@ impl RemoteSettingsContext {
if let Some(country) = self.country {
v.insert("country".to_string(), country.into());
}
if let Some(distribution) = self.distribution {
v.insert("distribution".to_string(), distribution.into());
}
if let Some(custom) = self.custom_targetting_attributes {
v.extend(custom.into_iter().map(|(k, v)| (k, v.into())));
}
Expand All @@ -120,6 +125,7 @@ mod test {
locale: Some("en-US".into()),
form_factor: Some("tablet".into()),
country: Some("US".into()),
distribution: Some("firefox-001".into()),
custom_targetting_attributes: Some(HashMap::from([("extra".into(), "test".into())])),
};
assert_eq!(
Expand All @@ -141,6 +147,7 @@ mod test {
// into official fields that both the Gecko and Rust client support.
"formFactor": "tablet",
"country": "US",
"distribution": "firefox-001",
"extra": "test",
})
);
Expand Down