Skip to content

Commit 50a806f

Browse files
committed
Switch to Microsoft.PowerShell.Archive for help tests for smaller artifact size.
1 parent 5a46259 commit 50a806f

13 files changed

+49
-23
lines changed

PowerShellEditorServices.build.ps1

+8-8
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,10 @@ Task BuildCmdletHelp -After AssembleModule {
195195
Task SetupHelpForTests {
196196
# Some CI do not ship with help included, and the secure devops pipeline also does not allow internet access, so we must update help from our local repository source.
197197

198-
# Only commands in Microsoft.PowerShell.Utility can be tested for help so as to minimize the repository storage.
198+
# Only commands in Microsoft.PowerShell.Archive can be tested for help so as to minimize the repository storage.
199199
# This requires admin rights for PS5.1
200200

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. Also this help is for PS5.1 so tests should be written for that even if PS7. For instance, don't write tests for new Invoke-RestMethod parameters.
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.
202202

203203
$installHelpScript = {
204204
param(
@@ -211,8 +211,8 @@ Task SetupHelpForTests {
211211
$helpPath = Join-Path $helpPath '7'
212212
}
213213

214-
if ((Get-Help Invoke-RestMethod).remarks -notlike 'Get-Help cannot find the Help files*') {
215-
Write-Host -Fore Green "PowerShell $PSVersion Utility Help is already installed"
214+
if ((Get-Help Expand-Archive).remarks -notlike 'Get-Help cannot find the Help files*') {
215+
Write-Host -Fore Green "PowerShell $PSVersion Archive Help is already installed"
216216
return
217217
}
218218

@@ -227,10 +227,10 @@ Task SetupHelpForTests {
227227
}
228228
}
229229

230-
Write-Host -Fore Magenta "Powershell $PSVersion Utility Help is not installed, installing from $helpPath"
230+
Write-Host -Fore Magenta "Powershell $PSVersion Archive Help is not installed, installing from $helpPath"
231231

232232
$updateHelpParams = @{
233-
Module = 'Microsoft.PowerShell.Utility'
233+
Module = 'Microsoft.PowerShell.Archive'
234234
SourcePath = $helpPath
235235
UICulture = 'en-US'
236236
Force = $true
@@ -244,10 +244,10 @@ Task SetupHelpForTests {
244244
#Update the help, and capture verbose output
245245
$updateHelpOutput = Update-Help @updateHelpParams *>&1
246246

247-
if ((Get-Help Invoke-RestMethod).remarks -like 'Get-Help cannot find the Help files*') {
247+
if ((Get-Help Expand-Archive).remarks -like 'Get-Help cannot find the Help files*') {
248248
throw "Failed to install PowerShell $PSVersion Help: $updateHelpOutput"
249249
} else {
250-
Write-Host -Fore Green "Powershell $PSVersion Utility Help installed successfully"
250+
Write-Host -Fore Green "Powershell $PSVersion Archive Help installed successfully"
251251
}
252252
}
253253

test/PowerShellEditorServices.Test.E2E/LanguageServerProtocolMessageTests.cs

+36-12
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public class LanguageServerProtocolMessageTests : IClassFixture<LSPTestsFixture>
3030
{
3131
private static readonly string s_binDir =
3232
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
33+
private const string testCommand = "Expand-Archive";
34+
private const string testDescription = "Extracts files from a specified archive (zipped) file.";
3335

3436
private readonly ILanguageClient PsesLanguageClient;
3537
private readonly List<LogMessageParams> Messages;
@@ -1054,32 +1056,54 @@ public async Task CanSendCompletionAndCompletionResolveRequestAsync()
10541056
[Fact]
10551057
public async Task CanSendCompletionResolveWithModulePrefixRequestAsync()
10561058
{
1057-
string filePath = NewTestFile("Get-TestDate");
1059+
await PsesLanguageClient
1060+
.SendRequest(
1061+
"evaluate",
1062+
new EvaluateRequestArguments
1063+
{
1064+
Expression = "Import-Module Microsoft.PowerShell.Archive -Prefix Test"
1065+
})
1066+
.ReturningVoid(CancellationToken.None);
10581067

1059-
CompletionList completionItems = await PsesLanguageClient.TextDocument.RequestCompletion(
1068+
try
1069+
{
1070+
const string command = "Expand-TestArchive";
1071+
1072+
CompletionList completionItems = await PsesLanguageClient.TextDocument.RequestCompletion(
10601073
new CompletionParams
10611074
{
10621075
TextDocument = new TextDocumentIdentifier
10631076
{
1064-
Uri = DocumentUri.FromFileSystemPath(filePath)
1077+
Uri = DocumentUri.FromFileSystemPath(NewTestFile(command))
10651078
},
10661079
Position = new Position(line: 0, character: 12)
10671080
});
10681081

1069-
CompletionItem completionItem = Assert.Single(completionItems,
1070-
completionItem1 => completionItem1.Label == "Get-TestDate");
1082+
CompletionItem completionItem = Assert.Single(completionItems,
1083+
completionItem1 => completionItem1.Label == command);
10711084

1072-
CompletionItem updatedCompletionItem = await PsesLanguageClient.ResolveCompletion(completionItem);
1085+
CompletionItem updatedCompletionItem = await PsesLanguageClient.ResolveCompletion(completionItem);
10731086

1074-
Assert.Contains("Gets the current date and time.", updatedCompletionItem.Documentation.String);
1087+
Assert.Contains(testDescription, updatedCompletionItem.Documentation.String);
1088+
}
1089+
finally
1090+
{
1091+
// Reset the Archive module to the non-prefixed version
1092+
await PsesLanguageClient
1093+
.SendRequest(
1094+
"evaluate",
1095+
new EvaluateRequestArguments
1096+
{
1097+
Expression = "Remove-Module Microsoft.PowerShell.Archive;Import-Module Microsoft.PowerShell.Archive -Force"
1098+
})
1099+
.ReturningVoid(CancellationToken.None);
1100+
}
10751101
}
10761102

10771103
[SkippableFact]
10781104
public async Task CanSendHoverRequestAsync()
10791105
{
1080-
Skip.If(OperatingSystem.IsWindows(),
1081-
"TODO: Fails in Windows GHA but works locally for some reason.");
1082-
string filePath = NewTestFile("Write-Host");
1106+
string filePath = NewTestFile(testCommand);
10831107

10841108
Hover hover = await PsesLanguageClient.TextDocument.RequestHover(
10851109
new HoverParams
@@ -1093,11 +1117,11 @@ public async Task CanSendHoverRequestAsync()
10931117

10941118
Assert.True(hover.Contents.HasMarkedStrings);
10951119
Assert.Collection(hover.Contents.MarkedStrings,
1096-
str1 => Assert.Equal("Write-Host", str1.Value),
1120+
str1 => Assert.Equal(testCommand, str1.Value),
10971121
str2 =>
10981122
{
10991123
Assert.Equal("markdown", str2.Language);
1100-
Assert.Equal("Writes customized output to a host.", str2.Value);
1124+
Assert.Equal(testDescription, str2.Value);
11011125
});
11021126
}
11031127

Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
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.
1+
Several CI platforms do not ship with PowerShell help. The build script updates help offline using this information.
2+
As some of the CI platforms do not have internet access.
3+
Linux servers use the zip file, while windows uses the cab files.

test/PowerShellEditorServices.Test.Shared/SymbolDetails/SymbolDetails.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Write-Host -ForegroundColor Black 'Test'
1+
Expand-Archive -Path $TEMP
22
# References Test uses this one
33
Get-Process -Name 'powershell*'
44

test/PowerShellEditorServices.Test/Language/SymbolsServiceTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ public async Task FindsDetailsForBuiltInCommand()
764764
FindsDetailsForBuiltInCommandData.SourceDetails.StartColumnNumber,
765765
CancellationToken.None);
766766

767-
Assert.Equal("Writes customized output to a host.", symbolDetails.Documentation);
767+
Assert.Equal("Extracts files from a specified archive (zipped) file.", symbolDetails.Documentation);
768768
}
769769

770770
[Fact]

0 commit comments

Comments
 (0)