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

Improvements sourced from several shield add-on repositories #49

Merged
merged 67 commits into from
Mar 9, 2018

Conversation

motin
Copy link
Contributor

@motin motin commented Feb 15, 2018

Many improvements to the template. Primarily sourced from:

Version bump to 1.3.0

The idea of this PR is to, in one big swoop, bring this template forward to reflect today's improvements and desired changes discovered while developing the above add-ons, as well as make it easier (via npm run format addition and linting improvements) to merge and backport code between add-ons and the template (with less differences only from code style and whitespace).

@motin
Copy link
Contributor Author

motin commented Feb 15, 2018

This PR currently includes commits from several open PRs in this repo. They can be approved in this order: First #37 then #41. Don't approve #35 (since it's change is already included in #41). Approve #39 and #30 in any order.
After that, I'll rebase this PR on top of the current master.

@gregglind
Copy link
Contributor

gregglind commented Feb 15, 2018 via email

.eslintrc.js Outdated
"eqeqeq": "error",
"indent": ["warn", 2, {SwitchCase: 1}],
eqeqeq: "error",
indent: ["warn", 2, { SwitchCase: 1 }],
"mozilla/no-aArgs": "warn",
"mozilla/balanced-listeners": 0,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this should be "off", for consistency.

.eslintrc.js Outdated
"eqeqeq": "error",
"indent": ["warn", 2, {SwitchCase: 1}],
eqeqeq: "error",
indent: ["warn", 2, { SwitchCase: 1 }],
"mozilla/no-aArgs": "warn",
"mozilla/balanced-listeners": 0,
"no-console": "warn",
"no-shadow": ["error"],
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this could just be "error", and doesn't need to be wrapped in an array.

DEV.md Outdated

Repositories that should no longer be used as templates for new studies:

