Refactor module version/GUID comparison logic - #7125
Aditya Patwardhan (adityapatwardhan) merged 6 commits into
Conversation
To make a quality check of this change we are forced to do a lot of tests locally. So it makes sense to start by reviewing and extending the tests in the repo. I see that we don't actually have the tests for this code. I think we could add the new tests in new separate PR and then continue the PR. The |
|
Ah so there is an Import-Module.Tests.ps1? It’s not under /test/powershell/engine/Module like I expected. Where is it? Yes agreed we should bulk up the tests in another PR to merge before this one. I’ve been thinking about doing that but now I know there’s a test file I will see what we already have... |
|
See |
|
Rob Holt (@rjmholt) It would be good to see a green |
|
Dongbo Wang (@daxian-dbw) Bruce Payette (@BrucePay) We need to get some traction on this; this PR is sitting without a review for more than a month now... |
|
I need to write tests for this I would say. Will mark as WIP. |
|
This PR has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed if no further activity occurs within 10 days. |
|
Rob Holt (@rjmholt) Please resolve the merge conflict. |
3467201 to
e56b1b4
Compare
|
I have now rebased this to include the 774 tests I wrote |
|
This is wrong. That test PR skips those tests. This PR should enable them. EDIT: Tests are now enabled, and pass. |
|
Rob Holt (@rjmholt) Can you please summarize what the breaking change is in the PR description? |
|
Ilya (@iSazonov) Tests were added in #7499. I added the tests for the new behaviour then and have removed the |
Dongbo Wang (daxian-dbw)
left a comment
There was a problem hiding this comment.
Thanks for revisit some of the optional parameters.
| /// </summary> | ||
| /// <param name="alreadyLoadedModule">The already loaded module that matched the name of the module to load.</param> | ||
| /// <returns>True if the pre-loaded module matches all GUID and version constraints provided, false otherwise.</returns> | ||
| internal bool IsModuleAlreadyLoaded(PSModuleInfo alreadyLoadedModule) |
There was a problem hiding this comment.
Seems the name should be IsAlreadyLoadedModuleMatchingConstraints. The module description should be corrected too.
There was a problem hiding this comment.
This method has been in PowerShell with this name (and with this behaviour) since at least Win8. I would be happy to change it, so long as it's not going to cause any issues.
|
Rob Holt (@rjmholt) Please address remaining couple of minor issues that Ilya pointed out and this will be ready. |
|
Aditya Patwardhan (@adityapatwardhan) this looks ready. |
|
Rob Holt (@rjmholt) Please address two comments. |
|
Rob Holt (@rjmholt) Please address comments from Ilya (@iSazonov). After that, is seems ready to merge. |
|
Aditya Patwardhan (@adityapatwardhan), Ilya (@iSazonov) Feedback addressed -- let me know if any further changes are required. |
|
Rob Holt (@rjmholt) please have a look at failing CI. |
|
Steve Lee (@SteveL-MSFT) The newly added test is failing. It is marked as Feature and Feature tests were not run when the PR got merged. |
|
Looking |
|
Test fix #8152 |
|
Rob Holt (@rjmholt) Please look CodeFactor issues and fix if they in your code. |
|
Aditya Patwardhan (@adityapatwardhan) Travis Plunk (@TravisEz13) Could you please reword the merged commit? [Breaking change] was skipped in description. |
PR Summary
TLDR: Factors out module GUID/version checking logic to all use the same code path.
This PR routes all of the module GUID/version checking through
ModuleIntrinsics.IsModuleMatchingSpec()(or a sub-method of it), so that all the version checking is consistent and DRY.Previously the code had a number of 6-line if-conditions and cascading if-elses that all check module versioning in a slightly different way. I've tried to identify the common logic and unify it all.
Breaking Change Summary
Fix #7496
Previous to this PR, having a module loaded with one version, meant that importing a different version of that module would give you the (wrong) loaded version. This change fixes the version check so that the loaded module is only used when it is the correct version. See #7496.
Tests
Tests for this PR were already added in #7499. This PR just removes the
-Pendingflags from the tests around the breaking change (on the basis that the previous behaviour was a bug).Fixes #7496.
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:to the beginning of the title and remove the prefix when the PR is ready.[feature]if the change is significant or affects feature testsThis change is