Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mandysGit
Copy link
Contributor

… based search engine selector.

Pull Request checklist

  • Breaking changes: This PR follows our breaking change policy
    • This PR follows the breaking change policy:
      • This PR has no breaking API changes, or
      • There are corresponding PRs for our consumer applications that resolve the breaking changes and have been approved
  • Quality: This PR builds and tests run cleanly
    • Note:
      • For changes that need extra cross-platform testing, consider adding [ci full] to the PR title.
      • If this pull request includes a breaking change, consider cutting a new release after merging.
  • Tests: This PR includes thorough tests or an explanation of why it does not
  • Changelog: This PR includes a changelog entry in CHANGELOG.md or an explanation of why it does not need one
    • Any breaking changes to Swift or Kotlin binding APIs are noted explicitly
  • Dependencies: This PR follows our dependency management guidelines
    • Any new dependencies are accompanied by a summary of the due diligence applied in selecting them.

Branch builds: add [firefox-android: branch-name] to the PR title.

@mandysGit mandysGit requested a review from Standard8 February 26, 2025 01:57
@mandysGit mandysGit force-pushed the search-config-overrides-v2 branch from ba28e3e to c5f227f Compare February 27, 2025 02:31
@mandysGit
Copy link
Contributor Author

I updated the patch to fix the failing tests. I didn't notice them when I first push this up.

Copy link
Member

@Standard8 Standard8 left a 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);
Copy link
Member

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.

Copy link
Contributor Author

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,
        })
    }

Copy link
Member

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() {
Copy link
Member

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) {
Copy link
Member

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants