Skip to content

Check RequiredModules versions in Test-ModuleManifest - #28184

Open
candygoogy (candygoogy) wants to merge 2 commits into
PowerShell:masterfrom
candygoogy:fix-test-modulemanifest-required-version
Open

candygoogy (candygoogy) wants to merge 2 commits into
PowerShell:masterfrom
candygoogy:fix-test-modulemanifest-required-version

Conversation

@candygoogy

@candygoogy candygoogy (candygoogy) commented Oct 11, 2026 •

Copy link
Copy Markdown

PR Summary

Test-ModuleManifest now reports a RequiredModules entry as invalid when the module is installed but none of its installed versions match the version (ModuleVersion, RequiredVersion or MaximumVersion) or GUID in the entry.

Fix #7495

PR Context

Before this change, Test-ModuleManifest only checked that a module with the required name exists. For example, with DepModule 1.5.0 installed, RequiredModules = @(@{ ModuleName = 'DepModule'; ModuleVersion = '2.0' }) passed without an error. Import-Module would then fail on the same manifest.

What changed:

  • In TestModuleManifestCommand, the modules found for the entry are now filtered with ModuleIntrinsics.IsModuleMatchingConstraints, with the same GUID and version arguments GetModuleIfAvailable uses when the module is loaded, including wildcard MaximumVersion values like 1.*.
  • The error is the same one already used when the module is missing (Modules_InvalidRequiredModulesinModuleManifest). The message now shows the whole entry, for example @{ ModuleName = 'DepModule'; ModuleVersion = '2.0' }, so it's clear which version was not found. For entries without a version, the message is unchanged.
  • As discussed in the issue, this doesn't check the required modules' own dependencies, and it doesn't add a new parameter.

Tests: new cases in TestModuleManifest.Tests.ps1 cover ModuleVersion too high, RequiredVersion not installed, MaximumVersion too low, a GUID that doesn't match, and five matching entries. The four error cases fail without the fix. test/powershell/engine/Module passes locally on Windows.

PR Checklist

`Test-ModuleManifest` reported a `RequiredModules` entry as invalid only
when no module with that name was available. Version constraints in the
entry (`ModuleVersion`, `RequiredVersion`, `MaximumVersion`) were ignored.
Now an available module must also match those constraints.
@candygoogy
candygoogy (candygoogy) requested a review from a team as a code owner October 11, 2026 15:41
Copilot AI balanced review requested due to automatic review settings October 11, 2026 15:41
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The validation omits the required module’s GUID constraint.

1 open finding
What changed in this PR

Validates RequiredModules version constraints in Test-ModuleManifest.

Changes:

  • Checks minimum, required, and maximum versions.
  • Improves invalid-entry error details.
  • Adds Pester coverage for matching and unavailable versions.
File Description
TestModuleManifestCommand.cs Adds constraint validation.
TestModuleManifest.Tests.ps1 Tests version constraint behavior.

🧠 Review effort: Balanced


💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +195 to +199
bool isRequiredModuleAvailable = modules.Exists(m => ModuleIntrinsics.IsModuleMatchingConstraints(
m,
requiredVersion: requiredModule.RequiredVersion,
minimumVersion: requiredModule.Version,
maximumVersion: requiredModule.MaximumVersion == null ? null : GetMaximumVersion(requiredModule.MaximumVersion)));
Pass the entry's GUID to `IsModuleMatchingConstraints` too, so the check
matches what module loading uses (`GetModuleIfAvailable`).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test-ModuleManifest checks if a required module is installed but doesn't check version

2 participants