Bug 1477255: offer context.environment as well as context.normandy r=leplatrem
authorEthan Glasser-Camp <ethan@betacantrips.com>
Wed, 02 Jan 2019 17:34:35 +0000
changeset 509461 49241781bf81a4e33cbf519a5a776ddc2eb6ebaa
parent 509460 7500e3ad817a91f000d3a249fe9bf42841f4f4b6
child 509462 6c2796200711c2e3a8ac721bc30a1576e2c16188
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersleplatrem
bugs1477255
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1477255: offer context.environment as well as context.normandy r=leplatrem Differential Revision: https://phabricator.services.mozilla.com/D15530
toolkit/components/normandy/lib/RecipeRunner.jsm
toolkit/components/normandy/test/browser/browser_RecipeRunner.js
--- a/toolkit/components/normandy/lib/RecipeRunner.jsm
+++ b/toolkit/components/normandy/lib/RecipeRunner.jsm
@@ -279,16 +279,18 @@ var RecipeRunner = {
 
   getFilterContext(recipe) {
     const environment = cacheProxy(ClientEnvironment);
     environment.recipe = {
       id: recipe.id,
       arguments: recipe.arguments,
     };
     return {
+      environment,
+      // Backwards compatibility -- see bug 1477255.
       normandy: environment,
     };
   },
 
   /**
    * Evaluate a recipe's filter expression against the environment.
    * @param {object} recipe
    * @param {string} recipe.filter The expression to evaluate against the environment.
--- a/toolkit/components/normandy/test/browser/browser_RecipeRunner.js
+++ b/toolkit/components/normandy/test/browser/browser_RecipeRunner.js
@@ -32,36 +32,39 @@ add_task(async function getFilterContext
     "syncMobileDevices",
     "syncSetup",
     "syncTotalDevices",
     "telemetry",
     "userId",
     "version",
   ];
   for (const key of expectedNormandyKeys) {
+    ok(key in context.environment, `environment.${key} is available`);
     ok(key in context.normandy, `normandy.${key} is available`);
   }
+  Assert.deepEqual(context.normandy, context.environment,
+                   "context offers normandy as backwards-compatible alias for context.environment");
 
   is(
-    context.normandy.recipe.id,
+    context.environment.recipe.id,
     recipe.id,
-    "normandy.recipe is the recipe passed to getFilterContext",
+    "environment.recipe is the recipe passed to getFilterContext",
   );
   delete recipe.unrelated;
   Assert.deepEqual(
-    context.normandy.recipe,
+    context.environment.recipe,
     recipe,
-    "normandy.recipe drops unrecognized attributes from the recipe",
+    "environment.recipe drops unrecognized attributes from the recipe",
   );
 
   // Filter context attributes are cached.
   await SpecialPowers.pushPrefEnv({set: [["app.normandy.user_id", "some id"]]});
-  is(context.normandy.userId, "some id", "User id is read from prefs when accessed");
+  is(context.environment.userId, "some id", "User id is read from prefs when accessed");
   await SpecialPowers.pushPrefEnv({set: [["app.normandy.user_id", "real id"]]});
-  is(context.normandy.userId, "some id", "userId was cached");
+  is(context.environment.userId, "some id", "userId was cached");
 
 });
 
 add_task(async function checkFilter() {
   const check = filter => RecipeRunner.checkFilter({filter_expression: filter});
 
   // Errors must result in a false return value.
   ok(!(await check("invalid ( + 5yntax")), "Invalid filter expressions return false");