-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Refactor module version/GUID comparison logic #7125
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
Refactor module version/GUID comparison logic #7125
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 |
|
@rjmholt It would be good to see a green |
|
@daxian-dbw @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. |
|
@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. |
|
Fix for CI is in #7987 |
daxian-dbw
left a 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.
LGTM except for the comment about the optional parameters.
|
I'd expect that we add new tests because of "breaking change". |
|
@rjmholt Can you please summarize what the breaking change is in the PR description? |
daxian-dbw
left a 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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems the name should be IsAlreadyLoadedModuleMatchingConstraints. The module description should be corrected too.
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.
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.
|
@rjmholt Please address remaining couple of minor issues that Ilya pointed out and this will be ready. |
|
@adityapatwardhan this looks ready. |
|
@rjmholt Please address two comments. |
|
@adityapatwardhan, @iSazonov Feedback addressed -- let me know if any further changes are required. |
|
@rjmholt please have a look at failing CI. |
|
@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 |
|
@rjmholt Please look CodeFactor issues and fix if they in your code. |
|
@adityapatwardhan @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