Fix preview build test failures

This commit is contained in:
Justin Chung
2026-05-28 13:07:18 -05:00
parent a8d65d320d
commit 9311457b6a
3 changed files with 51 additions and 30 deletions
@@ -306,19 +306,19 @@ namespace System.Management.Automation
public enum XDG_Type
{
/// <summary> XDG_CONFIG_HOME/powershell </summary>
CONFIG = 0,
CONFIG,
/// <summary> XDG_CACHE_HOME/powershell </summary>
CACHE = 1,
CACHE,
/// <summary> XDG_DATA_HOME/powershell </summary>
DATA = 2,
DATA,
/// <summary> XDG_DATA_HOME/powershell/Modules </summary>
USER_MODULES = 3,
USER_MODULES,
/// <summary> /usr/local/share/powershell/Modules </summary>
SHARED_MODULES = 4,
SHARED_MODULES,
/// <summary> XDG_CONFIG_HOME/powershell </summary>
DEFAULT = 5,
DEFAULT,
/// <summary> /etc/powershell </summary>
SYSTEM_CONFIG = 6,
SYSTEM_CONFIG,
}
/// <summary>
@@ -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
}
}
@@ -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
}
}