From 4d02c1bb105eb3a2c5d44be3ffa77ad6c852ee69 Mon Sep 17 00:00:00 2001 From: vgoodric Date: Mon, 8 Apr 2024 13:41:52 -0600 Subject: [PATCH 01/11] stash --- libs/features/personalization/entitlements.js | 2 +- .../personalization/personalization.js | 41 +++++++++++-------- .../personalization/personalization.test.js | 9 ++++ 3 files changed, 34 insertions(+), 18 deletions(-) diff --git a/libs/features/personalization/entitlements.js b/libs/features/personalization/entitlements.js index f313ba1563..de8e76a315 100644 --- a/libs/features/personalization/entitlements.js +++ b/libs/features/personalization/entitlements.js @@ -21,7 +21,7 @@ const ENTITLEMENT_MAP = { export const getEntitlementMap = async () => { const { env, consumerEntitlements } = getConfig(); - if (env.name === 'prod') return { ...consumerEntitlements, ...ENTITLEMENT_MAP }; + if (env?.name === 'prod') return { ...consumerEntitlements, ...ENTITLEMENT_MAP }; const { default: STAGE_ENTITLEMENTS } = await import('./stage-entitlements.js'); return { ...consumerEntitlements, ...STAGE_ENTITLEMENTS }; }; diff --git a/libs/features/personalization/personalization.js b/libs/features/personalization/personalization.js index f0f7106c75..be83501be9 100644 --- a/libs/features/personalization/personalization.js +++ b/libs/features/personalization/personalization.js @@ -482,22 +482,6 @@ const checkForParamMatch = (paramStr) => { }; async function getPersonalizationVariant(manifestPath, variantNames = [], variantLabel = null) { - const config = getConfig(); - if (config.mep?.override) { - let manifest; - /* c8 ignore start */ - config.mep?.override?.split('---').some((item) => { - const pair = item.trim().split('--'); - if (pair[0] === manifestPath && pair.length > 1) { - [, manifest] = pair; - return true; - } - return false; - }); - /* c8 ignore stop */ - if (manifest) return manifest; - } - const variantInfo = variantNames.reduce((acc, name) => { let nameArr = [name]; if (!name.startsWith(TARGET_EXP_PREFIX)) nameArr = name.split(','); @@ -512,6 +496,7 @@ async function getPersonalizationVariant(manifestPath, variantNames = [], varian let userEntitlements = []; if (hasEntitlementTag) { + const config = getConfig(); userEntitlements = await config.entitlements(); } @@ -601,7 +586,7 @@ export async function getPersConfig(info, override = false) { config.executionOrder = `${executionOrder['manifest-execution-order']}-${executionOrder['manifest-type']}`; } else { // eslint-disable-next-line prefer-destructuring - config.manifestType = infoKeyMap[1]; + config.manifestType = infoKeyMap['manifest-type'][1]; config.executionOrder = '1-1'; } @@ -680,6 +665,26 @@ export async function runPersonalization(experiment, config) { }; } +function overridePersonalizationVariant(manifest, config) { + const { manifestPath, variantNames } = manifest; + if (!config.mep?.override) return; + let selectedVariant; + /* c8 ignore start */ + config.mep?.override?.split('---').some((item) => { + const pair = item.trim().split('--'); + if (pair[0] === manifestPath && pair.length > 1) { + [, selectedVariant] = pair; + return true; + } + return false; + }); + /* c8 ignore stop */ + if (selectedVariant && variantNames.includes(selectedVariant)) { + manifest.selectedVariantName = selectedVariant; + manifest.selectedVariant = manifest.variants[selectedVariant]; + } +} + function compareExecutionOrder(a, b) { if (a.executionOrder === b.executionOrder) return 0; return a.executionOrder > b.executionOrder ? 1 : -1; @@ -687,6 +692,7 @@ function compareExecutionOrder(a, b) { export function cleanAndSortManifestList(manifests) { const manifestObj = {}; + const config = getConfig(); manifests.forEach((manifest) => { if (!manifest?.manifest) return; if (!manifest.manifestPath) manifest.manifestPath = normalizePath(manifest.manifest); @@ -704,6 +710,7 @@ export function cleanAndSortManifestList(manifests) { } else { manifestObj[manifest.manifestPath] = manifest; } + if (config.mep.override) overridePersonalizationVariant(manifest, config); }); return Object.values(manifestObj).sort(compareExecutionOrder); } diff --git a/test/features/personalization/personalization.test.js b/test/features/personalization/personalization.test.js index 15e2da9179..89815bced3 100644 --- a/test/features/personalization/personalization.test.js +++ b/test/features/personalization/personalization.test.js @@ -195,3 +195,12 @@ describe('matchGlob function', () => { expect(result).to.be.true; }); }); + +it('should choose override to firefox', async () => { + let config = getConfig(); + config.mep = { override: '/path/to/manifest.json--param-newoffer=123' }; + await loadManifestAndSetResponse('./mocks/actions/manifestAppendToSection.json'); + await applyPers([{ manifestPath: '/path/to/manifest.json' }]); + config = getConfig(); + expect(config.experiments[0].selectedVariantName).to.equal('param-newoffer=123'); +}); From de078341c8cfb1f6ecc4d0c25040fb0564538a9e Mon Sep 17 00:00:00 2001 From: vgoodric Date: Mon, 8 Apr 2024 13:44:54 -0600 Subject: [PATCH 02/11] update unit tests --- .../personalization/personalization.js | 2 -- .../personalization/personalization.test.js | 18 +++++++++--------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/libs/features/personalization/personalization.js b/libs/features/personalization/personalization.js index be83501be9..b34ca8acca 100644 --- a/libs/features/personalization/personalization.js +++ b/libs/features/personalization/personalization.js @@ -669,7 +669,6 @@ function overridePersonalizationVariant(manifest, config) { const { manifestPath, variantNames } = manifest; if (!config.mep?.override) return; let selectedVariant; - /* c8 ignore start */ config.mep?.override?.split('---').some((item) => { const pair = item.trim().split('--'); if (pair[0] === manifestPath && pair.length > 1) { @@ -678,7 +677,6 @@ function overridePersonalizationVariant(manifest, config) { } return false; }); - /* c8 ignore stop */ if (selectedVariant && variantNames.includes(selectedVariant)) { manifest.selectedVariantName = selectedVariant; manifest.selectedVariant = manifest.variants[selectedVariant]; diff --git a/test/features/personalization/personalization.test.js b/test/features/personalization/personalization.test.js index 89815bced3..771e847619 100644 --- a/test/features/personalization/personalization.test.js +++ b/test/features/personalization/personalization.test.js @@ -150,6 +150,15 @@ describe('Functional Test', () => { assert.calledWith(window.console.log, 'Invalid selector: ', '.bad...selector'); window.console.log.reset(); }); + + it('should override to param-newoffer=123', async () => { + let config = getConfig(); + config.mep = { override: '/path/to/manifest.json--param-newoffer=123' }; + await loadManifestAndSetResponse('./mocks/actions/manifestAppendToSection.json'); + await applyPers([{ manifestPath: '/path/to/manifest.json' }]); + config = getConfig(); + expect(config.experiments[0].selectedVariantName).to.equal('param-newoffer=123'); + }); }); describe('matchGlob function', () => { @@ -195,12 +204,3 @@ describe('matchGlob function', () => { expect(result).to.be.true; }); }); - -it('should choose override to firefox', async () => { - let config = getConfig(); - config.mep = { override: '/path/to/manifest.json--param-newoffer=123' }; - await loadManifestAndSetResponse('./mocks/actions/manifestAppendToSection.json'); - await applyPers([{ manifestPath: '/path/to/manifest.json' }]); - config = getConfig(); - expect(config.experiments[0].selectedVariantName).to.equal('param-newoffer=123'); -}); From a92630765810a65f65c0650602660f896a8e2f56 Mon Sep 17 00:00:00 2001 From: vgoodric Date: Mon, 8 Apr 2024 13:59:24 -0600 Subject: [PATCH 03/11] add ? to config.mep --- libs/features/personalization/personalization.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/features/personalization/personalization.js b/libs/features/personalization/personalization.js index b34ca8acca..79638c35de 100644 --- a/libs/features/personalization/personalization.js +++ b/libs/features/personalization/personalization.js @@ -708,7 +708,7 @@ export function cleanAndSortManifestList(manifests) { } else { manifestObj[manifest.manifestPath] = manifest; } - if (config.mep.override) overridePersonalizationVariant(manifest, config); + if (config.mep?.override) overridePersonalizationVariant(manifest, config); }); return Object.values(manifestObj).sort(compareExecutionOrder); } From b03e3aa6187cdadc54de62d00c8640fc78d4be52 Mon Sep 17 00:00:00 2001 From: vgoodric Date: Mon, 8 Apr 2024 15:02:35 -0600 Subject: [PATCH 04/11] see if this let's it pass nala --- libs/features/personalization/personalization.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/features/personalization/personalization.js b/libs/features/personalization/personalization.js index 79638c35de..10fe0d2317 100644 --- a/libs/features/personalization/personalization.js +++ b/libs/features/personalization/personalization.js @@ -708,7 +708,7 @@ export function cleanAndSortManifestList(manifests) { } else { manifestObj[manifest.manifestPath] = manifest; } - if (config.mep?.override) overridePersonalizationVariant(manifest, config); + // if (config.mep?.override) overridePersonalizationVariant(manifest, config); }); return Object.values(manifestObj).sort(compareExecutionOrder); } From 0f8ec59b5a968043c39c3ef044ad2dc38b530a35 Mon Sep 17 00:00:00 2001 From: vgoodric Date: Mon, 8 Apr 2024 15:08:42 -0600 Subject: [PATCH 05/11] didn't help --- libs/features/personalization/personalization.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/features/personalization/personalization.js b/libs/features/personalization/personalization.js index 10fe0d2317..79638c35de 100644 --- a/libs/features/personalization/personalization.js +++ b/libs/features/personalization/personalization.js @@ -708,7 +708,7 @@ export function cleanAndSortManifestList(manifests) { } else { manifestObj[manifest.manifestPath] = manifest; } - // if (config.mep?.override) overridePersonalizationVariant(manifest, config); + if (config.mep?.override) overridePersonalizationVariant(manifest, config); }); return Object.values(manifestObj).sort(compareExecutionOrder); } From 73e2f01ac9b48336cc231188fbd7e83acb17b7ff Mon Sep 17 00:00:00 2001 From: vgoodric Date: Mon, 8 Apr 2024 22:06:28 -0600 Subject: [PATCH 06/11] add static-links to mep-preview-overlay --- libs/features/personalization/preview.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/features/personalization/preview.js b/libs/features/personalization/preview.js index 0e920f0c21..6a554abf69 100644 --- a/libs/features/personalization/preview.js +++ b/libs/features/personalization/preview.js @@ -127,7 +127,7 @@ function addPillEventListeners(div) { } function createPreviewPill(manifests) { - const overlay = createTag('div', { class: 'mep-preview-overlay', style: 'display: none;' }); + const overlay = createTag('div', { class: 'mep-preview-overlay static-links', style: 'display: none;' }); document.body.append(overlay); const div = document.createElement('div'); div.classList.add('mep-hidden'); From 607623ddf34fcd6bf23d1b801114cd39d57b001e Mon Sep 17 00:00:00 2001 From: vgoodric Date: Tue, 9 Apr 2024 17:12:21 -0600 Subject: [PATCH 07/11] add in override to default ability --- libs/features/personalization/personalization.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/libs/features/personalization/personalization.js b/libs/features/personalization/personalization.js index 79638c35de..de8d4de207 100644 --- a/libs/features/personalization/personalization.js +++ b/libs/features/personalization/personalization.js @@ -677,9 +677,14 @@ function overridePersonalizationVariant(manifest, config) { } return false; }); - if (selectedVariant && variantNames.includes(selectedVariant)) { - manifest.selectedVariantName = selectedVariant; - manifest.selectedVariant = manifest.variants[selectedVariant]; + if (selectedVariant) { + if (variantNames.includes(selectedVariant)) { + manifest.selectedVariantName = selectedVariant; + manifest.selectedVariant = manifest.variants[selectedVariant]; + } else { + manifest.selectedVariantName = selectedVariant; + manifest.selectedVariant = manifest.variants[selectedVariant]; + } } } From 2b031dd54f76397fcc9a388c858248eb0ce10fba Mon Sep 17 00:00:00 2001 From: Vivian A Goodrich <101133187+vgoodric@users.noreply.github.com> Date: Wed, 10 Apr 2024 09:40:47 -0600 Subject: [PATCH 08/11] avoid nested if statements Co-authored-by: Okan Sahin <39759830+mokimo@users.noreply.github.com> --- .../features/personalization/personalization.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/libs/features/personalization/personalization.js b/libs/features/personalization/personalization.js index de8d4de207..e3327f1476 100644 --- a/libs/features/personalization/personalization.js +++ b/libs/features/personalization/personalization.js @@ -677,15 +677,14 @@ function overridePersonalizationVariant(manifest, config) { } return false; }); - if (selectedVariant) { - if (variantNames.includes(selectedVariant)) { - manifest.selectedVariantName = selectedVariant; - manifest.selectedVariant = manifest.variants[selectedVariant]; - } else { - manifest.selectedVariantName = selectedVariant; - manifest.selectedVariant = manifest.variants[selectedVariant]; - } - } + if (!selectedVariant) return + if (variantNames.includes(selectedVariant)) { + manifest.selectedVariantName = selectedVariant; + manifest.selectedVariant = manifest.variants[selectedVariant]; + return + } + manifest.selectedVariantName = selectedVariant; + manifest.selectedVariant = manifest.variants[selectedVariant]; } function compareExecutionOrder(a, b) { From 8e1670ae23c4e4b5c2d1f5f4870b0fe76ab53a4f Mon Sep 17 00:00:00 2001 From: Vivian A Goodrich <101133187+vgoodric@users.noreply.github.com> Date: Wed, 10 Apr 2024 09:44:53 -0600 Subject: [PATCH 09/11] remove extra space Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- libs/features/personalization/personalization.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/features/personalization/personalization.js b/libs/features/personalization/personalization.js index e3327f1476..fe6aa96ffa 100644 --- a/libs/features/personalization/personalization.js +++ b/libs/features/personalization/personalization.js @@ -682,7 +682,7 @@ function overridePersonalizationVariant(manifest, config) { manifest.selectedVariantName = selectedVariant; manifest.selectedVariant = manifest.variants[selectedVariant]; return - } + } manifest.selectedVariantName = selectedVariant; manifest.selectedVariant = manifest.variants[selectedVariant]; } From 1574db6401eadbbd2d899f4f991217c81e1e5931 Mon Sep 17 00:00:00 2001 From: Vivian A Goodrich <101133187+vgoodric@users.noreply.github.com> Date: Wed, 10 Apr 2024 09:45:12 -0600 Subject: [PATCH 10/11] add semi colon Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- libs/features/personalization/personalization.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/features/personalization/personalization.js b/libs/features/personalization/personalization.js index fe6aa96ffa..71949ab676 100644 --- a/libs/features/personalization/personalization.js +++ b/libs/features/personalization/personalization.js @@ -681,7 +681,7 @@ function overridePersonalizationVariant(manifest, config) { if (variantNames.includes(selectedVariant)) { manifest.selectedVariantName = selectedVariant; manifest.selectedVariant = manifest.variants[selectedVariant]; - return + return; } manifest.selectedVariantName = selectedVariant; manifest.selectedVariant = manifest.variants[selectedVariant]; From 5ef08d6f2473bb2f2abeb3c03b5a61b46d4ecd8f Mon Sep 17 00:00:00 2001 From: Vivian A Goodrich <101133187+vgoodric@users.noreply.github.com> Date: Wed, 10 Apr 2024 09:45:43 -0600 Subject: [PATCH 11/11] add another semi colon Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- libs/features/personalization/personalization.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/features/personalization/personalization.js b/libs/features/personalization/personalization.js index 71949ab676..62f3587328 100644 --- a/libs/features/personalization/personalization.js +++ b/libs/features/personalization/personalization.js @@ -677,7 +677,7 @@ function overridePersonalizationVariant(manifest, config) { } return false; }); - if (!selectedVariant) return + if (!selectedVariant) return; if (variantNames.includes(selectedVariant)) { manifest.selectedVariantName = selectedVariant; manifest.selectedVariant = manifest.variants[selectedVariant];