Repository: PowerShell/PowerShell
File: test/packaging/packaging.tests.ps1 (PowerShell)

Code before:
            Test-IsPreview -Version "7.5.0" | Should -Be $false
            Test-IsPreview -Version "7.4.13" | 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.4.0-rc.1" -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" {
            $result = Get-MacOSPackageId -IsPreview
            $result | Should -Be "com.microsoft.powershell-preview"
        }

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

    Context "macOS preview package identifier detection" {
        It "Should correctly detect preview from version string for preview builds" {
            # Simulate the logic used in New-MacOSPackage
            $Version = "7.6.0-preview.6"
            $LTS = $false
            $Name = "powershell"  # Preview builds use "powershell" not "powershell-preview"
            
            $IsPreview = Test-IsPreview -Version $Version -IsLTS:$LTS
            $pkgIdentifier = Get-MacOSPackageId -IsPreview:$IsPreview
            
            $IsPreview | Should -Be $true -Because "Version string contains preview marker"
            $pkgIdentifier | Should -Be "com.microsoft.powershell-preview" -Because "Preview builds should use preview identifier"
        }

        It "Should correctly detect stable from version string for stable builds" {
            # Simulate the logic used in New-MacOSPackage
            $Version = "7.6.0"
            $LTS = $false
            $Name = "powershell"
            
            $IsPreview = Test-IsPreview -Version $Version -IsLTS:$LTS
            $pkgIdentifier = Get-MacOSPackageId -IsPreview:$IsPreview
            
            $IsPreview | Should -Be $false -Because "Version string does not contain preview marker"
            $pkgIdentifier | Should -Be "com.microsoft.powershell" -Because "Stable builds should use stable identifier"
        }

        It "Should treat LTS builds as stable even with preview version string" {

Review comment (suggestion):
@copilot the issue was in `New-MacOSPackage`, but you never tested that.  If the logic there changes these tests won't detect that.

Code after:
        }

        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-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"
        }
    }
}