Problem/Motivation
Currently, we run through the validators of Package Manager in order to know if we should support UI installations. However, some of those are warnings and some of them are errors. One example is the Xdebug warning, which exists due to performance issues. This makes debugging difficult, since we have to comment out the validator.
Steps to reproduce
Enable xdebug. Attempt to install a module from the UI in Project Browser.
Proposed resolution
Do not prevent installations if the only messages coming back from Package Manager are warnings; there should be at least one ERROR to prevent the installs from running.
NOTE: Adam (phenaproxima) suggested that PM could add a hasErrors() method, if we want to pursue that upstream.
| Comment | File | Size | Author |
|---|---|---|---|
| #41 | Screenshot 2024-06-21 at 9.48.36 AM.png | 203.48 KB | chrisfromredfin |
| #41 | Screenshot 2024-06-21 at 9.47.50 AM.png | 224.08 KB | chrisfromredfin |
| #37 | project_browser-3365180-37-b.png | 123.45 KB | sime |
| #37 | project_browser-3365180-37-a.png | 115.56 KB | sime |
| #36 | project_browser-3365180-36.png | 114.13 KB | sime |
Issue fork project_browser-3365180
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3365180-pm-warnings-for-2x
changes, plain diff MR !510
- 3365180-pm-warnings
changes, plain diff MR !390
Comments
Comment #2
earthday47Comment #4
earthday47Fix in place.
Does this need a test?
Also - do we want to print warnings still? At the moment this is suppressing them.
Comment #5
earthday47We want to print warnings
Comment #6
chrisfromredfinYes there should be a test to go along with this, if possible. Not sure how to get it to fire a warning, though.
Comment #7
earthday47Refactored the way we return messages from package manager to return errors and non-errors (warnings). If there are any errors, prevent installs and show the heading "Unable to download modules via the UI". If there are any warnings, we print them without a header.
I've added some screenshots of the various scenarios we could get if there are multiple messages. Chris informed me that we're unlikely to get both because of the way Package Manager works, regardless, the styles are in there just in case this happens.
Comment #8
earthday47Will have to work on tests later - any help in that department is appreciated!
Comment #9
chrisfromredfinTested this manually in DrupalPod and is working well. Allows me to install even if XDebug is enabled, for example, which is perfect. (And great DX.)
Kicking back to NW because it needs tests, but it's working well. If anyone knows of a way to write a test for this to (a) cause an error from PM and (b) cause a _warning_ from PM, help appreciated.
Fran did a code review also, just to get that started.
Comment #10
fjgarlin commentedAlso left a review in the MR. Nothing big, but worth addressing or discussing.
Comment #11
chrisfromredfinWe may want to wait on https://www.drupal.org/project/project_browser/issues/3376202 to come in.
Comment #12
chrisfromredfinComment #15
pfrillingAttached is a patch that _should_ add test coverage for both warnings and errors coming from package manager. I also attempted to merge the changes from the MR into this patch. I admit, I'm no Svelte expert, so there is a good chance I didn't do the JS stuff correctly.
Comment #17
andy-blumMoved Phil's patch into the MR and fixed PHPCS errors
Comment #18
andy-blumTest failures appear to be aligned with current failures against 1.0.x
Comment #19
simePlan to refresh/rebase and review as this touches the code i'm working on here https://www.drupal.org/project/project_browser/issues/3451863
Comment #20
simeComment #21
simeI'm still in progress cleaning up tests on this please message @sime in slack if you want to contribute or take over.
Comment #22
simeOK. So this was meant to be just a rebase, and it still is a rebase because I didn't really change anything from the work 6 months ago.
Code logic
I haven't really touched the code logic, but i did have to update the message handling in the svelte, since we are using the Drupal.messages() since the last work on this.
I'm hoping to get things back to where the code reviews were at, as I do think there is more work to do, but I also think it needs a review just to make sure committers are happy with test changes.
Tests
->validatePackageManager(). This reflected our code spending a lot of time in thepackage_managervalidation - for no good reason, because we just needed mock message strings. So i mockedInstallReadinessinstead, which means we are focussed on testing PB logic, instead of PM logic.PackageManagerFixtureUtilityTrait->initPackageManager()- removing logic, because we can use the$modulesproperty again, it seems.Comment #23
simeComment #24
simeI still have this assigned to myself just because if someone wants to pick it up it would be great to talk through the approach.
Some thoughts on next steps
Comment #27
simeRebased and created new PR on 2.0.x branch.
Comment #28
simeI mostly resolved @fjgarlin's comments from 1.x MR
Comment #29
simeNon working state, removing from needs review.
Comment #30
simeUpdated to 2.0.x (new branch). Old branch kept.
Comment #31
simeJust re-summarising this progress. The previous progress is still here against 1.x.
Testing strategy
Compared to the 1.x progress, I changed the way errors were mocked so that test logic did not need to go deep into Package Manager. So the updated tests are testing the scenario, using a mock, where InstallReadiness generates errors. This is testing how ProjectBrowser.svelte handles errors, rather than testing how PM generates errors.
The reason i changed the tests was because it was very flaky (intermittent time outs and failures) and slow for me (yes, even without xdebug). I think this remains a bigger problem with a lot of PB tests. PB tests often do full integration and maybe not necessarily. Since PM validation is slow I feel like most tests should be mocking what PM is doing. I don't think adding fake errors using event handlers is a good approach due to how much work PM is still expected to do (which contributes to intermittent timeouts of our tests).
But, well, long story short, I can revert how the tests are architected if asked. it was a journey for me to get them to work but i'm not wedded to my approach.
Message strategy
Instead of just setting status messages in PHP, we are turning them into strings and passing them to the svelte app, which then uses the javascript equivalent of setting the messages. We could just set these messages in PHP and remove about 20 lines of code. (I have tested this).
Now, regarding progress, the current 2.x code is still doing the same thing as a the 1.x code. With a couple of notes:
messenger.clear();) any current status messages just to avoid the screen getting filled with messages.package_manager_prefixingInstalling test dependencies
Finally, a big thing in this MR is that it seems like we no longer need to install package_manager in a weird way via initPackageManager() and we can just use the $modules property.
This wasn't necessarily a goal of the issue, but there was a code TODO for it that I addressed in an effort to reduce the complexity of the code.
Comment #33
phenaproximaComment #34
phenaproximaComment #35
sime@phenaproxima has tightened the scope and it is looking good to me. I like the improvements in variable handling.
I have created a few extra tickets out of the things I learnt in the course of working on it.
#3455220: [REDO} Resolve technical debt in initPackageManager()
#3455215: ServiceProviderBase::alter shouldn't call parent::register
#3455210: Identify and action solutions for flaky tests
Comment #36
simeI'm just going to combined these up a little. It would be rare to have multiple errors here, I believe, so we'll just prefix each one and skip the extra ones?
Comment #37
simeChanges I made result in this:
The worst case scenario is two messages of the same type, thus showing the same prefix, but I think this is acceptable as it's very rare and looks fine.
Comment #38
simeComment #39
simeFor anyone who wants to manually test this, a simple way is to install the project_browser_test module.
1. You need this in your settings.php, note that it will start showing test modules/themes in the UI.
$settings['extension_discovery_scan_tests'] = TRUE;2. Then install project_browser_test, I just use drush.
3. Now in
TestInstallerReadiness.phpin theonStatusCheckmethod, just change the code to manual create whatever messages you want to create.Comment #40
simeYa know, I think this is RTBC. Feels solid to me. Will let Chris have the final say.
Comment #41
chrisfromredfinWith manual testing, prior to applying this MR - all messages show (two status messages and the error). When applied, only the error shows (now correctly as a warning, though). What happened to the other messages?
Comment #42
simeComment #44
chrisfromredfinOh man just being able to have Xdebug on is such a win. ;)