Skip to content

Commit 2a65e3d

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

13 files changed

+54
-30
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

+41-19
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;
@@ -1029,57 +1031,77 @@ await PsesLanguageClient
10291031
[Fact]
10301032
public async Task CanSendCompletionAndCompletionResolveRequestAsync()
10311033
{
1032-
string filePath = NewTestFile("Get-Date");
1033-
10341034
CompletionList completionItems = await PsesLanguageClient.TextDocument.RequestCompletion(
10351035
new CompletionParams
10361036
{
10371037
TextDocument = new TextDocumentIdentifier
10381038
{
1039-
Uri = DocumentUri.FromFileSystemPath(filePath)
1039+
Uri = DocumentUri.FromFileSystemPath(NewTestFile(testCommand))
10401040
},
10411041
Position = new Position(line: 0, character: 7)
10421042
});
10431043

10441044
CompletionItem completionItem = Assert.Single(completionItems,
1045-
completionItem1 => completionItem1.FilterText == "Get-Date");
1045+
completionItem1 => completionItem1.FilterText == testCommand);
10461046

10471047
CompletionItem updatedCompletionItem = await PsesLanguageClient
10481048
.SendRequest("completionItem/resolve", completionItem)
10491049
.Returning<CompletionItem>(CancellationToken.None);
10501050

1051-
Assert.Contains("Gets the current date and time.", updatedCompletionItem.Documentation.String);
1051+
Assert.Contains(testDescription, updatedCompletionItem.Documentation.String);
10521052
}
10531053

10541054
[Fact]
10551055
public async Task CanSendCompletionResolveWithModulePrefixRequestAsync()
10561056
{
1057-
string filePath = NewTestFile("Get-TestDate");
1057+
await PsesLanguageClient
1058+
.SendRequest(
1059+
"evaluate",
1060+
new EvaluateRequestArguments
1061+
{
1062+
Expression = "Import-Module Microsoft.PowerShell.Archive -Prefix Test"
1063+
})
1064+
.ReturningVoid(CancellationToken.None);
10581065

1059-
CompletionList completionItems = await PsesLanguageClient.TextDocument.RequestCompletion(
1066+
try
1067+
{
1068+
const string command = "Expand-TestArchive";
1069+
1070+
CompletionList completionItems = await PsesLanguageClient.TextDocument.RequestCompletion(
10601071
new CompletionParams
10611072
{
10621073
TextDocument = new TextDocumentIdentifier
10631074
{
1064-
Uri = DocumentUri.FromFileSystemPath(filePath)
1075+
Uri = DocumentUri.FromFileSystemPath(NewTestFile(command))
10651076
},
10661077
Position = new Position(line: 0, character: 12)
10671078
});
10681079

1069-
CompletionItem completionItem = Assert.Single(completionItems,
1070-
completionItem1 => completionItem1.Label == "Get-TestDate");
1080+
CompletionItem completionItem = Assert.Single(completionItems,
1081+
completionItem1 => completionItem1.Label == command);
10711082

1072-
CompletionItem updatedCompletionItem = await PsesLanguageClient.ResolveCompletion(completionItem);
1083+
CompletionItem updatedCompletionItem = await PsesLanguageClient.ResolveCompletion(completionItem);
10731084

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

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

10841106
Hover hover = await PsesLanguageClient.TextDocument.RequestHover(
10851107
new HoverParams
@@ -1093,18 +1115,18 @@ public async Task CanSendHoverRequestAsync()
10931115

10941116
Assert.True(hover.Contents.HasMarkedStrings);
10951117
Assert.Collection(hover.Contents.MarkedStrings,
1096-
str1 => Assert.Equal("Write-Host", str1.Value),
1118+
str1 => Assert.Equal(testCommand, str1.Value),
10971119
str2 =>
10981120
{
10991121
Assert.Equal("markdown", str2.Language);
1100-
Assert.Equal("Writes customized output to a host.", str2.Value);
1122+
Assert.Equal(testDescription, str2.Value);
11011123
});
11021124
}
11031125

11041126
[Fact]
11051127
public async Task CanSendSignatureHelpRequestAsync()
11061128
{
1107-
string filePath = NewTestFile("Get-Date -");
1129+
string filePath = NewTestFile($"{testCommand} -");
11081130

11091131
SignatureHelp signatureHelp = await PsesLanguageClient.RequestSignatureHelp
11101132
(
@@ -1122,7 +1144,7 @@ public async Task CanSendSignatureHelpRequestAsync()
11221144
}
11231145
);
11241146

1125-
Assert.Contains("Get-Date", signatureHelp.Signatures.First().Label);
1147+
Assert.Contains(testCommand, signatureHelp.Signatures.First().Label);
11261148
}
11271149

11281150
[Fact]
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)