Skip to content

Refactor ImportModule commandlet #8936

Closed

Description

@pougetat

Refactor Import-Module part of the codebase

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.

Activity

  1. changed the title [-]Feature Request[/-] [+]Refactor ImportModule commandlet[/+] on Feb 21, 2019
  2. rjmholt commented on Feb 21, 2019

    @rjmholt
    Collaborator
  3. pougetat commented on Mar 20, 2019

    @pougetat
    Author

    Hey Rob Holt (@rjmholt), Ilya (@iSazonov) 😄 ,

    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) ?
  4. iSazonov commented on Mar 21, 2019

    @iSazonov
    Collaborator

    How do we know …

    1. We should create tests for all practical scenarios
    2. Analyze code and cover all paths
    3. Use CodeCov (It seems still out of order /cc Aditya Patwardhan (@adityapatwardhan))
    4. Review opened issues for the code
  5. adityapatwardhan commented on Mar 21, 2019

    @adityapatwardhan
    Member

    /cc James Truher (@JamesWTruher) is working on fixing CodeCov.

  6. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    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.

  7. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    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.

  8. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    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.

  9. microsoft-github-policy-service commented on Nov 23, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Enhancementthe issue is more of a feature request than a bugResolution-No ActivityIssue has had no activity for 6 months or moreWG-Cmdletsgeneral cmdlet issues

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions