Skip to content

Commit 5fdc2a0

Browse files
CopilotTravisEz13
andauthored
Fix macOS preview package identifier detection to use version string (#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 bd33c2d commit 5fdc2a0

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
@@ -1371,6 +1371,7 @@ function New-UnixPackage {
13711371
AppsFolder = $AppsFolder
13721372
HostArchitecture = $HostArchitecture
13731373
CurrentLocation = $CurrentLocation
1374+
LTS = $LTS
13741375
}
13751376

13761377
try {
@@ -1515,7 +1516,12 @@ function New-MacOsDistributionPackage
15151516

15161517
# Get package ID if not provided
15171518
if (-not $PackageIdentifier) {
1518-
$PackageIdentifier = Get-MacOSPackageId -IsPreview:$IsPreview.IsPresent
1519+
if ($IsPreview.IsPresent) {
1520+
$PackageIdentifier = 'com.microsoft.powershell-preview'
1521+
}
1522+
else {
1523+
$PackageIdentifier = 'com.microsoft.powershell'
1524+
}
15191525
}
15201526

15211527
# Minimum OS version
@@ -1984,7 +1990,9 @@ function New-MacOSPackage
19841990
[Parameter(Mandatory)]
19851991
[string]$HostArchitecture,
19861992

1987-
[string]$CurrentLocation = (Get-Location)
1993+
[string]$CurrentLocation = (Get-Location),
1994+
1995+
[switch]$LTS
19881996
)
19891997

19901998
Write-Log "Creating macOS package using pkgbuild and productbuild..."
@@ -2059,8 +2067,10 @@ function New-MacOSPackage
20592067
Copy-Item -Path "$AppsFolder/*" -Destination $appsInPkg -Recurse -Force
20602068
}
20612069

2062-
# Build the component package using pkgbuild
2063-
$pkgIdentifier = Get-MacOSPackageId -IsPreview:($Name -like '*-preview')
2070+
# Get package identifier info based on version and LTS flag
2071+
$packageInfo = Get-MacOSPackageIdentifierInfo -Version $Version -LTS:$LTS
2072+
$IsPreview = $packageInfo.IsPreview
2073+
$pkgIdentifier = $packageInfo.PackageIdentifier
20642074

20652075
if ($PSCmdlet.ShouldProcess("Build component package with pkgbuild")) {
20662076
Write-Log "Running pkgbuild to create component package..."
@@ -2085,7 +2095,7 @@ function New-MacOSPackage
20852095
-OutputDirectory $CurrentLocation `
20862096
-HostArchitecture $HostArchitecture `
20872097
-PackageIdentifier $pkgIdentifier `
2088-
-IsPreview:($Name -like '*-preview')
2098+
-IsPreview:$IsPreview
20892099

20902100
return $distributionPackage
20912101
}
@@ -2292,20 +2302,44 @@ function New-ManGzip
22922302
}
22932303
}
22942304

2295-
# Returns the macOS Package Identifier
2296-
function Get-MacOSPackageId
2305+
<#
2306+
.SYNOPSIS
2307+
Determines the package identifier and preview status for macOS packages.
2308+
.DESCRIPTION
2309+
This function determines if a package is a preview build based on the version string
2310+
and LTS flag, then returns the appropriate package identifier.
2311+
.PARAMETER Version
2312+
The version string (e.g., "7.6.0-preview.6" or "7.6.0")
2313+
.PARAMETER LTS
2314+
Whether this is an LTS build
2315+
.OUTPUTS
2316+
Hashtable with IsPreview (boolean) and PackageIdentifier (string) properties
2317+
.EXAMPLE
2318+
Get-MacOSPackageIdentifierInfo -Version "7.6.0-preview.6" -LTS:$false
2319+
Returns @{ IsPreview = $true; PackageIdentifier = "com.microsoft.powershell-preview" }
2320+
#>
2321+
function Get-MacOSPackageIdentifierInfo
22972322
{
22982323
param(
2299-
[switch]
2300-
$IsPreview
2324+
[Parameter(Mandatory)]
2325+
[string]$Version,
2326+
2327+
[switch]$LTS
23012328
)
2302-
if ($IsPreview.IsPresent)
2303-
{
2304-
return 'com.microsoft.powershell-preview'
2329+
2330+
$IsPreview = Test-IsPreview -Version $Version -IsLTS:$LTS
2331+
2332+
# Determine package identifier based on preview status
2333+
if ($IsPreview) {
2334+
$PackageIdentifier = 'com.microsoft.powershell-preview'
23052335
}
2306-
else
2307-
{
2308-
return 'com.microsoft.powershell'
2336+
else {
2337+
$PackageIdentifier = 'com.microsoft.powershell'
2338+
}
2339+
2340+
return @{
2341+
IsPreview = $IsPreview
2342+
PackageIdentifier = $PackageIdentifier
23092343
}
23102344
}
23112345

@@ -2319,8 +2353,9 @@ function New-MacOSLauncher
23192353
[switch]$LTS
23202354
)
23212355

2322-
$IsPreview = Test-IsPreview -Version $Version -IsLTS:$LTS
2323-
$packageId = Get-MacOSPackageId -IsPreview:$IsPreview
2356+
$packageInfo = Get-MacOSPackageIdentifierInfo -Version $Version -LTS:$LTS
2357+
$IsPreview = $packageInfo.IsPreview
2358+
$packageId = $packageInfo.PackageIdentifier
23242359

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

0 commit comments

Comments
 (0)