Skip to content

Fix version comparison logic for 'latest' upgrades in PSGalleryModule and Package scripts#170

Merged
HeyItsGilbert merged 1 commit into
masterfrom
fix/version-comparison-latest
May 15, 2026
Merged

Fix version comparison logic for 'latest' upgrades in PSGalleryModule and Package scripts#170
HeyItsGilbert merged 1 commit into
masterfrom
fix/version-comparison-latest

Conversation

@HeyItsGilbert
Copy link
Copy Markdown
Member

@HeyItsGilbert HeyItsGilbert commented May 15, 2026

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:

You have the latest version of [module-name], with installed version [2.8.0] and PSGallery version [2.10.0]

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:

  1. Attempt to parse versions as [System.Management.Automation.SemanticVersion] objects first
  2. Fall back to [System.Version] if SemanticVersion parsing fails
  3. Compare the typed objects instead of strings
  4. Return $false if neither parsing method succeeds

Testing

Added regression tests to catch this scenario:

  • PSGalleryModule.Type.Tests.ps1: Verifies 2.8.0 → 2.10.0 upgrade with latest
  • Package.Type.Tests.ps1: Same scenario for Package dependencies

Fixes #139
Fixes #153

- 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
Copilot AI review requested due to automatic review settings May 15, 2026 22:39
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.ps1 to compare gallery vs installed versions using SemanticVersion / Version parsing rather than strings.
  • Update Package.ps1 to do the same for package source vs installed versions when latest is requested.
  • Add regression tests to cover the 2.8.0 -> 2.10.0 latest upgrade 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
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Resolving source version should be cheap so I'm ok with this.

@github-actions
Copy link
Copy Markdown

Test Results

    4 files     68 suites   3m 0s ⏱️
1 166 tests 1 080 ✅ 86 💤 0 ❌
1 412 runs  1 324 ✅ 88 💤 0 ❌

Results for commit b8ee0f1.

@HeyItsGilbert HeyItsGilbert merged commit b53eecc into master May 15, 2026
10 checks passed
@HeyItsGilbert HeyItsGilbert deleted the fix/version-comparison-latest branch May 15, 2026 22:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants