Skip to content

Fix macOS preview package identifier detection to use version string#26690

Merged
TravisEz13 merged 6 commits intomasterfrom
copilot/fix-preview-package-installation
Jan 15, 2026
Merged

Fix macOS preview package identifier detection to use version string#26690
TravisEz13 merged 6 commits intomasterfrom
copilot/fix-preview-package-installation

Conversation

Copy link
Contributor

Copilot AI commented Jan 14, 2026

Fix macOS preview package identifier bug

This PR fixes issue #26673 where macOS preview packages were incorrectly installing to the stable location instead of the preview location.

Problem

The macOS preview package for PowerShell 7.6.0-preview.6 was installing to /usr/local/microsoft/powershell/7/ (stable location) instead of /usr/local/microsoft/powershell/7-preview/ (preview location). This prevented users from having both stable and preview versions installed simultaneously.

Root Cause

The bug was introduced in PR #26268 where native macOS packaging tools replaced fpm. The New-MacOSPackage function incorrectly detected preview builds by checking the package name:

$pkgIdentifier = Get-MacOSPackageId -IsPreview:($Name -like '*-preview')

However, preview builds use the package name "powershell" (not "powershell-preview"), so this check always returned $false, causing preview packages to use the stable identifier com.microsoft.powershell instead of com.microsoft.powershell-preview.

Solution

Extracted and centralized the preview detection logic into Get-MacOSPackageIdentifierInfo function that determines preview status and package identifier based on version string and LTS flag:

$packageInfo = Get-MacOSPackageIdentifierInfo -Version $Version -LTS:$LTS
$IsPreview = $packageInfo.IsPreview
$pkgIdentifier = $packageInfo.PackageIdentifier

All package identifier logic is now centralized in this single testable function.

Changes Made

  1. Created and refined Get-MacOSPackageIdentifierInfo function (tools/packaging/packaging.psm1):

    • Testable function that encapsulates all preview detection and package ID logic
    • Takes Version and LTS parameters
    • Returns hashtable with IsPreview and PackageIdentifier properties
    • Inlined the package identifier logic (removed Get-MacOSPackageId helper)
  2. Modified New-MacOSPackage function (tools/packaging/packaging.psm1):

    • Added [switch]$LTS parameter
    • Calls Get-MacOSPackageIdentifierInfo to get package info
  3. Modified New-MacOSLauncher function (tools/packaging/packaging.psm1):

    • Now uses Get-MacOSPackageIdentifierInfo instead of calling functions separately
    • Consistent with other parts of the codebase
  4. Modified New-MacOsDistributionPackage function (tools/packaging/packaging.psm1):

    • Inlined simple package identifier logic
  5. Modified Start-PSPackage function (tools/packaging/packaging.psm1):

    • Added LTS = $LTS to pass the LTS flag to New-MacOSPackage
  6. Streamlined unit tests (test/packaging/packaging.tests.ps1):

Expected Behavior After Fix

  • ✅ Preview packages (e.g., 7.6.0-preview.6) use identifier com.microsoft.powershell-preview and install to /usr/local/microsoft/powershell/7-preview/
  • ✅ Stable packages use identifier com.microsoft.powershell and install to /usr/local/microsoft/powershell/7/
  • ✅ LTS packages are treated as stable even if version string contains preview markers

Testing

Validation

  • ✅ Code review completed with no issues
  • ✅ All unit tests passing
  • ✅ Changes are minimal and surgical
  • ✅ Logic centralized in single testable function per code review feedback
  • ✅ Solution matches existing patterns in codebase

Fixes #26673

Original prompt

Problem

The macOS preview package is installing to the stable location instead of the preview location. This was reported in issue #26673 where users installing PowerShell 7.6.0-preview.6 found that their existing preview 5 installation was not updated.

The root cause is in the New-MacOSPackage function in tools/packaging/packaging.psm1 around line 2063. The current code determines if a package is a preview by checking the $Name parameter:

$pkgIdentifier = Get-MacOSPackageId -IsPreview:($Name -like '*-preview')

However, the package name for preview builds is just powershell (not powershell-preview), so this check always returns $false for preview builds, causing them to use the stable package identifier com.microsoft.powershell instead of com.microsoft.powershell-preview.

Solution

Change the preview detection in New-MacOSPackage to use the Test-IsPreview function with the $Version parameter, which is the correct approach used by other functions like New-MacOSLauncher:

Current (buggy):

$pkgIdentifier = Get-MacOSPackageId -IsPreview:($Name -like '*-preview')

Should be:

$IsPreview = Test-IsPreview -Version $Version -IsLTS:$LTS
$pkgIdentifier = Get-MacOSPackageId -IsPreview:$IsPreview

The Test-IsPreview function correctly examines the version string (e.g., 7.6.0-preview.6) to determine if it's a preview build.

Regression Source

This bug was introduced in PR #26268 "Replace fpm with native macOS packaging tools (pkgbuild/productbuild)" merged on October 28, 2025.

