-
Notifications
You must be signed in to change notification settings - Fork 77
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
Add tests for static_react_task example #795
Conversation
Codecov Report
@@ Coverage Diff @@
## main #795 +/- ##
==========================================
+ Coverage 64.25% 64.33% +0.08%
==========================================
Files 107 107
Lines 9176 9178 +2
==========================================
+ Hits 5896 5905 +9
+ Misses 3280 3273 -7
Continue to review full report at Codecov.
|
…nto add-cypress-to-static-task
Thanks for describing the issue in the Linking section above. I think I understand the problem here, the Mephisto builder does indeed call I think that adding a config such as My alternative suggestion here would be something like The usage would then be something like this: python run_task.py mephisto.task.post_build_script=./link_mephisto_task.sh and then you have a file npm link mephisto-task This way you could run any arbitrary code after the build step. For example, in other dialog tasks we have another local package we use called npm link mephisto-task bootstrap-chat
# here we link two packages instead of just one. running a script allows us this flexibility In sum, I propose introducing "lifecycle hooks"-style config params to allow for more flexible configuration that not only solves for the current problem we have now, but could handle future diverse needs gracefully. Also see my comment above for how to solve for the optimization issue. We would detect when |
The post_build flag definitely seems like a good suggestion. It allows for much more freedom in choosing what to run. I'm not sure that checking if post_build_script is not none can be used to sufficiently skip the optimization, however. What I mean is that it doesn't work in both directions. If the flag does exist then you can skip the optimization and build it. What if you want to go back to the package.json package version and remove your link? Well then you would remove the flag. However, if the webapp is not touched, then no rebuild will be triggered and the linked version will still be used. You would have to make some arbitrary change to the webapp to force the rebuild. I think the simplest way to do this would be to add a param called |
Let's do it. Explicit is always better. |
ℹ️ This makes sure to create the link with the local version of the package
ℹ️ These sections are 'Cypress Testing' and 'Local Package Development'
🔥 Removed extraneous code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there a bunch of places we need to update to post install script now
examples/remote_procedure/mnist/hydra_configs/conf/launch_with_local.yaml
Outdated
Show resolved
Hide resolved
examples/remote_procedure/template/hydra_configs/conf/launch_with_local.yaml
Outdated
Show resolved
Hide resolved
Yeah, for some reason I forgot to update it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good - thanks for adding tests!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will need to execute the update to a 3-param build_custom_bundle
as discussed, but overall I'm really excited for this PR. Thanks for getting this together!
We'll definitely want to take the learnings from here to eventually have a test for all of the example tasks, as well as a workflow for being able to create new tests for new tasks (with different configuration options as well like onboarding for instance). Will leave as future work for now though!
Setting `mephisto.task.force_rebuild=true` runs `npm build` before running your task. By default the task is only rebuilt if a file is changed in the webapp, not if a linked package is changed. | ||
|
||
Setting `mephisto.task.post_install_script=link_mephisto_task.sh` runs the `link_mephisto_task.sh` script after `npm install` is ran and before the task is started. This script should be located in the webapp folder of the task. While this script can do many things, for local package development the primary purpose of it is to link to a local package. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a note - we can probably get these to automatically trigger as part of the test suite when any file in packages
is updated, such that we get this 'for free' on PRs.
post_install_script: "" | ||
force_rebuild: false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given these have a default hydra value (introduced in TaskRun
's file) is it required that we include these defaults in all of these files?
I imagine the tradeoff between discoverability and boilerplate is an important one to think about if not, but I'd lean towards these more landing in the camp of a heavy user or contributor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As most people will not do local package development, I think it makes sense to remove them from the hydra config.
I just tested it, and it works without defining them in the hydra config(uses the TaskRun default value).
mephisto/tools/scripts.py
Outdated
if "force_rebuild" not in kwargs: | ||
warnings.warn( | ||
"Consider adding the force_rebuild property to your hydra config and passing it into build_custom_bundle()\nSteps on how to do this: \nhttps://github.com/facebookresearch/Mephisto/issues/811", | ||
stacklevel=2, | ||
) | ||
|
||
if "post_install_script" not in kwargs: | ||
warnings.warn( | ||
"Consider adding the post_install_script property to your hydra config and passing it into build_custom_bundle()\nSteps on how to do this: \nhttps://github.com/facebookresearch/Mephisto/issues/811", | ||
stacklevel=2, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New warning messages
They link to a closed issue that describes how to fix this
force_rebuild=cfg.mephisto.task.force_rebuild, | ||
post_install_script=cfg.mephisto.task.post_install_script, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An example of passing in the new parameters
mephisto/tools/scripts.py
Outdated
@@ -221,7 +224,7 @@ def augment_config_from_db(script_cfg: DictConfig, db: "MephistoDB") -> DictConf | |||
return script_cfg | |||
|
|||
|
|||
def build_custom_bundle(custom_src_dir, run_config: DictConfig): | |||
def build_custom_bundle(custom_src_dir, **kwargs: Union[str, bool]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kwargs is type Union[str, bool] because the parameter value can be a string(post_install_script) or bool(force_rebuild) currently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't you be able to just write this as:
def build_custom_bundle(custom_src_dir, force_rebuild: Optional[bool] = None, post_install_script: Optional[str] = None)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I can do it like that, I was just following Pratik's suggestion here: #791 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Etesam913, you'd still be using kwargs with @JackUrb's suggestion above by naming the arguments in the list
more info: https://treyhunner.com/2018/04/keyword-arguments-in-python/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh so kwargs just refers to passing the arguments with keywords as opposed to using the **kwargs parameter. I got it 👍
install: false | ||
project: ./examples/static_react_task/webapp | ||
config-file: ./cypress.config.js | ||
start: python examples/static_react_task/run_task.py mephisto.task.post_install_script=link_mephisto_task.sh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a note - we can probably get these to automatically trigger as part of the test suite when any file in
packages
is updated, such that we get this 'for free' on PRs.
I think I am already doing that in this github action (the start field)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed - missed that on first pass!
🚨 Added an exception when the post_install_script does not execute correctly 💡 Added a comment that has a link to a GitHub issue that explains how to set up force_rebuild and post_install_script
Thanks for getting e2e testing finally added to the codebase here |
Summary
Tests
Configured cypress with the static_react_task webapp.
Added tests that test if:
GitHub Actions
Added a github action workflow named, cypress-e2e-tests which runs the cypress tests as described above.
Linking (RESOLVED)
To make sure that tests on a task adapt when doing local package development, the example task's webapp should be linked to the package.
This can easily be done by writing something like this in the package.json :
"mephisto-task": "file: ../../../packages/mephisto-task",
However, this is not ideal as an individual would have to go to mephisto-task run
npm link
, and then go to the examples task's webapp folder and runnpm link mephisto-task
, and then cd out and type python run_task. This is clearly many extra steps.The best of both worlds would allow someone who is just running the task without doing any local package development work to avoid having to do all the npm linking. This intuitively should work by the following steps:
Setting the following in the package.json:
"mephisto-task": "^2.0.1",
running
npm link mephisto-task
in the webapp folderRunning python run_task.py in the root folder for the task.
However, this is not possible as running python run_task.py runs
npm install
in the webapp folder (done under the hood), which undoes the link and installs mephisto-task 2.01 from the package.json.To resolve this issue for local development a new command line arg is defined.
Example:
Step 1:
cd packages/mephisto-task npm link
Step 2:
cd examples/static_react_task python run_task.py mephisto.task.package_to_link_to=mephisto-task
This works as this command line arg is read by the program and runs npm link mephisto-task after the npm install to get the local version of the package.
Removing the mephisto.task.package_to_link_to command line arg skips the npm link command. This means that the version of the package as specified in the package.json is used.
This achieves the best of both worlds, easy running of a task when doing no local development, and local development without having to tinker with the package.json by adding a weird file path.
Downsides
https://github.com/facebookresearch/Mephisto/pull/795/files/ac59bbdcde1c861f892d32485aaee87b2c7db8bc#r901965814
Testing
static_react_task_test.mov
To see the GitHub action output you can look at the "cypress-e2e-tests" test and click on "details" in the bottom of this pr.
TODO:
This pr will fix the issues: #787 #788