Skip to content

Conversation

@rjmholt
Copy link
Collaborator

@rjmholt rjmholt commented Jun 21, 2018

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 -Pending flags from the tests around the breaking change (on the basis that the previous behaviour was a bug).

Fixes #7496.

PR Checklist


This change is Reviewable

@rjmholt rjmholt changed the title Refactor module version/GUID comparison logic WIP: Refactor module version/GUID comparison logic Jun 21, 2018
@rjmholt rjmholt added WG-Cmdlets-Core cmdlets in the Microsoft.PowerShell.Core module Issue-Code Cleanup the issue is for cleaning up the code with no impact on functionality labels Jun 21, 2018
@rjmholt rjmholt changed the title WIP: Refactor module version/GUID comparison logic Refactor module version/GUID comparison logic Jun 21, 2018
@iSazonov
Copy link
Collaborator

Also, if our testing coverage on this should be improved, I'm happy to add tests to this PR

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 Import-Module.Tests.ps1 file is already large so we could create new Import-Module-Versions.Tests.ps1.

@rjmholt
Copy link
Collaborator Author

rjmholt commented Jun 21, 2018

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...

@iSazonov
Copy link
Collaborator

See test\powershell\Modules\Microsoft.PowerShell.Core\ subdirectory.

@daxian-dbw daxian-dbw self-assigned this Jul 2, 2018
@anmenaga
Copy link

@rjmholt It would be good to see a green [Feature] test pass result. Can you please run it again?

@anmenaga
Copy link

@daxian-dbw @BrucePay We need to get some traction on this; this PR is sitting without a review for more than a month now...

@rjmholt
Copy link
Collaborator Author

rjmholt commented Jul 30, 2018

I need to write tests for this I would say. Will mark as WIP.

@rjmholt rjmholt changed the title Refactor module version/GUID comparison logic WIP: Refactor module version/GUID comparison logic Jul 30, 2018
@rjmholt rjmholt added the Breaking-Change breaking change that may affect users label Aug 10, 2018
@stale
Copy link

stale bot commented Sep 9, 2018

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.
Thank you for your contributions.
Community members are welcome to grab these works.

@stale stale bot added the Stale label Sep 9, 2018
@iSazonov
Copy link
Collaborator

@rjmholt Please resolve the merge conflict.

@stale stale bot removed the Stale label Sep 10, 2018
@rjmholt rjmholt force-pushed the refactor-module-version-check branch from 3467201 to e56b1b4 Compare September 28, 2018 22:28
@rjmholt rjmholt changed the title WIP: Refactor module version/GUID comparison logic Refactor module version/GUID comparison logic Sep 28, 2018
@rjmholt
Copy link
Collaborator Author

rjmholt commented Sep 28, 2018

I have now rebased this to include the 774 tests I wrote

@rjmholt rjmholt removed the Breaking-Change breaking change that may affect users label Sep 28, 2018
@rjmholt
Copy link
Collaborator Author

rjmholt commented Sep 29, 2018

I've removed the breaking change tag since I think another PR has already made the relevant change. This PR changes no tests and passes all existing.

This is wrong. That test PR skips those tests. This PR should enable them.

EDIT: Tests are now enabled, and pass.

@rjmholt rjmholt added the Breaking-Change breaking change that may affect users label Oct 10, 2018
@iSazonov
Copy link
Collaborator

Fix for CI is in #7987

Copy link
Member

@daxian-dbw daxian-dbw left a 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.

@iSazonov
Copy link
Collaborator

I'd expect that we add new tests because of "breaking change".

@daxian-dbw
Copy link
Member

@rjmholt Can you please summarize what the breaking change is in the PR description?

@rjmholt
Copy link
Collaborator Author

rjmholt commented Oct 12, 2018

@iSazonov Tests were added in #7499. I added the tests for the new behaviour then and have removed the -Pending flag in this PR.

Copy link
Member

@daxian-dbw daxian-dbw left a 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)
Copy link
Collaborator

@iSazonov iSazonov Oct 12, 2018

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.

Copy link
Collaborator Author

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.

@anmenaga
Copy link

@rjmholt Please address remaining couple of minor issues that Ilya pointed out and this will be ready.

@anmenaga
Copy link

@adityapatwardhan this looks ready.

@iSazonov
Copy link
Collaborator

@rjmholt Please address two comments.

@adityapatwardhan
Copy link
Member

@rjmholt Please address comments from @iSazonov. After that, is seems ready to merge.

@rjmholt
Copy link
Collaborator Author

rjmholt commented Oct 30, 2018

@adityapatwardhan, @iSazonov Feedback addressed -- let me know if any further changes are required.

@adityapatwardhan
Copy link
Member

adityapatwardhan commented Oct 30, 2018

@rjmholt please have a look at failing CI.

@adityapatwardhan
Copy link
Member

@SteveL-MSFT The newly added test is failing. It is marked as Feature and Feature tests were not run when the PR got merged.

@SteveL-MSFT
Copy link
Member

Looking

@SteveL-MSFT
Copy link
Member

SteveL-MSFT commented Oct 31, 2018

Test fix #8152

@iSazonov
Copy link
Collaborator

@rjmholt Please look CodeFactor issues and fix if they in your code.

@adityapatwardhan adityapatwardhan merged commit 5d06fba into PowerShell:master Nov 1, 2018
@iSazonov
Copy link
Collaborator

iSazonov commented Nov 2, 2018

@adityapatwardhan @TravisEz13 Could you please reword the merged commit? [Breaking change] was skipped in description.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Breaking-Change breaking change that may affect users Issue-Code Cleanup the issue is for cleaning up the code with no impact on functionality WG-Cmdlets-Core cmdlets in the Microsoft.PowerShell.Core module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Import-Module on path ignores version constraints

7 participants