You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After speaking with Rob Holt (@rjmholt) I've learned that the Import-Module part of the codebase has gotten rather complex and needs to be refactored. However, due to numerous subtleties in how Import-Module works we need to achieve much better testing coverage of Import-Module before work can be done to refactor.
For some context the following PR is what is leading me to create this issue as I noticed some odd behavior which is described in the comments : #8758
I'm opening this meta issue to track ongoing work relating to this refactoring and hopefully it can lead to useful discussions. I will also use it to add my own insights, ideas and questions as I dive into it.
A potential refactoring I've been thinking about has to to with LoadModuleManifest method within ModuleCmdletBase.cs
This method does essentially two things :
Checks the manifest file properties.
Loads the related modules included in the file.
Since we already have a TestModuleManifest.cs which uses LoadModuleManifest + flag disabling all the imports it might be interesting to move the checks to TestModuleManifest.cs (something along the lines of CheckManifestProperties) and have LoadModuleManifest call that method before carrying on with the imports.
This has the following benefits :
Delegate module manifest checks to TestModuleManifest.cs so that the property checking can be "owned" by the file implementing the associated cmdlet.
Reduce ModuleCmdletBase.cs size by 25% making it more readable and relieving it of some of its responsibilities improving overall readability.
This has the following potential issues :
Module related cmdlets can have some subtle behavior and the current test base does not cover the cmdlets sufficiently to easily refactor without running a big risk of introducing unforeseen potential breaking changes.
LoadModuleManifest intertwines simple property checks with imports of related modules and therefore taking into account the previous point we could very well be introducting breaking changes by following through with that refactoring idea.
Currently the method does : TestSomeProperties => ImportModules => TestSomeMoreProperties
And I am thinking of : TestAllProperties => ImportModules
Here are the steps to get to where we'd like to go if this strategy gets a green light :
More tests for Remove-Module (very few tests exist for this one right now)
More tests for Import-Module
More tests for Test-ModuleManifest (This should be the one with the smallest risk of unexpected behavior)
More tests for Get-Module
Implement refactoring idea
One question I've had regarding the testing base in general is :
How do we know we have sufficient coverage regarding a cmdlet (especially since for example import-module can have subtle behavior so it's tough to test for that behavior without knowing about it) ?
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commented on Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commented on Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
Activity
[-]Feature Request[/-][+]Refactor ImportModule commandlet[/+]rjmholt commentedon Feb 21, 2019
A few PRs in this vein:
Note an example of a regression caused by this refactoring, fixed in #8218.
pougetat commentedon Mar 20, 2019
Hey Rob Holt (@rjmholt), Ilya (@iSazonov) 😄 ,
A potential refactoring I've been thinking about has to to with
LoadModuleManifestmethod withinModuleCmdletBase.csThis method does essentially two things :
Since we already have a
TestModuleManifest.cswhich usesLoadModuleManifest+ flag disabling all the imports it might be interesting to move the checks toTestModuleManifest.cs(something along the lines ofCheckManifestProperties) and haveLoadModuleManifestcall that method before carrying on with the imports.This has the following benefits :
TestModuleManifest.csso that the property checking can be "owned" by the file implementing the associated cmdlet.ModuleCmdletBase.cssize by 25% making it more readable and relieving it of some of its responsibilities improving overall readability.This has the following potential issues :
LoadModuleManifestintertwines simple property checks with imports of related modules and therefore taking into account the previous point we could very well be introducting breaking changes by following through with that refactoring idea.Currently the method does :
TestSomeProperties => ImportModules => TestSomeMorePropertiesAnd I am thinking of :
TestAllProperties => ImportModulesHere are the steps to get to where we'd like to go if this strategy gets a green light :
One question I've had regarding the testing base in general is :
iSazonov commentedon Mar 21, 2019
adityapatwardhan commentedon Mar 21, 2019
/cc James Truher (@JamesWTruher) is working on fixing CodeCov.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 23, 2023
This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.