Skip to content

Commit 158f785

Browse files
Fix PSModuleInfo.Author deserialization issue using CurrentRunspace
Changed PowerShell.Create() to PowerShell.Create(RunspaceMode.CurrentRunspace) in Utils.ValidateModuleManifest() to prevent property deserialization issues when crossing runspace boundaries. Added test case to verify the fix. Co-authored-by: adityapatwardhan <[email protected]>
1 parent 408fdd7 commit 158f785

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/code/Utils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1375,7 +1375,7 @@ private static bool TryReadPSDataFile(
13751375
public static bool ValidateModuleManifest(string moduleManifestPath, out string errorMsg)
13761376
{
13771377
errorMsg = string.Empty;
1378-
using (System.Management.Automation.PowerShell pwsh = System.Management.Automation.PowerShell.Create())
1378+
using (System.Management.Automation.PowerShell pwsh = System.Management.Automation.PowerShell.Create(RunspaceMode.CurrentRunspace))
13791379
{
13801380
// use PowerShell cmdlet Test-ModuleManifest
13811381
// TODO: Test-ModuleManifest will throw an error if RequiredModules specifies a module that does not exist

test/PublishPSResourceTests/PublishPSResource.Tests.ps1

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,21 @@ Describe "Test Publish-PSResource" -tags 'CI' {
131131
}
132132
}
133133

134+
It "Publish a module with valid Author field without -SkipModuleManifestValidate" {
135+
# This test verifies that the fix for runspace deserialization issue works correctly.
136+
# Previously, PSModuleInfo.Author would return empty string when called via PowerShell.Create(),
137+
# causing false positive "No author was provided" errors.
138+
$version = "1.0.0"
139+
$author = "TestAuthor"
140+
New-ModuleManifest -Path (Join-Path -Path $script:PublishModuleBase -ChildPath "$script:PublishModuleName.psd1") -ModuleVersion $version -Description "$script:PublishModuleName module" -Author $author
141+
142+
# This should succeed without needing -SkipModuleManifestValidate
143+
Publish-PSResource -Path $script:PublishModuleBase -Repository $testRepository2
144+
145+
$expectedPath = Join-Path -Path $script:repositoryPath2 -ChildPath "$script:PublishModuleName.$version.nupkg"
146+
(Get-ChildItem $script:repositoryPath2).FullName | Should -Be $expectedPath
147+
}
148+
134149
It "Publish a module with -Path to the highest priority repo" {
135150
$version = "1.0.0"
136151
New-ModuleManifest -Path (Join-Path -Path $script:PublishModuleBase -ChildPath "$script:PublishModuleName.psd1") -ModuleVersion $version -Description "$script:PublishModuleName module"

0 commit comments

Comments
 (0)