Repository navigation
Check RequiredModules versions in Test-ModuleManifest - #28184
Open
candygoogy (candygoogy) wants to merge 2 commits into
Open
candygoogy (candygoogy) wants to merge 2 commits into
candygoogy (candygoogy) wants to merge 2 commits into
Conversation
`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.
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
🟡 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`).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

PR Summary
Test-ModuleManifestnow reports aRequiredModulesentry as invalid when the module is installed but none of its installed versions match the version (ModuleVersion,RequiredVersionorMaximumVersion) orGUIDin the entry.Fix #7495
PR Context
Before this change,
Test-ModuleManifestonly checked that a module with the required name exists. For example, withDepModule1.5.0 installed,RequiredModules = @(@{ ModuleName = 'DepModule'; ModuleVersion = '2.0' })passed without an error.Import-Modulewould then fail on the same manifest.What changed:
TestModuleManifestCommand, the modules found for the entry are now filtered withModuleIntrinsics.IsModuleMatchingConstraints, with the same GUID and version argumentsGetModuleIfAvailableuses when the module is loaded, including wildcardMaximumVersionvalues like1.*.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.Tests: new cases in
TestModuleManifest.Tests.ps1cover 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/Modulepasses locally on Windows.PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright header