Skip to content

fix(tests): Update filter expression script to use ExperimentAPI module. #12855

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

Merged
merged 5 commits into from
Jul 9, 2025

Conversation

b4handjr
Copy link
Contributor

@b4handjr b4handjr commented Jun 25, 2025

Because

  • Our targeting tests are failing due to a change in an upstream module we consume to creating targeting contexts.

This commit

  • Updates our script to use the newer ExperimenterAPI module.

Fixes #12851

@b4handjr b4handjr enabled auto-merge June 25, 2025 21:53
const TargetingContext = ChromeUtils.importESModule("resource://messaging-system/targeting/Targeting.sys.mjs");

const _experiment = JSON.parse(arguments[1]);
ExperimentAPI.ready();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This returns a promise

Suggested change
ExperimentAPI.ready();
await ExperimentAPI.ready();

@freshstrangemusic
Copy link
Member

There is a typo in the PR title: ExperimetAPI

@b4handjr b4handjr changed the title fix(tests): Update filter expression script to use ExperimetAPI module. fix(tests): Update filter expression script to use ExperimentAPI module. Jun 26, 2025
@b4handjr b4handjr added this pull request to the merge queue Jun 26, 2025
@b4handjr b4handjr removed this pull request from the merge queue due to a manual request Jun 26, 2025

return results;
remoteSettings(targetingString, recipe, callback);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of taking the callback as an arg, lets do remoteSettings(targetingString, recipe).then(callback, () => null)

It makes the control flow of remoteSettings cleaner and it doesnt need a bunch of try/catch.

const targetingContext = new TargetingContext.TargetingContext(context);
let result = false;
try {
result = await targetingContext.evalWithDefault(targetingString) !== undefined;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we dont take callback as an arg, we can just return immediately here. We dont even need to try/catch

} catch (err) {
result = null;
callback(null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here.

@b4handjr b4handjr force-pushed the fix-12851 branch 2 times, most recently from 4241515 to b9858e6 Compare June 26, 2025 21:50
Comment on lines 15 to 16
else:
return self.execute_script
return self.execute_async_script
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not understand how this is supposed to work

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use it in the test

with filter_expression_path.open() as js:
        result = Browser.execute_async_script(
            selenium,
            targeting,
            json.dumps({"experiment": recipe}),
            script=js.read(),
            context="chrome",
        )

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the example you gave, context="chrome" so we're in the other branch. From inspection, you would have to use this like:

result = Browser.execute_async_script()(script)

Comment on lines 15 to 16
else:
return self.execute_script
return self.execute_async_script
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the example you gave, context="chrome" so we're in the other branch. From inspection, you would have to use this like:

result = Browser.execute_async_script()(script)

Comment on lines 12 to 16
if "chrome" in context:
with self.context(self.CONTEXT_CHROME):
return self.execute_script(script, *args)
return self.execute_async_script(script, *args)
else:
return self.execute_script
return self.execute_async_script
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be

return self.execute_async_script(script, *args)

see my other comment.

@b4handjr b4handjr enabled auto-merge July 9, 2025 16:52
@b4handjr b4handjr added this pull request to the merge queue Jul 9, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jul 9, 2025
@b4handjr b4handjr added this pull request to the merge queue Jul 9, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jul 9, 2025
@b4handjr b4handjr added this pull request to the merge queue Jul 9, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to a conflict with the base branch Jul 9, 2025
@b4handjr b4handjr added this pull request to the merge queue Jul 9, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jul 9, 2025
@b4handjr b4handjr added this pull request to the merge queue Jul 9, 2025
Merged via the queue into main with commit 206e134 Jul 9, 2025
16 checks passed
@b4handjr b4handjr deleted the fix-12851 branch July 9, 2025 21:54
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.

Targeting Integration Tests are failing on CI
2 participants