-
Notifications
You must be signed in to change notification settings - Fork 230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug 1938924 - Add support for search-config-overrides-v2 to the Rust… #6614
base: main
Are you sure you want to change the base?
Conversation
… based search engine selector.
ba28e3e
to
c5f227f
Compare
I updated the patch to fix the failing tests. I didn't notice them when I first push this up. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, this is a good start and looks like it will fix some more of the desktop tests 🎉
A few things to consider that I've added in-line.
@@ -92,16 +103,21 @@ impl SearchEngineSelector { | |||
if records.is_empty() { | |||
return Err(Error::SearchConfigNoRecords); | |||
} | |||
return filter_engine_configuration_impl(user_environment, &records); | |||
return filter_engine_configuration_impl(user_environment, &records, None); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should set this up such that if an application calls use_remote_settings_server
with apply_engine_overrides == true
, then we will create a remote settings client (in use_remote_settings_server
) and then use the client here.
It isn't much extra to do, and if we do enable this on android in future, then we won't need to do extra work for them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I'm understanding correctly, and I pass the search-config-overrides-v2
client to filter_engine_configuration_impl()
Then I have to convert the overrides record to strings and then deserialize them again to the records we can use, similar to the code below.
I want to clarify is this what you're suggesting or am I over complicating it and there's a simpler way?
fn filter_records(
&self,
user_environment: &SearchUserEnvironment,
_overrides: Option<Vec<JSONOverridesRecord>>,
) -> Result<FilterRecordsResult, Error> {
let mut engines = Vec::new();
let mut default_engines_record = None;
let mut engine_orders_record = None;
for record in self {
// TODO: Bug 1947241 - Find a way to avoid having to serialise the records
// back to strings and then deserilise them into the records that we want.
let stringified = serde_json::to_string(&record.fields)?;
match record.fields.get("recordType") {
Some(val) if *val == "engine" => {
let engine_config: Option<JSONEngineRecord> =
serde_json::from_str(&stringified)?;
if let Some(engine_config) = engine_config {
let result =
maybe_extract_engine_config(user_environment, Box::new(engine_config));
engines.extend(result);
}
}
Some(val) if *val == "defaultEngines" => {
default_engines_record = serde_json::from_str(&stringified)?;
}
Some(val) if *val == "engineOrders" => {
engine_orders_record = serde_json::from_str(&stringified)?;
}
// These cases are acceptable - we expect the potential for new
// record types/options so that we can be flexible.
Some(_val) => {}
None => {}
}
}
Ok(FilterRecordsResult {
engines,
default_engines_record,
engine_orders_record,
})
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At the moment we'll have to do it the convert to string & then back to the records in a similar way. At some point we'll make that easier for ourselves.
@@ -270,6 +286,26 @@ mod tests { | |||
fn test_filter_engine_configuration_returns_basic_engines() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't add this above here, but please can we add a test similar to test_filter_engine_configuration_throws_without_config
but for the overrides.
@@ -94,6 +95,17 @@ impl SearchEngineDefinition { | |||
} | |||
} | |||
|
|||
fn merge_override(&mut self, override_record: &JSONOverridesRecord) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be nice to add a unit test for this - something fairly simple that checks we merge the parameters correctly (and don't change the telemetry suffix if none is supplied).
… based search engine selector.
Pull Request checklist
[ci full]
to the PR title.Branch builds: add
[firefox-android: branch-name]
to the PR title.