From cb0d22a72a735443999687e4cf1dc25e8c3988d0 Mon Sep 17 00:00:00 2001 From: AJ Alon Date: Thu, 25 Jun 2026 16:46:19 -0700 Subject: [PATCH 1/6] 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 7bb0f006021b22bef98e2ea3f673e6c532673052 Mon Sep 17 00:00:00 2001 From: AJ Alon Date: Thu, 25 Jun 2026 17:01:33 -0700 Subject: [PATCH 2/6] 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 016ce518b09a0d218801653de09340d5f02e4ea5 Mon Sep 17 00:00:00 2001 From: AJ Alon Date: Thu, 25 Jun 2026 17:08:07 -0700 Subject: [PATCH 3/6] 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 c8a3a91571b2f86589df9e35ab16b91d0a5d269a Mon Sep 17 00:00:00 2001 From: AJ Alon Date: Thu, 25 Jun 2026 17:10:50 -0700 Subject: [PATCH 4/6] 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 40ba917aaf46c88cfb932203bb6f04c3cff7c329 Mon Sep 17 00:00:00 2001 From: AJ Alon Date: Thu, 25 Jun 2026 17:19:24 -0700 Subject: [PATCH 5/6] 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 4b7625c0995e107cc551459b6db1c5cd5698c7ab Mon Sep 17 00:00:00 2001 From: AJ Alon Date: Thu, 25 Jun 2026 17:24:09 -0700 Subject: [PATCH 6/6] 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 }