Skip to content

Commit a7b4d8e

Browse files
CopilotTravisEz13
andcommitted
Fix macOS preview package identifier detection to use version string (PowerShell#26690)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: TravisEz13 <10873629+TravisEz13@users.noreply.github.com>
1 parent 5efa21e commit a7b4d8e

2 files changed

Lines changed: 119 additions & 17 deletions

File tree

test/packaging/packaging.tests.ps1

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
3+
4+
Describe "Packaging Module Functions" {
5+
BeforeAll {
6+
Import-Module $PSScriptRoot/../../build.psm1 -Force
7+
Import-Module $PSScriptRoot/../../tools/packaging/packaging.psm1 -Force
8+
}
9+
10+
Context "Test-IsPreview function" {
11+
It "Should return True for preview versions" {
12+
Test-IsPreview -Version "7.6.0-preview.6" | Should -Be $true
13+
Test-IsPreview -Version "7.5.0-rc.1" | Should -Be $true
14+
}
15+
16+
It "Should return False for stable versions" {
17+
Test-IsPreview -Version "7.6.0" | Should -Be $false
18+
Test-IsPreview -Version "7.5.0" | Should -Be $false
19+
}
20+
21+
It "Should return False for LTS builds regardless of version string" {
22+
Test-IsPreview -Version "7.6.0-preview.6" -IsLTS | Should -Be $false
23+
Test-IsPreview -Version "7.5.0" -IsLTS | Should -Be $false
24+
}
25+
}
26+
27+
Context "Get-MacOSPackageIdentifierInfo function (New-MacOSPackage logic)" {
28+
It "Should detect preview builds and return preview identifier" {
29+
$result = Get-MacOSPackageIdentifierInfo -Version "7.6.0-preview.6" -LTS:$false
30+
31+
$result.IsPreview | Should -Be $true
32+
$result.PackageIdentifier | Should -Be "com.microsoft.powershell-preview"
33+
}
34+
35+
It "Should detect stable builds and return stable identifier" {
36+
$result = Get-MacOSPackageIdentifierInfo -Version "7.6.0" -LTS:$false
37+
38+
$result.IsPreview | Should -Be $false
39+
$result.PackageIdentifier | Should -Be "com.microsoft.powershell"
40+
}
41+
42+
It "Should treat LTS builds as stable even with preview version string" {
43+
$result = Get-MacOSPackageIdentifierInfo -Version "7.4.0-preview.1" -LTS:$true
44+
45+
$result.IsPreview | Should -Be $false
46+
$result.PackageIdentifier | Should -Be "com.microsoft.powershell"
47+
}
48+
49+
It "Should NOT use package name for preview detection (bug fix verification)" {
50+
# This test verifies the fix for issue #26673
51+
# The bug was using ($Name -like '*-preview') which always returned false
52+
# because preview builds use Name="powershell" not "powershell-preview"
53+
54+
$Version = "7.6.0-preview.6"
55+
$Name = "powershell" # Preview builds use "powershell" not "powershell-preview"
56+
57+
# The INCORRECT logic (the bug): $Name -like '*-preview'
58+
$incorrectCheck = $Name -like '*-preview'
59+
$incorrectCheck | Should -Be $false -Because "Package name is 'powershell' not 'powershell-preview'"
60+
61+
# The CORRECT logic (the fix): uses version string
62+
$result = Get-MacOSPackageIdentifierInfo -Version $Version -LTS:$false
63+
$result.IsPreview | Should -Be $true -Because "Version string correctly identifies preview"
64+
$result.PackageIdentifier | Should -Be "com.microsoft.powershell-preview"
65+
}
66+
}
67+
}

tools/packaging/packaging.psm1

Lines changed: 52 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,6 +1360,7 @@ function New-UnixPackage {
13601360
AppsFolder = $AppsFolder
13611361
HostArchitecture = $HostArchitecture
13621362
CurrentLocation = $CurrentLocation
1363+
LTS = $LTS
13631364
}
13641365

13651366
try {
@@ -1504,7 +1505,12 @@ function New-MacOsDistributionPackage
15041505

15051506
# Get package ID if not provided
15061507
if (-not $PackageIdentifier) {
1507-
$PackageIdentifier = Get-MacOSPackageId -IsPreview:$IsPreview.IsPresent
1508+
if ($IsPreview.IsPresent) {
1509+
$PackageIdentifier = 'com.microsoft.powershell-preview'
1510+
}
1511+
else {
1512+
$PackageIdentifier = 'com.microsoft.powershell'
1513+
}
15081514
}
15091515

15101516
# Minimum OS version
@@ -1973,7 +1979,9 @@ function New-MacOSPackage
19731979
[Parameter(Mandatory)]
19741980
[string]$HostArchitecture,
19751981

1976-
[string]$CurrentLocation = (Get-Location)
1982+
[string]$CurrentLocation = (Get-Location),
1983+
1984+
[switch]$LTS
19771985
)
19781986

19791987
Write-Log "Creating macOS package using pkgbuild and productbuild..."
@@ -2048,8 +2056,10 @@ function New-MacOSPackage
20482056
Copy-Item -Path "$AppsFolder/*" -Destination $appsInPkg -Recurse -Force
20492057
}
20502058

2051-
# Build the component package using pkgbuild
2052-
$pkgIdentifier = Get-MacOSPackageId -IsPreview:($Name -like '*-preview')
2059+
# Get package identifier info based on version and LTS flag
2060+
$packageInfo = Get-MacOSPackageIdentifierInfo -Version $Version -LTS:$LTS
2061+
$IsPreview = $packageInfo.IsPreview
2062+
$pkgIdentifier = $packageInfo.PackageIdentifier
20532063

20542064
if ($PSCmdlet.ShouldProcess("Build component package with pkgbuild")) {
20552065
Write-Log "Running pkgbuild to create component package..."
@@ -2074,7 +2084,7 @@ function New-MacOSPackage
20742084
-OutputDirectory $CurrentLocation `
20752085
-HostArchitecture $HostArchitecture `
20762086
-PackageIdentifier $pkgIdentifier `
2077-
-IsPreview:($Name -like '*-preview')
2087+
-IsPreview:$IsPreview
20782088

20792089
return $distributionPackage
20802090
}
@@ -2261,20 +2271,44 @@ function New-ManGzip
22612271
}
22622272
}
22632273

2264-
# Returns the macOS Package Identifier
2265-
function Get-MacOSPackageId
2274+
<#
2275+
.SYNOPSIS
2276+
Determines the package identifier and preview status for macOS packages.
2277+
.DESCRIPTION
2278+
This function determines if a package is a preview build based on the version string
2279+
and LTS flag, then returns the appropriate package identifier.
2280+
.PARAMETER Version
2281+
The version string (e.g., "7.6.0-preview.6" or "7.6.0")
2282+
.PARAMETER LTS
2283+
Whether this is an LTS build
2284+
.OUTPUTS
2285+
Hashtable with IsPreview (boolean) and PackageIdentifier (string) properties
2286+
.EXAMPLE
2287+
Get-MacOSPackageIdentifierInfo -Version "7.6.0-preview.6" -LTS:$false
2288+
Returns @{ IsPreview = $true; PackageIdentifier = "com.microsoft.powershell-preview" }
2289+
#>
2290+
function Get-MacOSPackageIdentifierInfo
22662291
{
22672292
param(
2268-
[switch]
2269-
$IsPreview
2293+
[Parameter(Mandatory)]
2294+
[string]$Version,
2295+
2296+
[switch]$LTS
22702297
)
2271-
if ($IsPreview.IsPresent)
2272-
{
2273-
return 'com.microsoft.powershell-preview'
2298+
2299+
$IsPreview = Test-IsPreview -Version $Version -IsLTS:$LTS
2300+
2301+
# Determine package identifier based on preview status
2302+
if ($IsPreview) {
2303+
$PackageIdentifier = 'com.microsoft.powershell-preview'
22742304
}
2275-
else
2276-
{
2277-
return 'com.microsoft.powershell'
2305+
else {
2306+
$PackageIdentifier = 'com.microsoft.powershell'
2307+
}
2308+
2309+
return @{
2310+
IsPreview = $IsPreview
2311+
PackageIdentifier = $PackageIdentifier
22782312
}
22792313
}
22802314

@@ -2288,8 +2322,9 @@ function New-MacOSLauncher
22882322
[switch]$LTS
22892323
)
22902324

2291-
$IsPreview = Test-IsPreview -Version $Version -IsLTS:$LTS
2292-
$packageId = Get-MacOSPackageId -IsPreview:$IsPreview
2325+
$packageInfo = Get-MacOSPackageIdentifierInfo -Version $Version -LTS:$LTS
2326+
$IsPreview = $packageInfo.IsPreview
2327+
$packageId = $packageInfo.PackageIdentifier
22932328

22942329
# Define folder for launcher application.
22952330
$suffix = if ($IsPreview) { "-preview" } elseif ($LTS) { "-lts" }

0 commit comments

Comments
 (0)