From b1e597e0bef2ee8375667e8e427e3d8302247a6b Mon Sep 17 00:00:00 2001 From: AJ Alon Date: Thu, 25 Jun 2026 16:46:19 -0700 Subject: [PATCH 01/12] test(completion): ensure powershell completions install is actually successful --- smoke_test_scripts/windows/run_smoke_test.ps1 | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/smoke_test_scripts/windows/run_smoke_test.ps1 b/smoke_test_scripts/windows/run_smoke_test.ps1 index 4b2580d4..c04a13a8 100755 --- a/smoke_test_scripts/windows/run_smoke_test.ps1 +++ b/smoke_test_scripts/windows/run_smoke_test.ps1 @@ -150,6 +150,54 @@ if (Test-Path $completion_file) { } Write-End +# Test completion install under a fresh-machine execution policy. +# This intentionally exposes the bug: dr self completion install writes a +# profile that PowerShell refuses to load when the default Restricted policy +# is in effect. The CLI does not yet fix the policy, so the assertion below +# expects the policy to remain Restricted after install. +Write-Delimiter "Testing dr self completion install (Restricted execution policy)" + +$originalPolicy = Get-ExecutionPolicy -Scope CurrentUser + +# Simulate a fresh Windows machine where the default execution policy is Restricted. +Set-ExecutionPolicy Restricted -Scope CurrentUser -Force + +# Run the completion installer. This is the exact user path that is broken. +dr self completion install powershell --yes +if ($LASTEXITCODE -ne 0) { + Set-ExecutionPolicy $originalPolicy -Scope CurrentUser -Force -ErrorAction SilentlyContinue + Write-ErrorMsg "dr self completion install powershell --yes failed" +} + +# Verify the completion profile was written. +$profilePath = "$env:USERPROFILE\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1" +if (-not (Test-Path $profilePath)) { + $profilePath = "$env:USERPROFILE\Documents\PowerShell\Microsoft.PowerShell_profile.ps1" +} +if (-not (Test-Path $profilePath)) { + Set-ExecutionPolicy $originalPolicy -Scope CurrentUser -Force -ErrorAction SilentlyContinue + Write-ErrorMsg "Assertion failed: PowerShell profile was not created" +} +$profileContent = Get-Content $profilePath -Raw +if ($profileContent -notmatch "dr completion powershell") { + Set-ExecutionPolicy $originalPolicy -Scope CurrentUser -Force -ErrorAction SilentlyContinue + Write-ErrorMsg "Assertion failed: profile does not contain completion block" +} +Write-SuccessMsg "Assertion passed: profile written and contains completion block" + +# Verify the bug: the installer does NOT change the execution policy, so a +# fresh machine remains Restricted and the profile will not load next session. +$policy = Get-ExecutionPolicy -Scope CurrentUser +if ($policy -ne "Restricted") { + Set-ExecutionPolicy $originalPolicy -Scope CurrentUser -Force -ErrorAction SilentlyContinue + Write-ErrorMsg "Assertion failed: expected execution policy to remain Restricted (proving the bug), but it is '$policy'" +} +Write-SuccessMsg "Assertion passed: execution policy remains '$policy' after install, confirming the bug" + +# Restore the original policy so the rest of the smoke test is not affected. +Set-ExecutionPolicy $originalPolicy -Scope CurrentUser -Force -ErrorAction SilentlyContinue +Write-End + # Test dr run command Write-Delimiter "Testing dr run command" dr run From 7401c730d6745396656bc2adf055ab32a395a953 Mon Sep 17 00:00:00 2001 From: AJ Alon Date: Thu, 25 Jun 2026 17:01:33 -0700 Subject: [PATCH 02/12] test(completion): just check warnings --- smoke_test_scripts/windows/run_smoke_test.ps1 | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/smoke_test_scripts/windows/run_smoke_test.ps1 b/smoke_test_scripts/windows/run_smoke_test.ps1 index c04a13a8..fae703e5 100755 --- a/smoke_test_scripts/windows/run_smoke_test.ps1 +++ b/smoke_test_scripts/windows/run_smoke_test.ps1 @@ -151,10 +151,9 @@ if (Test-Path $completion_file) { Write-End # Test completion install under a fresh-machine execution policy. -# This intentionally exposes the bug: dr self completion install writes a -# profile that PowerShell refuses to load when the default Restricted policy -# is in effect. The CLI does not yet fix the policy, so the assertion below -# expects the policy to remain Restricted after install. +# The installer should warn the user that the profile will not load under the +# default Restricted policy and print the exact command to fix it, but it should +# not modify the policy itself. Write-Delimiter "Testing dr self completion install (Restricted execution policy)" $originalPolicy = Get-ExecutionPolicy -Scope CurrentUser @@ -162,12 +161,20 @@ $originalPolicy = Get-ExecutionPolicy -Scope CurrentUser # Simulate a fresh Windows machine where the default execution policy is Restricted. Set-ExecutionPolicy Restricted -Scope CurrentUser -Force -# Run the completion installer. This is the exact user path that is broken. -dr self completion install powershell --yes -if ($LASTEXITCODE -ne 0) { +# Run the completion installer and capture its output so we can verify the warning. +$installOutput = (dr self completion install powershell --yes 2>&1 | Out-String) +$installExitCode = $LASTEXITCODE +if ($installExitCode -ne 0) { + Set-ExecutionPolicy $originalPolicy -Scope CurrentUser -Force -ErrorAction SilentlyContinue + Write-ErrorMsg "dr self completion install powershell --yes failed with exit code $installExitCode" +} + +# Verify the installer warned the user with the exact fix command. +if ($installOutput -notmatch "Set-ExecutionPolicy RemoteSigned -Scope CurrentUser") { Set-ExecutionPolicy $originalPolicy -Scope CurrentUser -Force -ErrorAction SilentlyContinue - Write-ErrorMsg "dr self completion install powershell --yes failed" + Write-ErrorMsg "Assertion failed: installer did not warn user with the execution policy fix command" } +Write-SuccessMsg "Assertion passed: installer warned about Restricted execution policy" # Verify the completion profile was written. $profilePath = "$env:USERPROFILE\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1" @@ -185,14 +192,13 @@ if ($profileContent -notmatch "dr completion powershell") { } Write-SuccessMsg "Assertion passed: profile written and contains completion block" -# Verify the bug: the installer does NOT change the execution policy, so a -# fresh machine remains Restricted and the profile will not load next session. +# Verify the policy remains unchanged (warn-only behavior; the fix is left to the user). $policy = Get-ExecutionPolicy -Scope CurrentUser if ($policy -ne "Restricted") { Set-ExecutionPolicy $originalPolicy -Scope CurrentUser -Force -ErrorAction SilentlyContinue - Write-ErrorMsg "Assertion failed: expected execution policy to remain Restricted (proving the bug), but it is '$policy'" + Write-ErrorMsg "Assertion failed: expected execution policy to remain Restricted (warn-only), but it is '$policy'" } -Write-SuccessMsg "Assertion passed: execution policy remains '$policy' after install, confirming the bug" +Write-SuccessMsg "Assertion passed: execution policy remains '$policy' (installer only warned)" # Restore the original policy so the rest of the smoke test is not affected. Set-ExecutionPolicy $originalPolicy -Scope CurrentUser -Force -ErrorAction SilentlyContinue From 56f24e12479016519f2b051bb194100807fcb4b5 Mon Sep 17 00:00:00 2001 From: AJ Alon Date: Thu, 25 Jun 2026 17:08:07 -0700 Subject: [PATCH 03/12] test(completion): also exercise permissive scenario --- smoke_test_scripts/windows/run_smoke_test.ps1 | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/smoke_test_scripts/windows/run_smoke_test.ps1 b/smoke_test_scripts/windows/run_smoke_test.ps1 index fae703e5..70e1065b 100755 --- a/smoke_test_scripts/windows/run_smoke_test.ps1 +++ b/smoke_test_scripts/windows/run_smoke_test.ps1 @@ -204,6 +204,58 @@ Write-SuccessMsg "Assertion passed: execution policy remains '$policy' (installe Set-ExecutionPolicy $originalPolicy -Scope CurrentUser -Force -ErrorAction SilentlyContinue Write-End +# Test completion install under a permissive execution policy. +# The installer should complete silently without warning the user. +Write-Delimiter "Testing dr self completion install (permissive execution policy)" + +$originalPolicyPermissive = Get-ExecutionPolicy -Scope CurrentUser + +# Simulate a machine where the user has already relaxed the execution policy. +Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Force + +# Run the completion installer and capture its output. +$installOutputPermissive = (dr self completion install powershell --yes 2>&1 | Out-String) +$installExitCodePermissive = $LASTEXITCODE +if ($installExitCodePermissive -ne 0) { + Set-ExecutionPolicy $originalPolicyPermissive -Scope CurrentUser -Force -ErrorAction SilentlyContinue + Write-ErrorMsg "dr self completion install powershell --yes failed with exit code $installExitCodePermissive" +} + +# Verify the installer did NOT warn about execution policy. +if ($installOutputPermissive -match "Set-ExecutionPolicy RemoteSigned -Scope CurrentUser") { + Set-ExecutionPolicy $originalPolicyPermissive -Scope CurrentUser -Force -ErrorAction SilentlyContinue + Write-ErrorMsg "Assertion failed: installer warned about execution policy when policy was already permissive" +} +Write-SuccessMsg "Assertion passed: installer did not warn when execution policy is permissive" + +# Verify the completion profile exists and contains the completion block. +$profilePathPermissive = "$env:USERPROFILE\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1" +if (-not (Test-Path $profilePathPermissive)) { + $profilePathPermissive = "$env:USERPROFILE\Documents\PowerShell\Microsoft.PowerShell_profile.ps1" +} +if (-not (Test-Path $profilePathPermissive)) { + Set-ExecutionPolicy $originalPolicyPermissive -Scope CurrentUser -Force -ErrorAction SilentlyContinue + Write-ErrorMsg "Assertion failed: PowerShell profile was not found" +} +$profileContentPermissive = Get-Content $profilePathPermissive -Raw +if ($profileContentPermissive -notmatch "dr completion powershell") { + Set-ExecutionPolicy $originalPolicyPermissive -Scope CurrentUser -Force -ErrorAction SilentlyContinue + Write-ErrorMsg "Assertion failed: profile does not contain completion block" +} +Write-SuccessMsg "Assertion passed: profile contains completion block" + +# Verify the policy remains unchanged. +$policyPermissive = Get-ExecutionPolicy -Scope CurrentUser +if ($policyPermissive -ne "RemoteSigned") { + Set-ExecutionPolicy $originalPolicyPermissive -Scope CurrentUser -Force -ErrorAction SilentlyContinue + Write-ErrorMsg "Assertion failed: expected execution policy to remain RemoteSigned, but it is '$policyPermissive'" +} +Write-SuccessMsg "Assertion passed: execution policy remains '$policyPermissive'" + +# Restore the original policy. +Set-ExecutionPolicy $originalPolicyPermissive -Scope CurrentUser -Force -ErrorAction SilentlyContinue +Write-End + # Test dr run command Write-Delimiter "Testing dr run command" dr run From 0402525f9071cbb296cefaab718c5bb50ede3687 Mon Sep 17 00:00:00 2001 From: AJ Alon Date: Thu, 25 Jun 2026 17:10:50 -0700 Subject: [PATCH 04/12] test(completion): refactor --- smoke_test_scripts/windows/run_smoke_test.ps1 | 176 ++++++++---------- 1 file changed, 82 insertions(+), 94 deletions(-) diff --git a/smoke_test_scripts/windows/run_smoke_test.ps1 b/smoke_test_scripts/windows/run_smoke_test.ps1 index 70e1065b..1201aabe 100755 --- a/smoke_test_scripts/windows/run_smoke_test.ps1 +++ b/smoke_test_scripts/windows/run_smoke_test.ps1 @@ -51,6 +51,86 @@ function Test-URLAccessible { } } +function Get-DRCompletionProfilePath { + # Match the order used by the Go installer: prefer PowerShell Core if the + # directory exists, otherwise fall back to Windows PowerShell. + $documentsPath = "$env:USERPROFILE\Documents" + $psCoreDir = Join-Path $documentsPath "PowerShell" + $windowsPsDir = Join-Path $documentsPath "WindowsPowerShell" + + if (Test-Path $psCoreDir) { + return Join-Path $psCoreDir "Microsoft.PowerShell_profile.ps1" + } + return Join-Path $windowsPsDir "Microsoft.PowerShell_profile.ps1" +} + +function Test-DRCompletionProfile { + param( + [string]$ProfilePath, + [string]$OriginalPolicy + ) + + if (-not (Test-Path $ProfilePath)) { + Set-ExecutionPolicy $OriginalPolicy -Scope CurrentUser -Force -ErrorAction SilentlyContinue + Write-ErrorMsg "Assertion failed: PowerShell profile was not found at $ProfilePath" + } + + $profileContent = Get-Content $ProfilePath -Raw + if ($profileContent -notmatch "dr completion powershell") { + Set-ExecutionPolicy $OriginalPolicy -Scope CurrentUser -Force -ErrorAction SilentlyContinue + Write-ErrorMsg "Assertion failed: profile does not contain completion block" + } + + Write-SuccessMsg "Assertion passed: profile contains completion block" +} + +function Test-DRCompletionInstallWithExecutionPolicy { + param( + [string]$TestName, + [string]$Policy, + [string]$ExpectedPolicy, + [bool]$ExpectWarning + ) + + $originalPolicy = Get-ExecutionPolicy -Scope CurrentUser + Set-ExecutionPolicy $Policy -Scope CurrentUser -Force + + $installOutput = (dr self completion install powershell --yes 2>&1 | Out-String) + $installExitCode = $LASTEXITCODE + if ($installExitCode -ne 0) { + Set-ExecutionPolicy $originalPolicy -Scope CurrentUser -Force -ErrorAction SilentlyContinue + Write-ErrorMsg "dr self completion install powershell --yes failed with exit code $installExitCode" + } + + $fixCommand = "Set-ExecutionPolicy RemoteSigned -Scope CurrentUser" + $hasWarning = $installOutput -match $fixCommand + + if ($ExpectWarning -and -not $hasWarning) { + Set-ExecutionPolicy $originalPolicy -Scope CurrentUser -Force -ErrorAction SilentlyContinue + Write-ErrorMsg "Assertion failed [$TestName]: installer did not warn user with the execution policy fix command" + } + + if (-not $ExpectWarning -and $hasWarning) { + Set-ExecutionPolicy $originalPolicy -Scope CurrentUser -Force -ErrorAction SilentlyContinue + Write-ErrorMsg "Assertion failed [$TestName]: installer warned about execution policy when policy was already permissive" + } + + Write-SuccessMsg "Assertion passed [$TestName]: warning behavior correct" + + $profilePath = Get-DRCompletionProfilePath + Test-DRCompletionProfile -ProfilePath $profilePath -OriginalPolicy $originalPolicy + + $actualPolicy = Get-ExecutionPolicy -Scope CurrentUser + if ($actualPolicy -ne $ExpectedPolicy) { + Set-ExecutionPolicy $originalPolicy -Scope CurrentUser -Force -ErrorAction SilentlyContinue + Write-ErrorMsg "Assertion failed [$TestName]: expected execution policy to be $ExpectedPolicy, but it is '$actualPolicy'" + } + + Write-SuccessMsg "Assertion passed [$TestName]: execution policy remains '$actualPolicy'" + + Set-ExecutionPolicy $originalPolicy -Scope CurrentUser -Force -ErrorAction SilentlyContinue +} + # Main execution Write-Host 'Running smoke tests for Windows...' @@ -155,105 +235,13 @@ Write-End # default Restricted policy and print the exact command to fix it, but it should # not modify the policy itself. Write-Delimiter "Testing dr self completion install (Restricted execution policy)" - -$originalPolicy = Get-ExecutionPolicy -Scope CurrentUser - -# Simulate a fresh Windows machine where the default execution policy is Restricted. -Set-ExecutionPolicy Restricted -Scope CurrentUser -Force - -# Run the completion installer and capture its output so we can verify the warning. -$installOutput = (dr self completion install powershell --yes 2>&1 | Out-String) -$installExitCode = $LASTEXITCODE -if ($installExitCode -ne 0) { - Set-ExecutionPolicy $originalPolicy -Scope CurrentUser -Force -ErrorAction SilentlyContinue - Write-ErrorMsg "dr self completion install powershell --yes failed with exit code $installExitCode" -} - -# Verify the installer warned the user with the exact fix command. -if ($installOutput -notmatch "Set-ExecutionPolicy RemoteSigned -Scope CurrentUser") { - Set-ExecutionPolicy $originalPolicy -Scope CurrentUser -Force -ErrorAction SilentlyContinue - Write-ErrorMsg "Assertion failed: installer did not warn user with the execution policy fix command" -} -Write-SuccessMsg "Assertion passed: installer warned about Restricted execution policy" - -# Verify the completion profile was written. -$profilePath = "$env:USERPROFILE\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1" -if (-not (Test-Path $profilePath)) { - $profilePath = "$env:USERPROFILE\Documents\PowerShell\Microsoft.PowerShell_profile.ps1" -} -if (-not (Test-Path $profilePath)) { - Set-ExecutionPolicy $originalPolicy -Scope CurrentUser -Force -ErrorAction SilentlyContinue - Write-ErrorMsg "Assertion failed: PowerShell profile was not created" -} -$profileContent = Get-Content $profilePath -Raw -if ($profileContent -notmatch "dr completion powershell") { - Set-ExecutionPolicy $originalPolicy -Scope CurrentUser -Force -ErrorAction SilentlyContinue - Write-ErrorMsg "Assertion failed: profile does not contain completion block" -} -Write-SuccessMsg "Assertion passed: profile written and contains completion block" - -# Verify the policy remains unchanged (warn-only behavior; the fix is left to the user). -$policy = Get-ExecutionPolicy -Scope CurrentUser -if ($policy -ne "Restricted") { - Set-ExecutionPolicy $originalPolicy -Scope CurrentUser -Force -ErrorAction SilentlyContinue - Write-ErrorMsg "Assertion failed: expected execution policy to remain Restricted (warn-only), but it is '$policy'" -} -Write-SuccessMsg "Assertion passed: execution policy remains '$policy' (installer only warned)" - -# Restore the original policy so the rest of the smoke test is not affected. -Set-ExecutionPolicy $originalPolicy -Scope CurrentUser -Force -ErrorAction SilentlyContinue +Test-DRCompletionInstallWithExecutionPolicy -TestName "Restricted" -Policy "Restricted" -ExpectedPolicy "Restricted" -ExpectWarning $true Write-End # Test completion install under a permissive execution policy. # The installer should complete silently without warning the user. Write-Delimiter "Testing dr self completion install (permissive execution policy)" - -$originalPolicyPermissive = Get-ExecutionPolicy -Scope CurrentUser - -# Simulate a machine where the user has already relaxed the execution policy. -Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Force - -# Run the completion installer and capture its output. -$installOutputPermissive = (dr self completion install powershell --yes 2>&1 | Out-String) -$installExitCodePermissive = $LASTEXITCODE -if ($installExitCodePermissive -ne 0) { - Set-ExecutionPolicy $originalPolicyPermissive -Scope CurrentUser -Force -ErrorAction SilentlyContinue - Write-ErrorMsg "dr self completion install powershell --yes failed with exit code $installExitCodePermissive" -} - -# Verify the installer did NOT warn about execution policy. -if ($installOutputPermissive -match "Set-ExecutionPolicy RemoteSigned -Scope CurrentUser") { - Set-ExecutionPolicy $originalPolicyPermissive -Scope CurrentUser -Force -ErrorAction SilentlyContinue - Write-ErrorMsg "Assertion failed: installer warned about execution policy when policy was already permissive" -} -Write-SuccessMsg "Assertion passed: installer did not warn when execution policy is permissive" - -# Verify the completion profile exists and contains the completion block. -$profilePathPermissive = "$env:USERPROFILE\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1" -if (-not (Test-Path $profilePathPermissive)) { - $profilePathPermissive = "$env:USERPROFILE\Documents\PowerShell\Microsoft.PowerShell_profile.ps1" -} -if (-not (Test-Path $profilePathPermissive)) { - Set-ExecutionPolicy $originalPolicyPermissive -Scope CurrentUser -Force -ErrorAction SilentlyContinue - Write-ErrorMsg "Assertion failed: PowerShell profile was not found" -} -$profileContentPermissive = Get-Content $profilePathPermissive -Raw -if ($profileContentPermissive -notmatch "dr completion powershell") { - Set-ExecutionPolicy $originalPolicyPermissive -Scope CurrentUser -Force -ErrorAction SilentlyContinue - Write-ErrorMsg "Assertion failed: profile does not contain completion block" -} -Write-SuccessMsg "Assertion passed: profile contains completion block" - -# Verify the policy remains unchanged. -$policyPermissive = Get-ExecutionPolicy -Scope CurrentUser -if ($policyPermissive -ne "RemoteSigned") { - Set-ExecutionPolicy $originalPolicyPermissive -Scope CurrentUser -Force -ErrorAction SilentlyContinue - Write-ErrorMsg "Assertion failed: expected execution policy to remain RemoteSigned, but it is '$policyPermissive'" -} -Write-SuccessMsg "Assertion passed: execution policy remains '$policyPermissive'" - -# Restore the original policy. -Set-ExecutionPolicy $originalPolicyPermissive -Scope CurrentUser -Force -ErrorAction SilentlyContinue +Test-DRCompletionInstallWithExecutionPolicy -TestName "RemoteSigned" -Policy "RemoteSigned" -ExpectedPolicy "RemoteSigned" -ExpectWarning $false Write-End # Test dr run command From 28a1b951154d37e425bf123a51f4e69b25a217e8 Mon Sep 17 00:00:00 2001 From: AJ Alon Date: Thu, 25 Jun 2026 17:19:24 -0700 Subject: [PATCH 05/12] test(completion): inline single-use profile helpers Get-DRCompletionProfilePath and Test-DRCompletionProfile were each called from exactly one site. Inline them into Test-DRCompletionInstallWithExecutionPolicy to co-locate the logic with its only consumer. Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com> --- smoke_test_scripts/windows/run_smoke_test.ps1 | 59 ++++++++----------- 1 file changed, 24 insertions(+), 35 deletions(-) diff --git a/smoke_test_scripts/windows/run_smoke_test.ps1 b/smoke_test_scripts/windows/run_smoke_test.ps1 index 1201aabe..22d01360 100755 --- a/smoke_test_scripts/windows/run_smoke_test.ps1 +++ b/smoke_test_scripts/windows/run_smoke_test.ps1 @@ -51,39 +51,6 @@ function Test-URLAccessible { } } -function Get-DRCompletionProfilePath { - # Match the order used by the Go installer: prefer PowerShell Core if the - # directory exists, otherwise fall back to Windows PowerShell. - $documentsPath = "$env:USERPROFILE\Documents" - $psCoreDir = Join-Path $documentsPath "PowerShell" - $windowsPsDir = Join-Path $documentsPath "WindowsPowerShell" - - if (Test-Path $psCoreDir) { - return Join-Path $psCoreDir "Microsoft.PowerShell_profile.ps1" - } - return Join-Path $windowsPsDir "Microsoft.PowerShell_profile.ps1" -} - -function Test-DRCompletionProfile { - param( - [string]$ProfilePath, - [string]$OriginalPolicy - ) - - if (-not (Test-Path $ProfilePath)) { - Set-ExecutionPolicy $OriginalPolicy -Scope CurrentUser -Force -ErrorAction SilentlyContinue - Write-ErrorMsg "Assertion failed: PowerShell profile was not found at $ProfilePath" - } - - $profileContent = Get-Content $ProfilePath -Raw - if ($profileContent -notmatch "dr completion powershell") { - Set-ExecutionPolicy $OriginalPolicy -Scope CurrentUser -Force -ErrorAction SilentlyContinue - Write-ErrorMsg "Assertion failed: profile does not contain completion block" - } - - Write-SuccessMsg "Assertion passed: profile contains completion block" -} - function Test-DRCompletionInstallWithExecutionPolicy { param( [string]$TestName, @@ -117,8 +84,30 @@ function Test-DRCompletionInstallWithExecutionPolicy { Write-SuccessMsg "Assertion passed [$TestName]: warning behavior correct" - $profilePath = Get-DRCompletionProfilePath - Test-DRCompletionProfile -ProfilePath $profilePath -OriginalPolicy $originalPolicy + # Match the order used by the Go installer: prefer PowerShell Core if the + # directory exists, otherwise fall back to Windows PowerShell. + $documentsPath = "$env:USERPROFILE\Documents" + $psCoreDir = Join-Path $documentsPath "PowerShell" + $windowsPsDir = Join-Path $documentsPath "WindowsPowerShell" + + if (Test-Path $psCoreDir) { + $profilePath = Join-Path $psCoreDir "Microsoft.PowerShell_profile.ps1" + } else { + $profilePath = Join-Path $windowsPsDir "Microsoft.PowerShell_profile.ps1" + } + + if (-not (Test-Path $profilePath)) { + Set-ExecutionPolicy $originalPolicy -Scope CurrentUser -Force -ErrorAction SilentlyContinue + Write-ErrorMsg "Assertion failed: PowerShell profile was not found at $profilePath" + } + + $profileContent = Get-Content $profilePath -Raw + if ($profileContent -notmatch "dr completion powershell") { + Set-ExecutionPolicy $originalPolicy -Scope CurrentUser -Force -ErrorAction SilentlyContinue + Write-ErrorMsg "Assertion failed: profile does not contain completion block" + } + + Write-SuccessMsg "Assertion passed: profile contains completion block" $actualPolicy = Get-ExecutionPolicy -Scope CurrentUser if ($actualPolicy -ne $ExpectedPolicy) { From a036bd7ff9be5e855bd7d9c01d340d300e4cfa60 Mon Sep 17 00:00:00 2001 From: AJ Alon Date: Thu, 25 Jun 2026 17:24:09 -0700 Subject: [PATCH 06/12] test(completion): document stuff --- smoke_test_scripts/windows/run_smoke_test.ps1 | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/smoke_test_scripts/windows/run_smoke_test.ps1 b/smoke_test_scripts/windows/run_smoke_test.ps1 index 22d01360..96661185 100755 --- a/smoke_test_scripts/windows/run_smoke_test.ps1 +++ b/smoke_test_scripts/windows/run_smoke_test.ps1 @@ -25,6 +25,7 @@ function Write-InfoMsg { Write-Host $Message } +# Prints a section header banner centered around the given message. function Write-Delimiter { param([string]$Message) Write-Host "" @@ -35,6 +36,7 @@ function Write-Delimiter { Write-Host ("=" * 20) } +# Prints a closing END banner to delimit test sections. function Write-End { Write-Host ("=" * 20) -NoNewline Write-Host " END " -NoNewline @@ -51,6 +53,7 @@ function Test-URLAccessible { } } +# Installs PowerShell completions under a given execution policy and asserts warning behavior, profile contents, and policy preservation. function Test-DRCompletionInstallWithExecutionPolicy { param( [string]$TestName, @@ -59,9 +62,11 @@ function Test-DRCompletionInstallWithExecutionPolicy { [bool]$ExpectWarning ) + # Save the current policy so it can be restored after the test, then apply the policy under test. $originalPolicy = Get-ExecutionPolicy -Scope CurrentUser Set-ExecutionPolicy $Policy -Scope CurrentUser -Force + # Run the installer and fail fast if it exits non-zero. $installOutput = (dr self completion install powershell --yes 2>&1 | Out-String) $installExitCode = $LASTEXITCODE if ($installExitCode -ne 0) { @@ -69,6 +74,7 @@ function Test-DRCompletionInstallWithExecutionPolicy { Write-ErrorMsg "dr self completion install powershell --yes failed with exit code $installExitCode" } + # Assert the installer warned (or did not warn) about the execution policy fix command. $fixCommand = "Set-ExecutionPolicy RemoteSigned -Scope CurrentUser" $hasWarning = $installOutput -match $fixCommand @@ -84,8 +90,7 @@ function Test-DRCompletionInstallWithExecutionPolicy { Write-SuccessMsg "Assertion passed [$TestName]: warning behavior correct" - # Match the order used by the Go installer: prefer PowerShell Core if the - # directory exists, otherwise fall back to Windows PowerShell. + # Resolve the PowerShell profile path, preferring PowerShell Core over Windows PowerShell (matches the Go installer). $documentsPath = "$env:USERPROFILE\Documents" $psCoreDir = Join-Path $documentsPath "PowerShell" $windowsPsDir = Join-Path $documentsPath "WindowsPowerShell" @@ -96,6 +101,7 @@ function Test-DRCompletionInstallWithExecutionPolicy { $profilePath = Join-Path $windowsPsDir "Microsoft.PowerShell_profile.ps1" } + # Assert the profile exists and contains the dr completion block. if (-not (Test-Path $profilePath)) { Set-ExecutionPolicy $originalPolicy -Scope CurrentUser -Force -ErrorAction SilentlyContinue Write-ErrorMsg "Assertion failed: PowerShell profile was not found at $profilePath" @@ -109,6 +115,7 @@ function Test-DRCompletionInstallWithExecutionPolicy { Write-SuccessMsg "Assertion passed: profile contains completion block" + # Assert the execution policy was not modified by the installer. $actualPolicy = Get-ExecutionPolicy -Scope CurrentUser if ($actualPolicy -ne $ExpectedPolicy) { Set-ExecutionPolicy $originalPolicy -Scope CurrentUser -Force -ErrorAction SilentlyContinue @@ -117,6 +124,7 @@ function Test-DRCompletionInstallWithExecutionPolicy { Write-SuccessMsg "Assertion passed [$TestName]: execution policy remains '$actualPolicy'" + # Restore the original execution policy. Set-ExecutionPolicy $originalPolicy -Scope CurrentUser -Force -ErrorAction SilentlyContinue } From 99ff55d184b264ae7ff7f7c31fe8490e446edd38 Mon Sep 17 00:00:00 2001 From: AJ Alon Date: Wed, 22 Jul 2026 13:51:37 -0700 Subject: [PATCH 07/12] test(completion): mark Restricted policy warning as xfail The Restricted execution policy test expects a warning that won't appear until Phase 2 (the Go fix in CFX-6647-phase2) is merged. Mark it as an expected failure (xfail) so CI stays green on Phase 1 alone. When Phase 2 lands, delete the xfail branch inside Test-DRCompletionInstallWithExecutionPolicy to make the assertion hard. Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com> --- smoke_test_scripts/windows/run_smoke_test.ps1 | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/smoke_test_scripts/windows/run_smoke_test.ps1 b/smoke_test_scripts/windows/run_smoke_test.ps1 index 96661185..09a1b323 100755 --- a/smoke_test_scripts/windows/run_smoke_test.ps1 +++ b/smoke_test_scripts/windows/run_smoke_test.ps1 @@ -5,6 +5,8 @@ $DR_API_TOKEN = $args[0] $ErrorActionPreference = "Stop" +$global:XFailCount = 0 + function Write-ErrorMsg { param([string]$Message) Write-Host "[ERROR] " -NoNewline -ForegroundColor Red @@ -13,6 +15,13 @@ function Write-ErrorMsg { exit 1 } +function Write-XFailMsg { + param([string]$Message) + Write-Host "[XFAIL] " -NoNewline -ForegroundColor Yellow + Write-Host $Message + $global:XFailCount++ +} + function Write-SuccessMsg { param([string]$Message) Write-Host "[OK] " -NoNewline -ForegroundColor Green @@ -80,7 +89,17 @@ function Test-DRCompletionInstallWithExecutionPolicy { if ($ExpectWarning -and -not $hasWarning) { Set-ExecutionPolicy $originalPolicy -Scope CurrentUser -Force -ErrorAction SilentlyContinue - Write-ErrorMsg "Assertion failed [$TestName]: installer did not warn user with the execution policy fix command" + + # XFAIL: when testing Restricted policy without the Phase 2 Go fix, + # the warning is expected to be absent. Track as an expected failure + # instead of a hard error. Remove this branch when Phase 2 lands. + $isXFail = $ExpectWarning -and ($Policy -eq "Restricted") + + if ($isXFail) { + Write-XFailMsg "Assertion xfail [$TestName]: installer did not warn user with the execution policy fix command (expected: Phase 2 not yet merged)" + } else { + Write-ErrorMsg "Assertion failed [$TestName]: installer did not warn user with the execution policy fix command" + } } if (-not $ExpectWarning -and $hasWarning) { @@ -327,5 +346,13 @@ if (-not $url_accessible) { Write-End } +if ($global:XFailCount -gt 0) { + Write-Host "" + Write-Host ("=" * 20) -NoNewline + Write-Host " XFAIL SUMMARY " -NoNewline -ForegroundColor Yellow + Write-Host ("=" * 20) + Write-Host "$global:XFailCount expected failure(s) (xfail) -- these will pass after Phase 2 (CFX-6647 Go fix) is merged." +} + Write-SuccessMsg "Smoke tests for Windows completed successfully." exit 0 From e0dc224715916eb3194a9e5b731d4b9169a86a66 Mon Sep 17 00:00:00 2001 From: AJ Alon Date: Wed, 22 Jul 2026 16:51:20 -0700 Subject: [PATCH 08/12] test(completion,windows): fix xfail fall-through, guard Get-ExecutionPolicy Address review feedback from chasdr: the xfail branch in Test-DRCompletionInstallWithExecutionPolicy restored the original policy then fell through to the execution-policy check, which hard-failed because the restored policy didn't match ExpectedPolicy. Fix: return early after Write-XFailMsg so remaining assertions are skipped. Also restore several safeguards lost during rebase: - Guard Get-ExecutionPolicy with try/catch (Windows Server 2025 runner images may fail to auto-load Microsoft.PowerShell.Security) - Add --force to installer so each test does a real install - Clean up profile before/after each test for isolation Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com> --- smoke_test_scripts/windows/run_smoke_test.ps1 | 63 +++++++++++++------ 1 file changed, 43 insertions(+), 20 deletions(-) diff --git a/smoke_test_scripts/windows/run_smoke_test.ps1 b/smoke_test_scripts/windows/run_smoke_test.ps1 index 09a1b323..8c403004 100755 --- a/smoke_test_scripts/windows/run_smoke_test.ps1 +++ b/smoke_test_scripts/windows/run_smoke_test.ps1 @@ -71,16 +71,44 @@ function Test-DRCompletionInstallWithExecutionPolicy { [bool]$ExpectWarning ) + # Guard: Get-ExecutionPolicy may not be available on every PowerShell + # build (e.g. some Windows Server 2025 runner images fail to auto-load + # the Microsoft.PowerShell.Security module). Skip gracefully instead of + # crashing the entire smoke-test suite. + try { + $null = Get-ExecutionPolicy -Scope CurrentUser -ErrorAction Stop + } catch { + Write-InfoMsg "Skipping [$TestName]: Get-ExecutionPolicy cmdlet not available on this system." + + return + } + # Save the current policy so it can be restored after the test, then apply the policy under test. $originalPolicy = Get-ExecutionPolicy -Scope CurrentUser Set-ExecutionPolicy $Policy -Scope CurrentUser -Force - # Run the installer and fail fast if it exits non-zero. - $installOutput = (dr self completion install powershell --yes 2>&1 | Out-String) + # Resolve the PowerShell profile path, preferring PowerShell Core over Windows PowerShell (matches the Go installer). + $documentsPath = "$env:USERPROFILE\Documents" + $psCoreDir = Join-Path $documentsPath "PowerShell" + $windowsPsDir = Join-Path $documentsPath "WindowsPowerShell" + + if (Test-Path $psCoreDir) { + $profilePath = Join-Path $psCoreDir "Microsoft.PowerShell_profile.ps1" + } else { + $profilePath = Join-Path $windowsPsDir "Microsoft.PowerShell_profile.ps1" + } + + # Clean up any existing profile from a previous test so each run starts fresh. + if (Test-Path $profilePath) { + Remove-Item $profilePath -Force -ErrorAction SilentlyContinue + } + + # Run the installer with --force so each invocation performs a real install. + $installOutput = (dr self completion install powershell --yes --force 2>&1 | Out-String) $installExitCode = $LASTEXITCODE if ($installExitCode -ne 0) { Set-ExecutionPolicy $originalPolicy -Scope CurrentUser -Force -ErrorAction SilentlyContinue - Write-ErrorMsg "dr self completion install powershell --yes failed with exit code $installExitCode" + Write-ErrorMsg "dr self completion install powershell --yes --force failed with exit code $installExitCode" } # Assert the installer warned (or did not warn) about the execution policy fix command. @@ -88,18 +116,23 @@ function Test-DRCompletionInstallWithExecutionPolicy { $hasWarning = $installOutput -match $fixCommand if ($ExpectWarning -and -not $hasWarning) { - Set-ExecutionPolicy $originalPolicy -Scope CurrentUser -Force -ErrorAction SilentlyContinue - # XFAIL: when testing Restricted policy without the Phase 2 Go fix, # the warning is expected to be absent. Track as an expected failure - # instead of a hard error. Remove this branch when Phase 2 lands. + # and return early — the remaining assertions (profile, policy) are + # not meaningful when the warning behavior isn't yet implemented. + # Remove this branch when Phase 2 lands. $isXFail = $ExpectWarning -and ($Policy -eq "Restricted") if ($isXFail) { Write-XFailMsg "Assertion xfail [$TestName]: installer did not warn user with the execution policy fix command (expected: Phase 2 not yet merged)" - } else { - Write-ErrorMsg "Assertion failed [$TestName]: installer did not warn user with the execution policy fix command" + Set-ExecutionPolicy $originalPolicy -Scope CurrentUser -Force -ErrorAction SilentlyContinue + if (Test-Path $profilePath) { Remove-Item $profilePath -Force -ErrorAction SilentlyContinue } + + return } + + Set-ExecutionPolicy $originalPolicy -Scope CurrentUser -Force -ErrorAction SilentlyContinue + Write-ErrorMsg "Assertion failed [$TestName]: installer did not warn user with the execution policy fix command" } if (-not $ExpectWarning -and $hasWarning) { @@ -109,17 +142,6 @@ function Test-DRCompletionInstallWithExecutionPolicy { Write-SuccessMsg "Assertion passed [$TestName]: warning behavior correct" - # Resolve the PowerShell profile path, preferring PowerShell Core over Windows PowerShell (matches the Go installer). - $documentsPath = "$env:USERPROFILE\Documents" - $psCoreDir = Join-Path $documentsPath "PowerShell" - $windowsPsDir = Join-Path $documentsPath "WindowsPowerShell" - - if (Test-Path $psCoreDir) { - $profilePath = Join-Path $psCoreDir "Microsoft.PowerShell_profile.ps1" - } else { - $profilePath = Join-Path $windowsPsDir "Microsoft.PowerShell_profile.ps1" - } - # Assert the profile exists and contains the dr completion block. if (-not (Test-Path $profilePath)) { Set-ExecutionPolicy $originalPolicy -Scope CurrentUser -Force -ErrorAction SilentlyContinue @@ -143,8 +165,9 @@ function Test-DRCompletionInstallWithExecutionPolicy { Write-SuccessMsg "Assertion passed [$TestName]: execution policy remains '$actualPolicy'" - # Restore the original execution policy. + # Restore the original execution policy and clean up the profile. Set-ExecutionPolicy $originalPolicy -Scope CurrentUser -Force -ErrorAction SilentlyContinue + if (Test-Path $profilePath) { Remove-Item $profilePath -Force -ErrorAction SilentlyContinue } } # Main execution From fe3220de7ad6a25d6bb8d4ad51d01b16eec98fc5 Mon Sep 17 00:00:00 2001 From: AJ Alon Date: Thu, 23 Jul 2026 10:46:56 -0700 Subject: [PATCH 09/12] fix(smoke-test,windows): clear PSModulePath before launching powershell.exe When task smoke-test-windows is run from pwsh 7 (the default shell on GitHub Actions windows-latest), powershell.exe 5.1 inherits pwsh 7's PSModulePath, causing Microsoft.PowerShell.Security to fail to load and Get-ExecutionPolicy to be unavailable. This made both execution policy test cases skip silently instead of actually testing. Fix: clear PSModulePath in the Taskfile command so powershell.exe 5.1 reconstructs its own default module path. This is the workaround recommended by the PowerShell team. Ref: https://github.com/PowerShell/PowerShell/issues/18530#issuecomment-1325691850 Ref: https://github.com/actions/runner-images/issues/13221 Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com> --- Taskfile.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Taskfile.yaml b/Taskfile.yaml index 436aaedb..cf942bed 100644 --- a/Taskfile.yaml +++ b/Taskfile.yaml @@ -224,7 +224,10 @@ tasks: smoke-test-windows: desc: "Run smoke tests (Windows)" cmds: - - powershell.exe -ExecutionPolicy Bypass -File ./smoke_test_scripts/windows/run_smoke_test.ps1 {{if .DR_API_TOKEN}}{{.DR_API_TOKEN}}{{else}}$env:DR_API_TOKEN{{end}} + # Clear PSModulePath so powershell.exe (5.1) reconstructs its own module + # path instead of inheriting pwsh 7's incompatible module paths. + # See: https://github.com/PowerShell/PowerShell/issues/18530#issuecomment-1325691850 + - $env:PSModulePath = ''; powershell.exe -ExecutionPolicy Bypass -File ./smoke_test_scripts/windows/run_smoke_test.ps1 {{if .DR_API_TOKEN}}{{.DR_API_TOKEN}}{{else}}$env:DR_API_TOKEN{{end}} docs-serve: silent: true From 562042baad4d4ab6493f71372f341b92bd7a17bb Mon Sep 17 00:00:00 2001 From: AJ Alon Date: Thu, 23 Jul 2026 11:10:46 -0700 Subject: [PATCH 10/12] fix(smoke-test,windows): use cmd.exe syntax for PSModulePath clear Taskfile uses cmd.exe on Windows, not pwsh. The previous fix used PowerShell syntax ($env:PSModulePath = '') which cmd.exe doesn't recognize, causing exit code 127. Use cmd.exe syntax instead: set "PSModulePath=" Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com> --- Taskfile.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Taskfile.yaml b/Taskfile.yaml index cf942bed..b0dad191 100644 --- a/Taskfile.yaml +++ b/Taskfile.yaml @@ -227,7 +227,7 @@ tasks: # Clear PSModulePath so powershell.exe (5.1) reconstructs its own module # path instead of inheriting pwsh 7's incompatible module paths. # See: https://github.com/PowerShell/PowerShell/issues/18530#issuecomment-1325691850 - - $env:PSModulePath = ''; powershell.exe -ExecutionPolicy Bypass -File ./smoke_test_scripts/windows/run_smoke_test.ps1 {{if .DR_API_TOKEN}}{{.DR_API_TOKEN}}{{else}}$env:DR_API_TOKEN{{end}} + - set "PSModulePath=" && powershell.exe -ExecutionPolicy Bypass -File ./smoke_test_scripts/windows/run_smoke_test.ps1 {{if .DR_API_TOKEN}}{{.DR_API_TOKEN}}{{else}}$env:DR_API_TOKEN{{end}} docs-serve: silent: true From 42730302533519df319d62724c4834ed4a9d64a9 Mon Sep 17 00:00:00 2001 From: AJ Alon Date: Thu, 23 Jul 2026 11:18:17 -0700 Subject: [PATCH 11/12] fix(smoke-test,windows): use POSIX env-prefix for PSModulePath, harden script Taskfile v3 uses mvdan/sh (POSIX sh), not cmd.exe. The previous 'set "PSModulePath="' was a no-op in POSIX sh. Use env-prefix assignment syntax: 'PSModulePath= powershell.exe ...' Also address review findings: - Guard Set-ExecutionPolicy (applying test policy) with try/catch to skip gracefully if the runner restricts policy changes - Relax ErrorActionPreference around installer call to prevent stderr lines from causing terminating errors (consistent with the --debug test pattern in the same file) Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com> --- Taskfile.yaml | 4 +++- smoke_test_scripts/windows/run_smoke_test.ps1 | 14 +++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Taskfile.yaml b/Taskfile.yaml index b0dad191..7a853438 100644 --- a/Taskfile.yaml +++ b/Taskfile.yaml @@ -226,8 +226,10 @@ tasks: cmds: # Clear PSModulePath so powershell.exe (5.1) reconstructs its own module # path instead of inheriting pwsh 7's incompatible module paths. + # Taskfile uses mvdan/sh (POSIX sh), so we use env-prefix assignment + # syntax (not cmd.exe `set` or pwsh `$env:` syntax). # See: https://github.com/PowerShell/PowerShell/issues/18530#issuecomment-1325691850 - - set "PSModulePath=" && powershell.exe -ExecutionPolicy Bypass -File ./smoke_test_scripts/windows/run_smoke_test.ps1 {{if .DR_API_TOKEN}}{{.DR_API_TOKEN}}{{else}}$env:DR_API_TOKEN{{end}} + - PSModulePath= powershell.exe -ExecutionPolicy Bypass -File ./smoke_test_scripts/windows/run_smoke_test.ps1 {{if .DR_API_TOKEN}}{{.DR_API_TOKEN}}{{else}}$env:DR_API_TOKEN{{end}} docs-serve: silent: true diff --git a/smoke_test_scripts/windows/run_smoke_test.ps1 b/smoke_test_scripts/windows/run_smoke_test.ps1 index 8c403004..c1170abd 100755 --- a/smoke_test_scripts/windows/run_smoke_test.ps1 +++ b/smoke_test_scripts/windows/run_smoke_test.ps1 @@ -85,7 +85,14 @@ function Test-DRCompletionInstallWithExecutionPolicy { # Save the current policy so it can be restored after the test, then apply the policy under test. $originalPolicy = Get-ExecutionPolicy -Scope CurrentUser - Set-ExecutionPolicy $Policy -Scope CurrentUser -Force + + try { + Set-ExecutionPolicy $Policy -Scope CurrentUser -Force -ErrorAction Stop + } catch { + Write-InfoMsg "Skipping [$TestName]: unable to set execution policy to $Policy." + + return + } # Resolve the PowerShell profile path, preferring PowerShell Core over Windows PowerShell (matches the Go installer). $documentsPath = "$env:USERPROFILE\Documents" @@ -104,8 +111,13 @@ function Test-DRCompletionInstallWithExecutionPolicy { } # Run the installer with --force so each invocation performs a real install. + # Relax EAP to "Continue" so stderr lines from the native command are + # captured, not thrown (same pattern as the --debug test above). + $prevEAP = $ErrorActionPreference + $ErrorActionPreference = "Continue" $installOutput = (dr self completion install powershell --yes --force 2>&1 | Out-String) $installExitCode = $LASTEXITCODE + $ErrorActionPreference = $prevEAP if ($installExitCode -ne 0) { Set-ExecutionPolicy $originalPolicy -Scope CurrentUser -Force -ErrorAction SilentlyContinue Write-ErrorMsg "dr self completion install powershell --yes --force failed with exit code $installExitCode" From c75d82e65983a6f4834e0c55797513a1aa8c498e Mon Sep 17 00:00:00 2001 From: AJ Alon Date: Thu, 23 Jul 2026 14:47:55 -0700 Subject: [PATCH 12/12] test(completion,windows): use -Scope Process for execution policy tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Set-ExecutionPolicy -Scope CurrentUser fails on GitHub Actions Windows runners (Group Policy locks down registry-based policy changes). Switch to -Scope Process, which only affects the current PowerShell session and doesn't touch the registry. Use Get-ExecutionPolicy (effective) instead of -Scope CurrentUser to correctly reflect the Process-scope override. The $fixCommand string literal still says '-Scope CurrentUser' — that's the user-facing advice the Go installer should print (users should set it at CurrentUser scope, not Process scope). Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com> --- smoke_test_scripts/windows/run_smoke_test.ps1 | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/smoke_test_scripts/windows/run_smoke_test.ps1 b/smoke_test_scripts/windows/run_smoke_test.ps1 index c1170abd..09d9c395 100755 --- a/smoke_test_scripts/windows/run_smoke_test.ps1 +++ b/smoke_test_scripts/windows/run_smoke_test.ps1 @@ -76,18 +76,22 @@ function Test-DRCompletionInstallWithExecutionPolicy { # the Microsoft.PowerShell.Security module). Skip gracefully instead of # crashing the entire smoke-test suite. try { - $null = Get-ExecutionPolicy -Scope CurrentUser -ErrorAction Stop + $null = Get-ExecutionPolicy -ErrorAction Stop } catch { Write-InfoMsg "Skipping [$TestName]: Get-ExecutionPolicy cmdlet not available on this system." return } - # Save the current policy so it can be restored after the test, then apply the policy under test. - $originalPolicy = Get-ExecutionPolicy -Scope CurrentUser + # Save the current effective policy so it can be restored after the test. + # Use -Scope Process for Set-ExecutionPolicy so we don't touch the registry + # (some CI runners lock down CurrentUser/Machine policy via Group Policy). + # Get-ExecutionPolicy (no -Scope) returns the effective policy, which + # correctly reflects the Process-scope override. + $originalPolicy = Get-ExecutionPolicy try { - Set-ExecutionPolicy $Policy -Scope CurrentUser -Force -ErrorAction Stop + Set-ExecutionPolicy $Policy -Scope Process -Force -ErrorAction Stop } catch { Write-InfoMsg "Skipping [$TestName]: unable to set execution policy to $Policy." @@ -119,7 +123,7 @@ function Test-DRCompletionInstallWithExecutionPolicy { $installExitCode = $LASTEXITCODE $ErrorActionPreference = $prevEAP if ($installExitCode -ne 0) { - Set-ExecutionPolicy $originalPolicy -Scope CurrentUser -Force -ErrorAction SilentlyContinue + Set-ExecutionPolicy $originalPolicy -Scope Process -Force -ErrorAction SilentlyContinue Write-ErrorMsg "dr self completion install powershell --yes --force failed with exit code $installExitCode" } @@ -137,18 +141,18 @@ function Test-DRCompletionInstallWithExecutionPolicy { if ($isXFail) { Write-XFailMsg "Assertion xfail [$TestName]: installer did not warn user with the execution policy fix command (expected: Phase 2 not yet merged)" - Set-ExecutionPolicy $originalPolicy -Scope CurrentUser -Force -ErrorAction SilentlyContinue + Set-ExecutionPolicy $originalPolicy -Scope Process -Force -ErrorAction SilentlyContinue if (Test-Path $profilePath) { Remove-Item $profilePath -Force -ErrorAction SilentlyContinue } return } - Set-ExecutionPolicy $originalPolicy -Scope CurrentUser -Force -ErrorAction SilentlyContinue + Set-ExecutionPolicy $originalPolicy -Scope Process -Force -ErrorAction SilentlyContinue Write-ErrorMsg "Assertion failed [$TestName]: installer did not warn user with the execution policy fix command" } if (-not $ExpectWarning -and $hasWarning) { - Set-ExecutionPolicy $originalPolicy -Scope CurrentUser -Force -ErrorAction SilentlyContinue + Set-ExecutionPolicy $originalPolicy -Scope Process -Force -ErrorAction SilentlyContinue Write-ErrorMsg "Assertion failed [$TestName]: installer warned about execution policy when policy was already permissive" } @@ -156,29 +160,29 @@ function Test-DRCompletionInstallWithExecutionPolicy { # Assert the profile exists and contains the dr completion block. if (-not (Test-Path $profilePath)) { - Set-ExecutionPolicy $originalPolicy -Scope CurrentUser -Force -ErrorAction SilentlyContinue + Set-ExecutionPolicy $originalPolicy -Scope Process -Force -ErrorAction SilentlyContinue Write-ErrorMsg "Assertion failed: PowerShell profile was not found at $profilePath" } $profileContent = Get-Content $profilePath -Raw if ($profileContent -notmatch "dr completion powershell") { - Set-ExecutionPolicy $originalPolicy -Scope CurrentUser -Force -ErrorAction SilentlyContinue + Set-ExecutionPolicy $originalPolicy -Scope Process -Force -ErrorAction SilentlyContinue Write-ErrorMsg "Assertion failed: profile does not contain completion block" } Write-SuccessMsg "Assertion passed: profile contains completion block" # Assert the execution policy was not modified by the installer. - $actualPolicy = Get-ExecutionPolicy -Scope CurrentUser + $actualPolicy = Get-ExecutionPolicy if ($actualPolicy -ne $ExpectedPolicy) { - Set-ExecutionPolicy $originalPolicy -Scope CurrentUser -Force -ErrorAction SilentlyContinue + Set-ExecutionPolicy $originalPolicy -Scope Process -Force -ErrorAction SilentlyContinue Write-ErrorMsg "Assertion failed [$TestName]: expected execution policy to be $ExpectedPolicy, but it is '$actualPolicy'" } Write-SuccessMsg "Assertion passed [$TestName]: execution policy remains '$actualPolicy'" # Restore the original execution policy and clean up the profile. - Set-ExecutionPolicy $originalPolicy -Scope CurrentUser -Force -ErrorAction SilentlyContinue + Set-ExecutionPolicy $originalPolicy -Scope Process -Force -ErrorAction SilentlyContinue if (Test-Path $profilePath) { Remove-Item $profilePath -Force -ErrorAction SilentlyContinue } }