From 1ee20dda995799cbc6f7c9480d56ffe809a94fe5 Mon Sep 17 00:00:00 2001 From: Ryan Yates Date: Fri, 18 Jul 2025 06:56:36 +0100 Subject: [PATCH 1/5] Properly Expand Cmdlet/Function Aliases - fixes #25616 --- .../engine/TypeTable_Types_Ps1Xml.cs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/System.Management.Automation/engine/TypeTable_Types_Ps1Xml.cs b/src/System.Management.Automation/engine/TypeTable_Types_Ps1Xml.cs index c1a134cdfbf..26e3621c240 100644 --- a/src/System.Management.Automation/engine/TypeTable_Types_Ps1Xml.cs +++ b/src/System.Management.Automation/engine/TypeTable_Types_Ps1Xml.cs @@ -565,9 +565,7 @@ private void Process_Types_Ps1Xml(string filePath, ConcurrentBag errors) typeName, new PSScriptProperty( @"DisplayName", - GetScriptBlock(@"if ($this.Name.IndexOf('-') -lt 0) - { - if ($null -ne $this.ResolvedCommand) + GetScriptBlock(@"if ($null -ne $this.ResolvedCommand) { $this.Name + "" -> "" + $this.ResolvedCommand.Name } @@ -575,11 +573,7 @@ private void Process_Types_Ps1Xml(string filePath, ConcurrentBag errors) { $this.Name + "" -> "" + $this.Definition } - } - else - { - $this.Name - }"), + "), setterScript: null, shouldCloneOnAccess: true), typeMembers, From e0bf73277ed7f024e34c4c95b7c98701740db4ff Mon Sep 17 00:00:00 2001 From: Ryan Yates Date: Fri, 18 Jul 2025 07:23:48 +0100 Subject: [PATCH 2/5] Add test for issue 25616 --- .../Get-Alias.Tests.ps1 | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Alias.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Alias.Tests.ps1 index edccb912ca7..8d9b98a75f4 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Alias.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Alias.Tests.ps1 @@ -155,6 +155,29 @@ Describe "Get-Alias DRT Unit Tests" -Tags "CI" { $returnObject[$i].Definition | Should -Be 'Get-Command' } } + + # Below test was suggested by GitHub Copilot to aid with fixing issue #25616 + It "Get-Alias DisplayName should always show AliasName -> ReferencedCommand for all aliases" { + # Clean up any existing aliases + if (Get-Alias -Name Test-MyAlias -ErrorAction SilentlyContinue) { Remove-Item Alias:Test-MyAlias } + if (Get-Alias -Name tma -ErrorAction SilentlyContinue) { Remove-Item Alias:tma } + + # Create a Verb-Noun style alias "Test-MyAlias" pointing to Get-Command + Set-Alias -Name Test-MyAlias -Value Get-Command + # Create a short alias for the above "tma" -> "Test-MyAlias" + Set-Alias -Name tma -Value Test-MyAlias + + $aliases = Get-Alias Test-MyAlias, tma + + $aliases | ForEach-Object { + # The DisplayName property should always be in the format: Name -> [Definition or ReferencedCommand] + $_.DisplayName | Should -Be "$($_.Name) -> Get-Command" + } + + # Clean up + Remove-Item Alias:Test-MyAlias + Remove-Item Alias:tma +} } Describe "Get-Alias" -Tags "CI" { From 2a3e836202d291fb47fe0e971f9acc3798fbd947 Mon Sep 17 00:00:00 2001 From: Ryan Yates Date: Sat, 19 Jul 2025 18:48:36 +0100 Subject: [PATCH 3/5] address comments from @iSazonov --- .../Microsoft.PowerShell.Utility/Get-Alias.Tests.ps1 | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Alias.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Alias.Tests.ps1 index 8d9b98a75f4..b087cf3c817 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Alias.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Alias.Tests.ps1 @@ -158,17 +158,13 @@ Describe "Get-Alias DRT Unit Tests" -Tags "CI" { # Below test was suggested by GitHub Copilot to aid with fixing issue #25616 It "Get-Alias DisplayName should always show AliasName -> ReferencedCommand for all aliases" { - # Clean up any existing aliases - if (Get-Alias -Name Test-MyAlias -ErrorAction SilentlyContinue) { Remove-Item Alias:Test-MyAlias } - if (Get-Alias -Name tma -ErrorAction SilentlyContinue) { Remove-Item Alias:tma } + # Address comments in PR by @iSazonov + ('Test-MyAlias', 'tma').foreach{Remove-Item Alias:$_ -ErrorAction SilentlyContinue} - # Create a Verb-Noun style alias "Test-MyAlias" pointing to Get-Command Set-Alias -Name Test-MyAlias -Value Get-Command - # Create a short alias for the above "tma" -> "Test-MyAlias" Set-Alias -Name tma -Value Test-MyAlias $aliases = Get-Alias Test-MyAlias, tma - $aliases | ForEach-Object { # The DisplayName property should always be in the format: Name -> [Definition or ReferencedCommand] $_.DisplayName | Should -Be "$($_.Name) -> Get-Command" @@ -177,10 +173,11 @@ Describe "Get-Alias DRT Unit Tests" -Tags "CI" { # Clean up Remove-Item Alias:Test-MyAlias Remove-Item Alias:tma -} + ('Test-MyAlias', 'tma').foreach{Remove-Item Alias:$_ -ErrorAction SilentlyContinue} } Describe "Get-Alias" -Tags "CI" { + } It "Should have a return type of System.Array when gal returns more than one object" { $val1=(Get-Alias a*) $val2=(Get-Alias c*) From 0fdc16c937068e585df0e680185c3c85d31f116c Mon Sep 17 00:00:00 2001 From: Ryan Yates Date: Sat, 19 Jul 2025 19:05:46 +0100 Subject: [PATCH 4/5] test simplification --- .../Get-Alias.Tests.ps1 | 24 ++++++------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Alias.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Alias.Tests.ps1 index b087cf3c817..b62bb90cade 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Alias.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Alias.Tests.ps1 @@ -156,28 +156,18 @@ Describe "Get-Alias DRT Unit Tests" -Tags "CI" { } } - # Below test was suggested by GitHub Copilot to aid with fixing issue #25616 It "Get-Alias DisplayName should always show AliasName -> ReferencedCommand for all aliases" { - # Address comments in PR by @iSazonov - ('Test-MyAlias', 'tma').foreach{Remove-Item Alias:$_ -ErrorAction SilentlyContinue} - - Set-Alias -Name Test-MyAlias -Value Get-Command - Set-Alias -Name tma -Value Test-MyAlias - - $aliases = Get-Alias Test-MyAlias, tma - $aliases | ForEach-Object { - # The DisplayName property should always be in the format: Name -> [Definition or ReferencedCommand] - $_.DisplayName | Should -Be "$($_.Name) -> Get-Command" + Set-Alias -Name Test-MyAlias -Value Get-Command -Force + Set-Alias -Name tma -Value Test-MyAlias -force + $aliases = Get-Alias Test-MyAlias, tma + $aliases | ForEach-Object { + $_.DisplayName | Should -Be "$($_.Name) -> Get-Command" + } + $aliases.Name.foreach{Remove-Item Alias:$_ -ErrorAction SilentlyContinue} } - - # Clean up - Remove-Item Alias:Test-MyAlias - Remove-Item Alias:tma - ('Test-MyAlias', 'tma').foreach{Remove-Item Alias:$_ -ErrorAction SilentlyContinue} } Describe "Get-Alias" -Tags "CI" { - } It "Should have a return type of System.Array when gal returns more than one object" { $val1=(Get-Alias a*) $val2=(Get-Alias c*) From 57864d1b1adbc3edd01d322fd1b7fd243cb87e7b Mon Sep 17 00:00:00 2001 From: Ryan Yates Date: Sat, 19 Jul 2025 23:17:58 +0100 Subject: [PATCH 5/5] test name update --- .../Modules/Microsoft.PowerShell.Utility/Get-Alias.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Alias.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Alias.Tests.ps1 index b62bb90cade..a5b0b039d00 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Alias.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Get-Alias.Tests.ps1 @@ -156,7 +156,7 @@ Describe "Get-Alias DRT Unit Tests" -Tags "CI" { } } - It "Get-Alias DisplayName should always show AliasName -> ReferencedCommand for all aliases" { + It "Get-Alias DisplayName should always show AliasName -> ResolvedCommand for all aliases" { Set-Alias -Name Test-MyAlias -Value Get-Command -Force Set-Alias -Name tma -Value Test-MyAlias -force $aliases = Get-Alias Test-MyAlias, tma