Files to Modify

  • tools/packaging/packaging.psm1 - Fix the New-MacOSPackage function to use Test-IsPreview instead of checking $Name

Acceptance Criteria

  • Preview macOS packages should use the identifier com.microsoft.powershell-preview
  • Preview macOS packages should install to /usr/local/microsoft/powershell/7-preview/
  • Stable macOS packages should continue to use com.microsoft.powershell and install to /usr/local/microsoft/powershell/7/

Fixes #26673

This pull request was created from Copilot chat.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits January 14, 2026 19:30
- Add LTS parameter to New-MacOSPackage function
- Use Test-IsPreview with Version parameter instead of checking Name
- Update Start-PSPackage to pass LTS parameter to New-MacOSPackage
- Fix both pkgIdentifier and IsPreview usages in New-MacOSPackage

This fixes issue #26673 where preview packages incorrectly used
the stable package identifier and installed to the wrong location.

Co-authored-by: TravisEz13 <[email protected]>
- Add comprehensive tests for Test-IsPreview function
- Add tests for Get-MacOSPackageId function
- Add integration tests verifying the fix for issue #26673
- Test verifies preview detection uses version string not package name

Co-authored-by: TravisEz13 <[email protected]>
Copilot AI changed the title [WIP] Fix macOS preview package installation detection Fix macOS preview package identifier detection to use version string Jan 14, 2026
Copilot AI requested a review from TravisEz13 January 14, 2026 19:36
- Add 4 new tests that verify New-MacOSPackage uses the correct logic
- Tests verify Test-IsPreview is called with Version and LTS parameters
- Tests demonstrate the difference between the buggy and fixed logic
- All 13 tests now passing (9 original + 4 new integration tests)

Co-authored-by: TravisEz13 <[email protected]>
- Extract preview detection logic into Get-MacOSPackageIdentifierInfo
- This function encapsulates the logic we changed in New-MacOSPackage
- Simplify tests by removing redundant test cases (13 -> 9 tests)
- All tests now directly test the refactored function
- Tests verify the fix for issue #26673

Co-authored-by: TravisEz13 <[email protected]>
- Removed Get-MacOSPackageId function and inlined its logic
- Updated New-MacOSLauncher to use Get-MacOSPackageIdentifierInfo
- Updated New-MacOsDistributionPackage to inline package ID logic
- Removed tests for Get-MacOSPackageId (7 tests remain, all passing)
- All package identifier logic now centralized in Get-MacOSPackageIdentifierInfo

Co-authored-by: TravisEz13 <[email protected]>
Copilot AI requested a review from TravisEz13 January 14, 2026 20:01
@TravisEz13 TravisEz13 marked this pull request as ready for review January 14, 2026 22:33
@TravisEz13 TravisEz13 requested review from a team and jshigetomi as code owners January 14, 2026 22:33
Copilot AI review requested due to automatic review settings January 14, 2026 22:33
Copy link
Contributor

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

This PR fixes a bug where macOS preview packages were incorrectly installing to the stable location (/usr/local/microsoft/powershell/7/) instead of the preview location (/usr/local/microsoft/powershell/7-preview/). The issue was introduced in PR #26268 when native macOS packaging tools replaced fpm.

Changes:

  • Centralized preview detection and package identifier logic into a new Get-MacOSPackageIdentifierInfo function that uses version string analysis instead of package name checking
  • Added proper LTS parameter support throughout the macOS packaging pipeline
  • Inlined simple package identifier logic in New-MacOsDistributionPackage for better maintainability
  • Added comprehensive unit tests verifying the fix and all scenarios

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
tools/packaging/packaging.psm1 Added Get-MacOSPackageIdentifierInfo function to centralize preview detection logic; updated New-MacOSPackage, New-MacOSLauncher, and New-MacOsDistributionPackage to use the new function; added LTS parameter to New-MacOSPackage
test/packaging/packaging.tests.ps1 Added comprehensive unit tests for Test-IsPreview and Get-MacOSPackageIdentifierInfo functions, including a specific test documenting the bug fix for issue #26673

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@TravisEz13 TravisEz13 added MustHave CL-BuildPackaging Indicates that a PR should be marked as a build or packaging change in the Change Log labels Jan 14, 2026
@TravisEz13 TravisEz13 merged commit 5fdc2a0 into master Jan 15, 2026
44 of 50 checks passed
@TravisEz13 TravisEz13 deleted the copilot/fix-preview-package-installation branch January 15, 2026 15:41
daxian-dbw pushed a commit to daxian-dbw/PowerShell that referenced this pull request Jan 20, 2026
TravisEz13 added a commit to TravisEz13/PowerShell that referenced this pull request Feb 10, 2026
daxian-dbw pushed a commit to daxian-dbw/PowerShell that referenced this pull request Feb 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BackPort-7.4.x-Consider Backport-7.5.x-Migrated Backport-7.6.x-Migrated CL-BuildPackaging Indicates that a PR should be marked as a build or packaging change in the Change Log MustHave

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7.6.0 Preview 6 installer doesn't actually update preview 5 on macOS

4 participants