Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions test/packaging/packaging.tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

Describe "Packaging Module Functions" {
BeforeAll {
Import-Module $PSScriptRoot/../../build.psm1 -Force
Import-Module $PSScriptRoot/../../tools/packaging/packaging.psm1 -Force
}

Context "Test-IsPreview function" {
It "Should return True for preview versions" {
Test-IsPreview -Version "7.6.0-preview.6" | Should -Be $true
Test-IsPreview -Version "7.5.0-rc.1" | Should -Be $true
}

It "Should return False for stable versions" {
Test-IsPreview -Version "7.6.0" | Should -Be $false
Test-IsPreview -Version "7.5.0" | Should -Be $false
}

It "Should return False for LTS builds regardless of version string" {
Test-IsPreview -Version "7.6.0-preview.6" -IsLTS | Should -Be $false
Test-IsPreview -Version "7.5.0" -IsLTS | Should -Be $false
}
}

Context "Get-MacOSPackageId function" {
It "Should return preview identifier when -IsPreview is specified" {
Get-MacOSPackageId -IsPreview | Should -Be "com.microsoft.powershell-preview"
}

It "Should return stable identifier when -IsPreview is not specified" {
Get-MacOSPackageId | Should -Be "com.microsoft.powershell"
}
}

Context "Get-MacOSPackageIdentifierInfo function (New-MacOSPackage logic)" {
It "Should detect preview builds and return preview identifier" {
$result = Get-MacOSPackageIdentifierInfo -Version "7.6.0-preview.6" -LTS:$false

$result.IsPreview | Should -Be $true
$result.PackageIdentifier | Should -Be "com.microsoft.powershell-preview"
}

It "Should detect stable builds and return stable identifier" {
$result = Get-MacOSPackageIdentifierInfo -Version "7.6.0" -LTS:$false

$result.IsPreview | Should -Be $false
$result.PackageIdentifier | Should -Be "com.microsoft.powershell"
}

It "Should treat LTS builds as stable even with preview version string" {
$result = Get-MacOSPackageIdentifierInfo -Version "7.4.0-preview.1" -LTS:$true

$result.IsPreview | Should -Be $false
$result.PackageIdentifier | Should -Be "com.microsoft.powershell"
}

It "Should NOT use package name for preview detection (bug fix verification)" {
# This test verifies the fix for issue #26673
# The bug was using ($Name -like '*-preview') which always returned false
# because preview builds use Name="powershell" not "powershell-preview"

$Version = "7.6.0-preview.6"
$Name = "powershell" # Preview builds use "powershell" not "powershell-preview"

# The INCORRECT logic (the bug): $Name -like '*-preview'
$incorrectCheck = $Name -like '*-preview'
$incorrectCheck | Should -Be $false -Because "Package name is 'powershell' not 'powershell-preview'"

# The CORRECT logic (the fix): uses version string
$result = Get-MacOSPackageIdentifierInfo -Version $Version -LTS:$false
$result.IsPreview | Should -Be $true -Because "Version string correctly identifies preview"
$result.PackageIdentifier | Should -Be "com.microsoft.powershell-preview"
}
}
}
47 changes: 43 additions & 4 deletions tools/packaging/packaging.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -1371,6 +1371,7 @@ function New-UnixPackage {
AppsFolder = $AppsFolder
HostArchitecture = $HostArchitecture
CurrentLocation = $CurrentLocation
LTS = $LTS
}

try {
Expand Down Expand Up @@ -1984,7 +1985,9 @@ function New-MacOSPackage
[Parameter(Mandatory)]
[string]$HostArchitecture,

[string]$CurrentLocation = (Get-Location)
[string]$CurrentLocation = (Get-Location),

[switch]$LTS
)

Write-Log "Creating macOS package using pkgbuild and productbuild..."
Expand Down Expand Up @@ -2059,8 +2062,10 @@ function New-MacOSPackage
Copy-Item -Path "$AppsFolder/*" -Destination $appsInPkg -Recurse -Force
}

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

if ($PSCmdlet.ShouldProcess("Build component package with pkgbuild")) {
Write-Log "Running pkgbuild to create component package..."
Expand All @@ -2085,7 +2090,7 @@ function New-MacOSPackage
-OutputDirectory $CurrentLocation `
-HostArchitecture $HostArchitecture `
-PackageIdentifier $pkgIdentifier `
-IsPreview:($Name -like '*-preview')
-IsPreview:$IsPreview

return $distributionPackage
}
Expand Down Expand Up @@ -2309,6 +2314,40 @@ function Get-MacOSPackageId
}
}

<#
.SYNOPSIS
Determines the package identifier and preview status for macOS packages.
.DESCRIPTION
This function determines if a package is a preview build based on the version string
and LTS flag, then returns the appropriate package identifier.
.PARAMETER Version
The version string (e.g., "7.6.0-preview.6" or "7.6.0")
.PARAMETER LTS
Whether this is an LTS build
.OUTPUTS
Hashtable with IsPreview (boolean) and PackageIdentifier (string) properties
.EXAMPLE
Get-MacOSPackageIdentifierInfo -Version "7.6.0-preview.6" -LTS:$false
Returns @{ IsPreview = $true; PackageIdentifier = "com.microsoft.powershell-preview" }
#>
function Get-MacOSPackageIdentifierInfo
{
param(
[Parameter(Mandatory)]
[string]$Version,

[switch]$LTS
)

$IsPreview = Test-IsPreview -Version $Version -IsLTS:$LTS
$PackageIdentifier = Get-MacOSPackageId -IsPreview:$IsPreview
Comment thread
TravisEz13 marked this conversation as resolved.
Outdated

return @{
IsPreview = $IsPreview
PackageIdentifier = $PackageIdentifier
}
}

# Dynamically build macOS launcher application.
function New-MacOSLauncher
{
Expand Down