Fix version comparison logic for 'latest' upgrades in PSGalleryModule and Package scripts#170
Merged
Merged
Conversation
- PSGalleryModule.ps1: Compare parsed [System.Version] objects instead of strings - Package.ps1: Compare parsed [System.Version] objects instead of strings - Add regression tests for 2.8.0 → 2.10.0 upgrade scenario
There was a problem hiding this comment.
Pull request overview
Fixes incorrect latest upgrade behavior in PSDepend type scripts by replacing string-based version comparisons with typed comparisons, ensuring versions like 2.10.0 correctly compare greater than 2.8.0.
Changes:
- Update
PSGalleryModule.ps1to compare gallery vs installed versions usingSemanticVersion/Versionparsing rather than strings. - Update
Package.ps1to do the same for package source vs installed versions whenlatestis requested. - Add regression tests to cover the
2.8.0 -> 2.10.0latestupgrade scenario for both dependency types.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| Tests/PSGalleryModule.Type.Tests.ps1 | Adds a regression test ensuring latest triggers install when gallery minor version is higher. |
| Tests/Package.Type.Tests.ps1 | Adds a regression test ensuring latest triggers install when source minor version is higher. |
| PSDepend/PSDependScripts/PSGalleryModule.ps1 | Switches latest satisfaction check to typed version comparisons (SemanticVersion/Version). |
| PSDepend/PSDependScripts/Package.ps1 | Switches latest satisfaction check to typed version comparisons (SemanticVersion/Version). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+187
to
+191
| $SourceVersion = (& $GetSourceVersion) | ||
| [System.Version]$parsedExistingVersion = $null | ||
| [System.Version]$parsedSourceVersion = $null | ||
| [System.Management.Automation.SemanticVersion]$parsedExistingSemanticVersion = $null | ||
| [System.Management.Automation.SemanticVersion]$parsedSourceSemanticVersion = $null |
Member
Author
There was a problem hiding this comment.
Resolving source version should be cheap so I'm ok with this.
Test Results 4 files 68 suites 3m 0s ⏱️ Results for commit b8ee0f1. |
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.
Root Cause
PSDepend was failing to upgrade modules/packages when requesting
'latest'if a newer minor version was available. For example, machines with version 2.8.0 would not upgrade to 2.10.0, reporting:The issue was string-based version comparison instead of typed version comparison. When comparing as strings:
"2.10.0" -le "2.8.0"evaluates to$true(because "1" < "8" lexically)This caused the logic to incorrectly conclude that 2.10.0 was not newer than 2.8.0.
Solution
Both PSGalleryModule.ps1 and Package.ps1 now:
[System.Management.Automation.SemanticVersion]objects first[System.Version]if SemanticVersion parsing fails$falseif neither parsing method succeedsTesting
Added regression tests to catch this scenario:
latestFixes #139
Fixes #153