From 9311457b6a5fda9faf1b4759e5f2e11f0c0aa1c2 Mon Sep 17 00:00:00 2001 From: Justin Chung Date: Thu, 28 May 2026 13:07:18 -0500 Subject: [PATCH] Fix preview build test failures --- .../CoreCLR/CorePsPlatform.cs | 14 +++---- ...nableDisable-ExperimentalFeature.Tests.ps1 | 37 ++++++++++++------- .../Get-ExperimentalFeature.Tests.ps1 | 30 ++++++++++----- 3 files changed, 51 insertions(+), 30 deletions(-) diff --git a/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs b/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs index 270e5c925e..8f34683c36 100644 --- a/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs +++ b/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs @@ -306,19 +306,19 @@ namespace System.Management.Automation public enum XDG_Type { /// XDG_CONFIG_HOME/powershell - CONFIG = 0, + CONFIG, /// XDG_CACHE_HOME/powershell - CACHE = 1, + CACHE, /// XDG_DATA_HOME/powershell - DATA = 2, + DATA, /// XDG_DATA_HOME/powershell/Modules - USER_MODULES = 3, + USER_MODULES, /// /usr/local/share/powershell/Modules - SHARED_MODULES = 4, + SHARED_MODULES, /// XDG_CONFIG_HOME/powershell - DEFAULT = 5, + DEFAULT, /// /etc/powershell - SYSTEM_CONFIG = 6, + SYSTEM_CONFIG, } /// diff --git a/test/powershell/engine/ExperimentalFeature/EnableDisable-ExperimentalFeature.Tests.ps1 b/test/powershell/engine/ExperimentalFeature/EnableDisable-ExperimentalFeature.Tests.ps1 index 1a11a668fd..fad2e20748 100644 --- a/test/powershell/engine/ExperimentalFeature/EnableDisable-ExperimentalFeature.Tests.ps1 +++ b/test/powershell/engine/ExperimentalFeature/EnableDisable-ExperimentalFeature.Tests.ps1 @@ -10,18 +10,23 @@ Describe "Enable-ExperimentalFeature and Disable-ExperimentalFeature tests" -tag $systemConfigPath = (Get-PowerShellConfiguration -Scope AllUsers).Path $userConfigPath = (Get-PowerShellConfiguration -Scope CurrentUser).Path - # The legacy $PSHOME config may exist (e.g., preview builds). - # Back it up so tests start clean. Also track it separately because - # writes go to the new platform location, not the legacy path. - $legacyConfigPath = Join-Path $PSHOME "powershell.config.json" - $legacyConfigExists = $false - if (($legacyConfigPath -ne $systemConfigPath) -and (Test-Path $legacyConfigPath)) { - $legacyConfigExists = $true - Move-Item $legacyConfigPath "$legacyConfigPath.backup" -Force -ErrorAction SilentlyContinue + # Enable/Disable-ExperimentalFeature always writes to the new platform + # location via GetConfigFilePathForWrite(), even when the effective read + # path (from Get-PowerShellConfiguration) points to legacy $PSHOME. + # Track both so AfterEach can clean up writes that land at a different path. + if ($IsWindows) { + $systemWritePath = Join-Path $env:ProgramData "Microsoft\PowerShell\powershell.config.json" + } else { + $systemWritePath = "/etc/powershell/powershell.config.json" + } + + $systemWriteDir = Split-Path $systemWritePath + if (!(Test-Path $systemWriteDir)) { + $null = New-Item -ItemType Directory -Path $systemWriteDir -Force -ErrorAction SilentlyContinue } $systemConfigDir = Split-Path $systemConfigPath - if (!(Test-Path $systemConfigDir)) { + if (($systemConfigDir -ne $systemWriteDir) -and !(Test-Path $systemConfigDir)) { $null = New-Item -ItemType Directory -Path $systemConfigDir -Force -ErrorAction SilentlyContinue } @@ -30,6 +35,12 @@ Describe "Enable-ExperimentalFeature and Disable-ExperimentalFeature tests" -tag $null = New-Item -ItemType Directory -Path $userConfigDir -Force -ErrorAction SilentlyContinue } + $systemWriteExists = $false + if (($systemWritePath -ne $systemConfigPath) -and (Test-Path $systemWritePath)) { + $systemWriteExists = $true + Move-Item $systemWritePath "$systemWritePath.backup" -Force -ErrorAction SilentlyContinue + } + $systemConfigExists = $false if (Test-Path $systemConfigPath) { $systemConfigExists = $true @@ -48,8 +59,8 @@ Describe "Enable-ExperimentalFeature and Disable-ExperimentalFeature tests" -tag } AfterAll { - if ($legacyConfigExists) { - Move-Item "$legacyConfigPath.backup" $legacyConfigPath -Force -ErrorAction SilentlyContinue + if ($systemWriteExists) { + Move-Item "$systemWritePath.backup" $systemWritePath -Force -ErrorAction SilentlyContinue } if ($systemConfigExists) { @@ -66,8 +77,8 @@ Describe "Enable-ExperimentalFeature and Disable-ExperimentalFeature tests" -tag AfterEach { Remove-Item $systemConfigPath -Force -ErrorAction SilentlyContinue Remove-Item $userConfigPath -Force -ErrorAction SilentlyContinue - if ($legacyConfigPath -ne $systemConfigPath) { - Remove-Item $legacyConfigPath -Force -ErrorAction SilentlyContinue + if ($systemWritePath -ne $systemConfigPath) { + Remove-Item $systemWritePath -Force -ErrorAction SilentlyContinue } } diff --git a/test/powershell/engine/ExperimentalFeature/Get-ExperimentalFeature.Tests.ps1 b/test/powershell/engine/ExperimentalFeature/Get-ExperimentalFeature.Tests.ps1 index dce719c896..fd441e3ae3 100644 --- a/test/powershell/engine/ExperimentalFeature/Get-ExperimentalFeature.Tests.ps1 +++ b/test/powershell/engine/ExperimentalFeature/Get-ExperimentalFeature.Tests.ps1 @@ -10,15 +10,19 @@ Describe "Get-ExperimentalFeature Tests" -tags "Feature","RequireAdminOnWindows" $systemConfigPath = (Get-PowerShellConfiguration -Scope AllUsers).Path $userConfigPath = (Get-PowerShellConfiguration -Scope CurrentUser).Path - $legacyConfigPath = Join-Path $PSHOME "powershell.config.json" - $legacyConfigExists = $false - if (($legacyConfigPath -ne $systemConfigPath) -and (Test-Path $legacyConfigPath)) { - $legacyConfigExists = $true - Move-Item $legacyConfigPath "$legacyConfigPath.backup" -Force -ErrorAction SilentlyContinue + if ($IsWindows) { + $systemWritePath = Join-Path $env:ProgramData "Microsoft\PowerShell\powershell.config.json" + } else { + $systemWritePath = "/etc/powershell/powershell.config.json" + } + + $systemWriteDir = Split-Path $systemWritePath + if (!(Test-Path $systemWriteDir)) { + $null = New-Item -ItemType Directory -Path $systemWriteDir -Force -ErrorAction SilentlyContinue } $systemConfigDir = Split-Path $systemConfigPath - if (!(Test-Path $systemConfigDir)) { + if (($systemConfigDir -ne $systemWriteDir) -and !(Test-Path $systemConfigDir)) { $null = New-Item -ItemType Directory -Path $systemConfigDir -Force -ErrorAction SilentlyContinue } @@ -27,6 +31,12 @@ Describe "Get-ExperimentalFeature Tests" -tags "Feature","RequireAdminOnWindows" $null = New-Item -ItemType Directory -Path $userConfigDir -Force -ErrorAction SilentlyContinue } + $systemWriteExists = $false + if (($systemWritePath -ne $systemConfigPath) -and (Test-Path $systemWritePath)) { + $systemWriteExists = $true + Move-Item $systemWritePath "$systemWritePath.backup" -Force -ErrorAction SilentlyContinue + } + $systemConfigExists = $false if (Test-Path $systemConfigPath) { $systemConfigExists = $true @@ -46,8 +56,8 @@ Describe "Get-ExperimentalFeature Tests" -tags "Feature","RequireAdminOnWindows" } AfterAll { - if ($legacyConfigExists) { - Move-Item "$legacyConfigPath.backup" $legacyConfigPath -Force -ErrorAction SilentlyContinue + if ($systemWriteExists) { + Move-Item "$systemWritePath.backup" $systemWritePath -Force -ErrorAction SilentlyContinue } if ($systemConfigExists -and (Test-CanWriteToSystemConfigDir)) { @@ -67,8 +77,8 @@ Describe "Get-ExperimentalFeature Tests" -tags "Feature","RequireAdminOnWindows" } Remove-Item $userConfigPath -Force -ErrorAction SilentlyContinue - if ($legacyConfigPath -ne $systemConfigPath) { - Remove-Item $legacyConfigPath -Force -ErrorAction SilentlyContinue + if ($systemWritePath -ne $systemConfigPath) { + Remove-Item $systemWritePath -Force -ErrorAction SilentlyContinue } }