[https://github.com/gregglind/template-shield-study]() - The incubation repo for the updated structure and contents of this repo, implemented in late 2017.
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks "off". Not sure if we should duplicate the URL in the parens, or just use the <https://github.com/gregglind/template-shield-study> syntax since the URL and label are the same.

Same w/ the hello world example link below.

README.md Outdated
During FIRST INSTALL and EVERY OTHER STARTUP, users see:

- a 'toolbar button' (webExtension BrowserAction)
**Note**: This is toy / demonstration [Shield Study](https://wiki.mozilla.org/Firefox/Shield/Shield_Studies) Legacy Addon. Use this as a template for yours
Copy link
Contributor

Choose a reason for hiding this comment

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

nit "Add-on", for consistency.

TESTPLAN.md Outdated

Click on the 'x' button.
* notice closes
* addon uninstalls
Copy link
Contributor

Choose a reason for hiding this comment

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

add-on

TESTPLAN.md Outdated
1. Open a 2nd firefox window.
2. Close the initial window.
* notice closes
* addon uninstalls
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: add-on

TESTPLAN.md Outdated
---
## Helper code and tips
* notice closes
* addon uninstalls
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: add-on

TESTPLAN.md Outdated
}

printPings()
Example log output after installing the addon:
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: add-on (probably worth a global search and see what needs to be updated).

@motin
Copy link
Contributor Author

motin commented Feb 15, 2018

Btw, this PR also fixes #38

* - note first seen,
* - check eligible
*/
if (reason === REASONS.ADDON_INSTALL || reason === REASONS.ADDON_UPGRADE) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I can see how this would be useful for testing, but what about in deployment? @motin, @gregglind , If we have already deployed an addon, and we have to patch it, is that an upgrade or a fresh install?

If we do upgrade addons after deployment, do we want the addon to completely reset? I.e. there would multiple firstSeen and other initial pings from the old version and the user might see an "install" UI element more than once.

This point is moot if we never see the ADDON_UPGRADE reason when the study is re-deployed through Normandy.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Based on @mythmon's comments:

The add-on manager calls something an upgrade when an add-on with the same ID as an existing add-on is installed, and a greater or equal version

Normandy generally doesn't trigger upgrades, because Normandy doesn't change studies in practice. Instead it installs the add-on once, and then doesn't touch it until unenrollment time. In the future, when Normandy supports changing add-ons in place, it will trigger upgrades.

In light of this, my vote is that we future-proof the template and not equate ADDON_INSTALL with ADDON_UPGRADE. QA may have to remove the old version before re-installing a new version, but that seems a small price to pay to avoid potential unintended consequences of studies resetting on upgrade in the future. I think what happens on ADDON_UPGRADE will vary by study. @mythmon , @gregglind , @raymak, @motin , any feelings one way or the other?

@gregglind
Copy link
Contributor

gregglind commented Feb 17, 2018 via email

@mythmon
Copy link

mythmon commented Feb 20, 2018

The add-on manager calls something an upgrade when an add-on with the same ID as an existing add-on is installed, and a greater or equal version

Normandy generally doesn't trigger upgrades, because Normandy doesn't change studies in practice. Instead it installs the add-on once, and then doesn't touch it until unenrollment time. In the future, when Normandy supports changing add-ons in place, it will trigger upgrades.

package.json Outdated
@@ -20,6 +20,9 @@
"bugs": {
"url": "https://github.com/mozilla/shield-studies-addon-template/issues"
},
"engines": {
"node": ">=8.9.0"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know we require Node 7.6+ for async/await, but is there a specific reason why we require >= 8.9.0? I read that it's the LTS for Node v8. Just curious mostly.

test/utils.js Outdated
@@ -33,6 +33,9 @@ const FIREFOX_PREFERENCES = {
// NECESSARY for all 57+ builds
"extensions.legacy.enabled": true,

// Include log output in browser console
"shield.testing.logging.level": 10, // Trace
Copy link
Collaborator

@biancadanforth biancadanforth Feb 20, 2018

Choose a reason for hiding this comment

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

This doesn't look to be used in bootstrap.js any longer. In this PR's bootstrap, you pull the logging level from Config.jsm instead in initLog(). We should probably do one or the other, but not both.

I'm actually in favor of a pref in utils.js, since then we wouldn't have to remember to turn off logging in Config.jsm when shipping the addon. SSAU also pulls the logging level from Config.jsm, so we'd need a patch for it to read the pref instead as well.

Can you update this PR to read the logging level for initLog() from this pref in bootstrap.js and in any other files like Feature.jsm as well?

@gregglind
Copy link
Contributor

gregglind commented Feb 20, 2018 via email

@motin
Copy link
Contributor Author

motin commented Feb 20, 2018

Rebased upon latest master. Addressed open concerns via 815ff06 and 9d7fdaa

@motin
Copy link
Contributor Author

motin commented Feb 20, 2018

@biancadanforth I removed the configuration of study-specific logging since this should not belong in the template to begin with. We should expect a studyUtils.log API, like pioneerUtils has. Good target for mozilla/shield-studies-addon-utils#101

Lazy-loading StudyUtils makes it unavailable outside startup(), this affects when and where logging and REASONS is available. @gregglind Do we have to do a straight Cu.import to make this available in all of bootstrap.js?

@biancadanforth
Copy link
Collaborator

@motin That's a great point about the logging. Could you add a link to the pioneerUtils as a comment in that issue as a great example of how to do that?

// Start up your feature, with specific variation info.
this.feature = new Feature({variation, studyUtils, reasonName: REASONS[reason]});
// start up the chrome-privileged part of the study
this.feature.privilegedStartup();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just curious, why is this better than instantiating the feature once and having its constructor method startup the feature?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Originally, I separated them for the ability to have to extension startup hooks - one for when the webextension had loaded asynchronously, and one at the end of startup() for privileged startup logic. Currently, there is only one startup method but it is anyway clearer to not have side-effects happen in a constructor event.

package.json Outdated
@@ -45,7 +45,6 @@
"npm-run-all": "^4.1.1",
"nsp": "^2.8.1",
"onchange": "^3.2.1",
"path": "^0.12.7",
Copy link
Collaborator

Choose a reason for hiding this comment

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

We use this devDependency in run-firefox.js; can you add it back?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That removal comes from #41 - comment that this dependency is used, close the pr and I will rebase this pr to not include this removal :)

Copy link
Contributor

Choose a reason for hiding this comment

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

The path module is the built in Node.js module. Adding it in package.json includes a module from npm — which could potentially be dangerous.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Noted, and I have merged #41. Thank you Peter for clarifying!

// if you have code to handle expiration / long-timers, it could go here
/*
if (this.feature.hasExpired()) {
// Please note that the general study expiration should probably be taken care of by Normandy.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is news to me! I have been handling general study expiration in my addon code -- @mythmon , does Normandy handle this? What do you recommend study authors do re: general study expiration?

Copy link

Choose a reason for hiding this comment

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

Normandy does not handle this, and I do not agree with this comment.

Normandy will handle removal of the add-on when the study is ended on the server, but that is not what this feature is generally used for. The first expiration timer that I'm aware of was designed to expire an experiment as a fail safe, in case Normandy could not be contacted, or someone forgot to disable the recipe on the server.

In that original case, the expiry timer was not a normal end to the study, but a failsafe in case something went wrong. As such, it should be implemented in a very reliable way by the add-on.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for clarifying @mythmon, adding this information as a comment in the template

@motin
Copy link
Contributor Author

motin commented Feb 21, 2018

@motin That's a great point about the logging. Could you add a link to the pioneerUtils as a comment in that issue as a great example of how to do that?

Done

TESTPLAN.md Outdated

During INSTALL ONLY users see:
* Download a Release version of Firefox (Release is required for the recommendation heuristics to work)
Copy link
Collaborator

Choose a reason for hiding this comment

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

What do you mean by "recommendation heuristics"? Can you expand on that a little here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, a leftover from taar-v2, removing...

@@ -119,22 +119,26 @@ function shutdown(addonData, reason) {
// FRAGILE: handle uninstalls initiated by USER or by addon
if (reason === REASONS.ADDON_UNINSTALL || reason === REASONS.ADDON_DISABLE) {
log.debug("uninstall or disable");

Copy link
Collaborator

@biancadanforth biancadanforth Feb 23, 2018

Choose a reason for hiding this comment

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

Can you add a note here to say we check if feature exists because it's possible the study is shutting down before it has instantiated the feature. Ex: if the user is ineligible or if the study has expired.

Should probably have clicked a few lines below for this comment. :X

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Clarifying this

motin added 24 commits March 9, 2018 23:23
…e already on the way to be merged into) shield-study-addon-utils
@motin
Copy link
Contributor Author

motin commented Mar 9, 2018

Rebased upon the latest master. Ready for merge.

@biancadanforth biancadanforth merged commit 6aabef0 into mozilla:master Mar 9, 2018
@motin motin deleted the improvements-2 branch March 10, 2018 07:33
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.

6 participants