Skip to content

Commit 72a0707

Browse files
committed
Remote settings: update app-context correctly
As I was trying to use this in desktop, I noticed that updating the app config didn't actually change the JEXL filter.
1 parent 2cf20a7 commit 72a0707

File tree

3 files changed

+89
-4
lines changed

3 files changed

+89
-4
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
#### BREAKING CHANGE
99
- Removed `Megazord.kt` and moved the contents to the new `RustComponentsInitializer.kt`.
1010

11+
## 🔧 What's Fixed 🔧
12+
13+
### Remote Settings
14+
15+
- Fixed setting a new app context with `RemoteSettingsService::update_config`
16+
1117
[Full Changelog](In progress)
1218

1319
# v139.0 (_2025-04-28_)

components/remote_settings/src/client.rs

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,9 +507,15 @@ impl RemoteSettingsClient<ViaductApiClient> {
507507
Self::new_from_parts(collection_name, storage, jexl_filter, api_client)
508508
}
509509

510-
pub fn update_config(&self, server_url: BaseUrl, bucket_name: String) -> Result<()> {
510+
pub fn update_config(
511+
&self,
512+
server_url: BaseUrl,
513+
bucket_name: String,
514+
context: Option<RemoteSettingsContext>,
515+
) -> Result<()> {
511516
let mut inner = self.inner.lock();
512517
inner.api_client = ViaductApiClient::new(server_url, &bucket_name, &self.collection_name);
518+
inner.jexl_filter = JexlFilter::new(context);
513519
inner.storage.empty()
514520
}
515521
}
@@ -2040,6 +2046,76 @@ mod jexl_tests {
20402046
Some(vec![])
20412047
);
20422048
}
2049+
2050+
#[test]
2051+
fn test_update_jexl_context() {
2052+
let mut api_client = MockApiClient::new();
2053+
let records = vec![RemoteSettingsRecord {
2054+
id: "record-0001".into(),
2055+
last_modified: 100,
2056+
deleted: false,
2057+
attachment: None,
2058+
fields: serde_json::json!({
2059+
"filter_expression": "env.country == \"US\""
2060+
})
2061+
.as_object()
2062+
.unwrap()
2063+
.clone(),
2064+
}];
2065+
let changeset = ChangesetResponse {
2066+
changes: records.clone(),
2067+
timestamp: 42,
2068+
metadata: CollectionMetadata::default(),
2069+
};
2070+
api_client.expect_collection_url().returning(|| {
2071+
"http://rs.example.com/v1/buckets/main/collections/test-collection".into()
2072+
});
2073+
api_client.expect_fetch_changeset().returning({
2074+
let changeset = changeset.clone();
2075+
move |timestamp| {
2076+
assert_eq!(timestamp, None);
2077+
Ok(changeset.clone())
2078+
}
2079+
});
2080+
api_client.expect_is_prod_server().returning(|| Ok(false));
2081+
2082+
let context = RemoteSettingsContext {
2083+
country: Some("US".to_string()),
2084+
..Default::default()
2085+
};
2086+
2087+
let mut storage = Storage::new(":memory:".into());
2088+
let _ = storage.insert_collection_content(
2089+
"http://rs.example.com/v1/buckets/main/collections/test-collection",
2090+
&records,
2091+
42,
2092+
CollectionMetadata::default(),
2093+
);
2094+
2095+
let rs_client = RemoteSettingsClient::new_from_parts(
2096+
"test-collection".into(),
2097+
storage,
2098+
JexlFilter::new(Some(context)),
2099+
api_client,
2100+
);
2101+
2102+
assert_eq!(
2103+
rs_client.get_records(false).expect("Error getting records"),
2104+
Some(records)
2105+
);
2106+
2107+
// We can't call `update_config` directly, since that only works with a real API client.
2108+
// Instead, just execute the code from that method that updates the JEXL filter.
2109+
rs_client.inner.lock().jexl_filter = JexlFilter::new(Some(RemoteSettingsContext {
2110+
country: Some("UK".to_string()),
2111+
..Default::default()
2112+
}));
2113+
2114+
assert_eq!(
2115+
rs_client.get_records(false).expect("Error getting records"),
2116+
Some(vec![])
2117+
);
2118+
}
20432119
}
20442120

20452121
#[cfg(feature = "signatures")]

components/remote_settings/src/service.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,15 @@ impl RemoteSettingsService {
105105
let bucket_name = config.bucket_name.unwrap_or_else(|| String::from("main"));
106106
let mut inner = self.inner.lock();
107107
for client in inner.active_clients() {
108-
client
109-
.internal
110-
.update_config(base_url.clone(), bucket_name.clone())?;
108+
client.internal.update_config(
109+
base_url.clone(),
110+
bucket_name.clone(),
111+
config.app_context.clone(),
112+
)?;
111113
}
112114
inner.base_url = base_url;
113115
inner.bucket_name = bucket_name;
116+
inner.app_context = config.app_context;
114117
Ok(())
115118
}
116119
}

0 commit comments

Comments
 (0)