-
Notifications
You must be signed in to change notification settings - Fork 6
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
disable "show answers" feature in production versions #406
Comments
@jonathanolson What do you think about this solution? isProduction: function() { return assert === null; } |
Or maybe we don't even need URQueryParameters.showAnswers = !!( assert && URQueryParameters.showAnswers ); |
Ah.... |
I'm not wild about testing the version identifier. But if all production versions truly followed the same convention (e.g. "1.2.5"), then it would be: isProduction: function() {
// A production version identifier is 3 numbers separated by dots, like "1.4.23"
return /^\d+\.\d+\.\d+$/.test( phet.chipper.version );
} But would this be a problem for PhET-iO versions? Or research versions? |
Definitely for phet-io, potentially other (future) versions. Could consider leaving it up to the Brand object to see (if it is brand-customized), then the 'phet' brand would just check Alternately, we could add a flag in the build process (that will be complicated for maintenance releases and build-server). If we're concerned about showing answers, it may be simplest to white-list domain ranges (www.colorado.edu/physics/phet/dev, phettest.colorado.edu, localhost/127.0.0.1, etc.) instead. |
We could have most dev builds skip the uglify step (so assertions can be turned on), but we'd probably want RCs to uglify. |
I'm unclear on a viable way to do this. And now that I've created issues for where this needed to be applied in my sims, I'd like to get it done. So labeling to (re)discuss at developer meeting. |
Thoughts on:
|
What about only enabling these features if the version contains "-dev" or "-rc"? |
More specific patterns may be helpful, if things like |
Perhaps checking if the string endsWith |
That sounds safe enough to me. |
3/2/17 dev meeting: |
We have
220 this.version = packageJSON.version; // @public (joist-internal) And there are multiple ways of getting the version identifier: • Global After discovering that function isProductionVersion() { return !!phet.chipper.version; } ... but not confident that this would work with phet-io versions. If I have to parse the version identifier, I'm tempted to add these static functions to SimVersion: /**
* Does the specified version identifier correspond to a dev version? E.g. '1.0.0-dev.2'
* @param {string} versionIdentifier
* @returns {boolean}
*/
isDevVersion: function( versionIdentifier ) {
return /^\d+\.\d+\.\d+-dev.[0-9]+$/.test( versionIdentifier );
},
/**
* Does the specified version identifier correspond to an RC (release candidate) version? E.g. '1.0.0-rc.2'
* @param {string} versionIdentifier
* @returns {boolean}
*/
isRCVersion: function( versionIdentifier ) {
return /^\d+\.\d+\.\d+-rc.[0-9]+$/.test( versionIdentifier );
} ... with awful call sites like: URQueryParameters.showAnswers = URQueryParameters.showAnswers &&
!(SimVersion.isDevVersion( phet.joist.sim.version ) || SimVersion.isRCVersion( phet.joist.sim.version )); Or I could take the easy way out and add more baggage to Sim: // See https://github.com/phetsims/joist/issues/406
isShowAnswersEnabled: function() {
var isDevVersion = /^\d+\.\d+\.\d+-dev.[0-9]+$/.test( this.version ); // e.g. '1.0.0-dev.1'
var isRCVersion = /^\d+\.\d+\.\d+-rc.[0-9]+$/.test( this.version ); // e.g. '1.0.0-rc.1'
return ( isDevVersion || isRCVersion );
} ... with call sites that look like: URQueryParameters.showAnswers = URQueryParameters.showAnswers && phet.joist.sim.isShowAnswersEnabled(); @jonathanolson @samreid, your input is needed: • Can we just test if |
A side issue here is that I no longer have any faith in the consistency of PhET's version identifier. Imo that is because (a) we haven't evolved the syntax and semantics to accommodate phet-io and (b) we've been publishing things (particularly phet-io) that don't conform to the syntax that we originally agreed on. |
In phetsims/chipper#507 (comment) we decided to add the phetio string as metadata into the version number. This conforms to semver as "Additional labels for pre-release and build metadata" and is formalized and documented in getVersionForBrand.js. Please clarify your specific concerns so we can address or discuss them. |
Ideally, |
It occurred to me that we are already detecting production versions in order to strip out assertions. In initialize-globals.js:
How about if we promote this to a global variable? I.e.:
Then to disable var EqualityExplorerQueryParameters = QueryStringMachine.getAll( {
// Shows answers to challenges in the 'Solve It!' screen. ...
showAnswers: { type: 'flag' },
...
} );
EqualityExplorerQueryParameters.showAnswers =
EqualityExplorerQueryParameters.showAnswers && !phet.chipper.isProduction; And perhaps promote The downside of this approach is that, like assertions, this will disable Labeling for discussion at developer meeting. |
We could enable E.g.: EqualityExplorerQueryParameters.showAnswers =
EqualityExplorerQueryParameters.showAnswers &&
( !phet.chipper.isProduction || phet.chipper.isDebugBuild ); |
The two preceding comments seem sensible to me, and not too much work, easy to test. |
It looks like that is hard-coded to 'production' in the template, so ANY sim build includes that flag. So the above notes look good as long as we want showAnswers when "it's either not built or is the debug build". |
7/12/18 dev meeting: |
Thinking about this a bit more... Since we may want to disable more than just the
Do other devs think this is a good idea? Suggestion for this global's name? |
My initial reaction is that |
If we're going to have two parameters, how about having an object that could also contain a version ID in case we ever need to change it, e.g: phet.chipper.buildConfig = {
isProduction: true,
isDebugBuild: false,
formatVersion: "1.0"
} |
@jbphet suggested:
That doesn't address the issue. Call sites would then have to do And |
Signed-off-by: Chris Malley <[email protected]>
Signed-off-by: Chris Malley <[email protected]>
I added Tested in equality-explorer with development html file (requirejs mode), equality-explorer_en_phet.html, and equality-explorer_all_phet_debug.html. If similar behavior is needed for other query parameters: (1) If the query parameter is read using QUERY_PARAMETERS_SCHEMA is initialize-globals.js, override it in this function in initialize-globals.js: /**
* Overrides query parameters when running the primary built html file. Does not affect debug.html.
* See https://github.com/phetsims/joist/issues/406
*/
( function() {
if ( phet.chipper.isProduction && !phet.chipper.isDebugBuild ) {
phet.chipper.queryParameters.showAnswers = false;
}
}() ); (2) If the query parameter is sim-specific, evaluate the following expression to decide whether to override it: if ( phet.chipper.isProduction && !phet.chipper.isDebugBuild ) {
ArithmeticQueryParameters.autoAnswer = false;
} |
All of my sims have been converted to use |
@jonathanolson randomly selected to review. |
Some of my sims (the ones with games) will be picking up this change when published. So this needs to be reviewed before then. |
The commits and strategy look good to me. Closing. |
Add something to joist that allows us to determine (at runtime) whether we're running a production version. The main purpose of this is to turn off query parameters that reveal answers.
@jonathanolson suggested adding
Sim.isProduction
that parses the version number.The text was updated successfully, but these errors were encountered: