Skip to content

Commit 50c8d56

Browse files
CopilotTravisEz13
authored andcommitted
Fix macOS preview package identifier detection to use version string (PowerShell#26690)
Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: TravisEz13 <[email protected]>
1 parent 5168d15 commit 50c8d56

File tree

2 files changed

+119
-17
lines changed

2 files changed

+119
-17
lines changed

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
@@ -1359,6 +1359,7 @@ function New-UnixPackage {
13591359
AppsFolder = $AppsFolder
13601360
HostArchitecture = $HostArchitecture
13611361
CurrentLocation = $CurrentLocation
1362+
LTS = $LTS
13621363
}
13631364

13641365
try {
@@ -1503,7 +1504,12 @@ function New-MacOsDistributionPackage
15031504

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

15091515
# Minimum OS version
@@ -1972,7 +1978,9 @@ function New-MacOSPackage
19721978
[Parameter(Mandatory)]
19731979
[string]$HostArchitecture,
19741980

1975-
[string]$CurrentLocation = (Get-Location)
1981+
[string]$CurrentLocation = (Get-Location),
1982+
1983+
[switch]$LTS
19761984
)
19771985

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

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

20532063
if ($PSCmdlet.ShouldProcess("Build component package with pkgbuild")) {
20542064
Write-Log "Running pkgbuild to create component package..."
@@ -2073,7 +2083,7 @@ function New-MacOSPackage
20732083
-OutputDirectory $CurrentLocation `
20742084
-HostArchitecture $HostArchitecture `
20752085
-PackageIdentifier $pkgIdentifier `
2076-
-IsPreview:($Name -like '*-preview')
2086+
-IsPreview:$IsPreview
20772087

20782088
return $distributionPackage
20792089
}
@@ -2275,20 +2285,44 @@ function New-ManGzip
22752285
}
22762286
}
22772287

2278-
# Returns the macOS Package Identifier
2279-
function Get-MacOSPackageId
2288+
<#
2289+
.SYNOPSIS
2290+
Determines the package identifier and preview status for macOS packages.
2291+
.DESCRIPTION
2292+
This function determines if a package is a preview build based on the version string
2293+
and LTS flag, then returns the appropriate package identifier.
2294+
.PARAMETER Version
2295+
The version string (e.g., "7.6.0-preview.6" or "7.6.0")
2296+
.PARAMETER LTS
2297+
Whether this is an LTS build
2298+
.OUTPUTS
2299+
Hashtable with IsPreview (boolean) and PackageIdentifier (string) properties
2300+
.EXAMPLE
2301+
Get-MacOSPackageIdentifierInfo -Version "7.6.0-preview.6" -LTS:$false
2302+
Returns @{ IsPreview = $true; PackageIdentifier = "com.microsoft.powershell-preview" }
2303+
#>
2304+
function Get-MacOSPackageIdentifierInfo
22802305
{
22812306
param(
2282-
[switch]
2283-
$IsPreview
2307+
[Parameter(Mandatory)]
2308+
[string]$Version,
2309+
2310+
[switch]$LTS
22842311
)
2285-
if ($IsPreview.IsPresent)
2286-
{
2287-
return 'com.microsoft.powershell-preview'
2312+
2313+
$IsPreview = Test-IsPreview -Version $Version -IsLTS:$LTS
2314+
2315+
# Determine package identifier based on preview status
2316+
if ($IsPreview) {
2317+
$PackageIdentifier = 'com.microsoft.powershell-preview'
22882318
}
2289-
else
2290-
{
2291-
return 'com.microsoft.powershell'
2319+
else {
2320+
$PackageIdentifier = 'com.microsoft.powershell'
2321+
}
2322+
2323+
return @{
2324+
IsPreview = $IsPreview
2325+
PackageIdentifier = $PackageIdentifier
22922326
}
22932327
}
22942328

@@ -2302,8 +2336,9 @@ function New-MacOSLauncher
23022336
[switch]$LTS
23032337
)
23042338

2305-
$IsPreview = Test-IsPreview -Version $Version -IsLTS:$LTS
2306-
$packageId = Get-MacOSPackageId -IsPreview:$IsPreview
2339+
$packageInfo = Get-MacOSPackageIdentifierInfo -Version $Version -LTS:$LTS
2340+
$IsPreview = $packageInfo.IsPreview
2341+
$packageId = $packageInfo.PackageIdentifier
23072342

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

0 commit comments

Comments
 (0)