Skip to content

Commit eaeefa1

Browse files
committed
Fix Help Update Process
1 parent 2d7d3e2 commit eaeefa1

File tree

5 files changed

+46
-34
lines changed

5 files changed

+46
-34
lines changed

PowerShellEditorServices.build.ps1

+45-3
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,53 @@ Task BuildCmdletHelp -After AssembleModule {
193193
}
194194

195195
Task SetupHelpForTests {
196-
Write-Build DarkMagenta 'Updating help (for tests)'
197-
Update-Help -Module Microsoft.PowerShell.Management, Microsoft.PowerShell.Utility -Force -Scope CurrentUser -UICulture en-US
196+
# Powershell 7+ ship with help included, but 5.1 does not on Windows Servers and CI. The secure devops pipeline also does not allow internet access, so we must update help from our local repository source.
197+
198+
# Only commands in Microsoft.PowerShell.Utility can be tested for help so as to minimize the repository storage.
199+
# This requires admin rights
200+
201+
#NOTE: You can run this task once as admin or update help separately, and continue to run tests as non-admin, if for instance developing locally.
202+
203+
$installHelpScript = {
204+
$ErrorActionPreference = 'Stop'
205+
if ((Get-Help Invoke-RestMethod).remarks -notlike 'Get-Help cannot find the Help files*') {
206+
Write-Host -Fore Green 'Powershell 5.1 Utility Help is already installed'
207+
return
208+
}
209+
210+
# Cant use requires RunAsAdministrator because PS isn't smart enough to know this is a subscript.
211+
if (-not [Security.Principal.WindowsPrincipal]::new([Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
212+
throw 'Windows PowerShell Update-Help requires admin rights. Please re-run the script in an elevated powershell session.'
213+
}
214+
215+
# We store our local copy of help files here for testing as some pipelines disallow internet access
216+
$helpPath = '{{HELPPATH}}'
217+
218+
Write-Host -Fore Magenta "Powershell 5.1 Utility Help is not installed, installing from $helpPath"
219+
220+
#Update the help, and capture verbose output
221+
$updateHelpOutput = Update-Help 'Microsoft.PowerShell.Utility' -Verbose -SourcePath $helpPath -Force *>&1
222+
223+
if ((Get-Help Invoke-RestMethod).remarks -like 'Get-Help cannot find the Help files*') {
224+
throw "Failed to install PowerShell 5.1 Help: $updateHelpOutput"
225+
} else {
226+
Write-Host -Fore Green 'Powershell 5.1 Utility Help installed successfully'
227+
}
228+
}
229+
230+
#Need this to inject the help file path, since PSScriptRoot won't work inside the script
231+
$helpPath = "$PSScriptRoot\test\PowerShellEditorServices.Test.Shared\PSHelp"
232+
$resolvedScript = $installHelpScript -replace '{{HELPPATH}}', $helpPath
233+
234+
#We might be running as PS7, so run as separate WinPS process to be sure.
235+
powershell.exe -NoProfile -NonInteractive -Command $resolvedScript
236+
237+
if ($LASTEXITCODE -ne 0) {
238+
throw 'Failed to install PowerShell 5.1 Help.'
239+
}
198240
}
199241

200-
Task TestPS74 Build, SetupHelpForTests, {
242+
Task TestPS74 Build, {
201243
Set-Location ./test/PowerShellEditorServices.Test/
202244
Invoke-BuildExec { & dotnet $script:dotnetTestArgs $script:NetFramework.PS74 }
203245
}

test/PowerShellEditorServices.Test.E2E/LanguageServerProtocolMessageTests.cs

-18
Original file line numberDiff line numberDiff line change
@@ -1029,15 +1029,6 @@ await PsesLanguageClient
10291029
[Fact]
10301030
public async Task CanSendCompletionAndCompletionResolveRequestAsync()
10311031
{
1032-
await PsesLanguageClient
1033-
.SendRequest(
1034-
"evaluate",
1035-
new EvaluateRequestArguments
1036-
{
1037-
Expression = $"Update-Help Microsoft.Powershell.Utility -SourcePath {s_binDir};"
1038-
})
1039-
.ReturningVoid(CancellationToken.None);
1040-
10411032
string filePath = NewTestFile("Get-Date");
10421033

10431034
CompletionList completionItems = await PsesLanguageClient.TextDocument.RequestCompletion(
@@ -1063,15 +1054,6 @@ await PsesLanguageClient
10631054
[Fact]
10641055
public async Task CanSendCompletionResolveWithModulePrefixRequestAsync()
10651056
{
1066-
await PsesLanguageClient
1067-
.SendRequest(
1068-
"evaluate",
1069-
new EvaluateRequestArguments
1070-
{
1071-
Expression = $"Update-Help Microsoft.Powershell.Utility -SourcePath {s_binDir};Import-Module Microsoft.PowerShell.Utility -Prefix Test -Force"
1072-
})
1073-
.ReturningVoid(CancellationToken.None);
1074-
10751057
string filePath = NewTestFile("Get-TestDate");
10761058

10771059
CompletionList completionItems = await PsesLanguageClient.TextDocument.RequestCompletion(

test/PowerShellEditorServices.Test.E2E/PowerShellEditorServices.Test.E2E.csproj

-7
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,4 @@
4040
<ItemGroup>
4141
<Content Include="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
4242
</ItemGroup>
43-
44-
<ItemGroup>
45-
<!-- Used for Update-Help for some test fixtures -->
46-
<Content Include="..\PowerShellEditorServices.Test.Shared\PSHelp\**\*"
47-
CopyToOutputDirectory="PreserveNewest" />
48-
</ItemGroup>
49-
5043
</Project>
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Windows PowerShell does not have updated help in CI by default and we utilize a private Azure Devops repo for builds that has no internet access. The completion tests validate the Windows Help so we update it offline from here so these tests can work.
1+
Windows PowerShell does not have updated help in CI by default and we utilize a private Azure Devops repo for builds that has no internet access. The completion tests validate the Windows Help so we update it offline from here so these tests can work. The help is updated as part of the build pipeline in PowerShellEditorServices.build.ps1 for PS5 only.

test/PowerShellEditorServices.Test/Language/SymbolsServiceTests.cs

-5
Original file line numberDiff line numberDiff line change
@@ -758,11 +758,6 @@ public async Task FindsReferencesOnEnumMember()
758758
[Fact]
759759
public async Task FindsDetailsForBuiltInCommand()
760760
{
761-
// Ensure help is updated prior to test run
762-
await psesHost.ExecutePSCommandAsync(
763-
new PSCommand().AddScript("Update-Help Microsoft.Powershell.Utility -SourcePath $PSHOME"),
764-
default);
765-
766761
SymbolDetails symbolDetails = await symbolsService.FindSymbolDetailsAtLocationAsync(
767762
GetScriptFile(FindsDetailsForBuiltInCommandData.SourceDetails),
768763
FindsDetailsForBuiltInCommandData.SourceDetails.StartLineNumber,

0 commit comments

Comments
 (0)