Skip to content

Commit 79a26c0

Browse files
Pin generated module to PowerShell 7.6 Core
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 5bf49c4 commit 79a26c0

4 files changed

Lines changed: 54 additions & 8 deletions

File tree

src/init/requirements.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#Requires -Version 7.6
2+
#Requires -PSEdition Core

tests/Conformance.Tests.ps1

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ param()
1414
BeforeAll {
1515
$archivePath = Join-Path $PSScriptRoot 'fixtures\yaml-test-suite\yaml-test-suite-data-2022-01-17.zip'
1616
$sourcesPath = Join-Path $PSScriptRoot 'fixtures\yaml-test-suite\SOURCES.txt'
17+
$repositoryRoot = Split-Path -Parent $PSScriptRoot
1718
$suitePath = Join-Path $TestDrive 'yaml-test-suite'
19+
. (Join-Path $PSScriptRoot 'TestBootstrap.ps1')
20+
$conformanceYamlModule = $yamlModule
1821
Expand-Archive -LiteralPath $archivePath -DestinationPath $suitePath
1922
$suiteRoots = @(
2023
Get-ChildItem -LiteralPath $suitePath -Directory
@@ -34,6 +37,18 @@ BeforeAll {
3437
}
3538

3639
Describe 'Released yaml-test-suite corpus accounting' {
40+
It 'uses the built module for conformance in GitHub Actions' {
41+
if ($env:GITHUB_ACTIONS -eq 'true') {
42+
$conformanceYamlModule | Should -Not -BeNullOrEmpty
43+
$command = Get-Command -Name ConvertFrom-Yaml
44+
$command.Module | Should -Be $conformanceYamlModule
45+
$conformanceYamlModule.ModuleBase |
46+
Should -Not -Be (Join-Path $repositoryRoot 'src')
47+
$conformanceYamlModule.PowerShellVersion | Should -Be '7.6'
48+
@($conformanceYamlModule.CompatiblePSEditions) | Should -Be @('Core')
49+
}
50+
}
51+
3752
It 'uses the pinned unmodified release archive' {
3853
(Get-FileHash -LiteralPath $archivePath -Algorithm SHA256).Hash |
3954
Should -Be '47C173AFFEB480517B30FB77DC8C76FD48609B9B65DD1C1D3D0D0BAEE48D6AA9'

tests/Packaging.Tests.ps1

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ BeforeAll {
2222
$loadedYamlModule = if (-not [string]::IsNullOrWhiteSpace(
2323
$env:PSMODULE_YAML_TEST_ARTIFACT
2424
)) {
25-
Import-Module -Name $env:PSMODULE_YAML_TEST_ARTIFACT -Force -Global -PassThru |
25+
Import-Module -Name $env:PSMODULE_YAML_TEST_ARTIFACT -Force -Global -PassThru `
26+
-ErrorAction Stop |
2627
Where-Object Name -EQ 'Yaml' |
2728
Select-Object -First 1
2829
} else {
@@ -55,10 +56,19 @@ Describe 'Dependency-free package source' {
5556

5657
$manifest.PowerShellVersion | Should -Be '7.6'
5758
@($manifest.CompatiblePSEditions) | Should -Be @('Core')
59+
@($manifest.CompatiblePSEditions) | Should -Not -Contain 'Desktop'
5860
$manifest.ContainsKey('DotNetFrameworkVersion') | Should -BeFalse
5961
$manifest.ContainsKey('RequiredAssemblies') | Should -BeFalse
6062
}
6163

64+
It 'declares the generated artifact runtime once in module initialization' {
65+
$requirementPath = Join-Path $repositoryRoot 'src\init\requirements.ps1'
66+
$source = Get-Content -LiteralPath $requirementPath -Raw
67+
68+
$source | Should -Match '(?m)^#Requires -Version 7\.6\r?$'
69+
$source | Should -Match '(?m)^#Requires -PSEdition Core\r?$'
70+
}
71+
6272
It 'contains no external parser references or custom assembly loader' {
6373
$sourceFiles = Get-ChildItem -Path (Join-Path $repositoryRoot 'src') -Recurse -File
6474
$source = $sourceFiles |
@@ -125,24 +135,38 @@ Describe 'Generated artifact package' {
125135

126136
$manifest.PowerShellVersion | Should -Be '7.6'
127137
@($manifest.CompatiblePSEditions) | Should -Be @('Core')
138+
@($manifest.CompatiblePSEditions) | Should -Not -Contain 'Desktop'
128139
$manifest.ContainsKey('RequiredAssemblies') | Should -BeFalse
129140
$manifest.ContainsKey('DotNetFrameworkVersion') | Should -BeFalse
130141
@($manifest.FunctionsToExport | Sort-Object) |
131142
Should -Be @('ConvertFrom-Yaml', 'ConvertTo-Yaml', 'Test-Yaml')
132143
@($manifest.FileList) | Should -Contain 'Yaml.psm1'
144+
$packagedFiles = @(
145+
Get-ChildItem -Path $moduleBase -Recurse -File |
146+
Where-Object FullName -NE $artifactManifestPath |
147+
ForEach-Object {
148+
[System.IO.Path]::GetRelativePath($moduleBase, $_.FullName)
149+
} |
150+
Sort-Object
151+
)
152+
@($manifest.FileList | Sort-Object) | Should -Be $packagedFiles
133153
@($manifest.FileList | Where-Object { $_ -match '\.(?:dll|exe)$' }).Count | Should -Be 0
134154
@($manifest.FileList | Where-Object { $_ -match 'THIRD-PARTY|YamlDotNet' }).Count | Should -Be 0
155+
@($manifest.PrivateData.PSData.Tags) | Should -Not -Contain 'PSEdition_Desktop'
135156
@(Get-ChildItem -Path $moduleBase -Recurse -File -Filter '*.dll').Count | Should -Be 0
136157
{ Test-ModuleManifest -Path $artifactManifestPath } | Should -Not -Throw
137158
}
138159

139-
It 'imports in a fresh PowerShell 7 process and preserves arrays, aliases, and depth' `
160+
It 'imports in a fresh PowerShell 7.6 Core process and preserves arrays, aliases, and depth' `
140161
-Skip:($skipArtifactTests -or $null -eq (Get-Command pwsh -ErrorAction SilentlyContinue)) {
141162
$script = @'
142163
$ErrorActionPreference = 'Stop'
143164
$ps = $PSVersionTable.PSVersion
144-
if ($ps.Major -lt 7 -or ($ps.Major -eq 7 -and $ps.Minor -lt 6)) {
145-
throw "Expected PowerShell 7.6+ but got $ps."
165+
if ($ps.Major -ne 7 -or $ps.Minor -ne 6) {
166+
throw "Expected PowerShell 7.6.x but got $ps."
167+
}
168+
if ($PSVersionTable.PSEdition -cne 'Core') {
169+
throw "Expected PowerShell Core but got $($PSVersionTable.PSEdition)."
146170
}
147171
Import-Module -Name '__MANIFEST__' -Force
148172
$value = 'v: []' | ConvertFrom-Yaml -AsHashtable
@@ -179,11 +203,15 @@ $deepYaml = ConvertTo-Yaml -InputObject $atLimit -Depth 128 -MaxNodes 300
179203
if (-not (Test-Yaml -Yaml $deepYaml -Depth 128 -MaxNodes 300)) {
180204
throw 'The public maximum serialization depth failed.'
181205
}
182-
'powershell-7-ok'
206+
"powershell-runtime=$ps;edition=$($PSVersionTable.PSEdition)"
183207
'@.Replace('__MANIFEST__', $artifactManifestPath.Replace("'", "''"))
184208

185-
(& pwsh -NoLogo -NoProfile -Command $script) |
186-
Should -Contain 'powershell-7-ok'
209+
$output = @(& pwsh -NoLogo -NoProfile -Command $script)
210+
$runtime = $output | Where-Object { $_ -like 'powershell-runtime=*' } |
211+
Select-Object -Last 1
212+
213+
$runtime | Should -Match '^powershell-runtime=7\.6\.\d+;edition=Core$'
214+
Write-Information -MessageData $runtime -InformationAction Continue
187215
$LASTEXITCODE | Should -Be 0
188216
}
189217
}

tests/TestBootstrap.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
$artifactManifestOverride = $env:PSMODULE_YAML_TEST_ARTIFACT
22
$yamlModule = $null
33
if (-not [string]::IsNullOrWhiteSpace($artifactManifestOverride)) {
4-
$yamlModule = Import-Module -Name $artifactManifestOverride -Force -Global -PassThru |
4+
$yamlModule = Import-Module -Name $artifactManifestOverride -Force -Global -PassThru `
5+
-ErrorAction Stop |
56
Where-Object Name -EQ 'Yaml' |
67
Select-Object -First 1
78
}

0 commit comments

Comments
 (0)