From 408fdd7856b4cf38eb1f92815b790bd1e454a109 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 18 Nov 2025 20:02:54 +0000 Subject: [PATCH 1/3] Initial plan From 158f785c49ef724cd1cee6634a9976bb93f882cf Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 18 Nov 2025 20:09:37 +0000 Subject: [PATCH 2/3] 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 <12820925+adityapatwardhan@users.noreply.github.com> --- src/code/Utils.cs | 2 +- .../PublishPSResource.Tests.ps1 | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/code/Utils.cs b/src/code/Utils.cs index c9c970506..7d640e824 100644 --- a/src/code/Utils.cs +++ b/src/code/Utils.cs @@ -1375,7 +1375,7 @@ private static bool TryReadPSDataFile( public static bool ValidateModuleManifest(string moduleManifestPath, out string errorMsg) { errorMsg = string.Empty; - using (System.Management.Automation.PowerShell pwsh = System.Management.Automation.PowerShell.Create()) + using (System.Management.Automation.PowerShell pwsh = System.Management.Automation.PowerShell.Create(RunspaceMode.CurrentRunspace)) { // use PowerShell cmdlet Test-ModuleManifest // TODO: Test-ModuleManifest will throw an error if RequiredModules specifies a module that does not exist diff --git a/test/PublishPSResourceTests/PublishPSResource.Tests.ps1 b/test/PublishPSResourceTests/PublishPSResource.Tests.ps1 index e97f64407..ed0adf1b8 100644 --- a/test/PublishPSResourceTests/PublishPSResource.Tests.ps1 +++ b/test/PublishPSResourceTests/PublishPSResource.Tests.ps1 @@ -131,6 +131,21 @@ Describe "Test Publish-PSResource" -tags 'CI' { } } + It "Publish a module with valid Author field without -SkipModuleManifestValidate" { + # This test verifies that the fix for runspace deserialization issue works correctly. + # Previously, PSModuleInfo.Author would return empty string when called via PowerShell.Create(), + # causing false positive "No author was provided" errors. + $version = "1.0.0" + $author = "TestAuthor" + New-ModuleManifest -Path (Join-Path -Path $script:PublishModuleBase -ChildPath "$script:PublishModuleName.psd1") -ModuleVersion $version -Description "$script:PublishModuleName module" -Author $author + + # This should succeed without needing -SkipModuleManifestValidate + Publish-PSResource -Path $script:PublishModuleBase -Repository $testRepository2 + + $expectedPath = Join-Path -Path $script:repositoryPath2 -ChildPath "$script:PublishModuleName.$version.nupkg" + (Get-ChildItem $script:repositoryPath2).FullName | Should -Be $expectedPath + } + It "Publish a module with -Path to the highest priority repo" { $version = "1.0.0" New-ModuleManifest -Path (Join-Path -Path $script:PublishModuleBase -ChildPath "$script:PublishModuleName.psd1") -ModuleVersion $version -Description "$script:PublishModuleName module" From d5ed92a02fb1c2d216103a4aa3734106d4febfbc Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 19 Nov 2025 19:15:12 +0000 Subject: [PATCH 3/3] Validate PSModuleInfo properties directly instead of checking pwsh.HadErrors first Changed validation logic to check Author, Description, and Version properties on the result object directly, rather than only checking them when pwsh.HadErrors is true. This ensures proper validation with CurrentRunspace mode. Co-authored-by: adityapatwardhan <12820925+adityapatwardhan@users.noreply.github.com> --- src/code/Utils.cs | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/code/Utils.cs b/src/code/Utils.cs index 7d640e824..cc6f0fa14 100644 --- a/src/code/Utils.cs +++ b/src/code/Utils.cs @@ -1400,32 +1400,32 @@ public static bool ValidateModuleManifest(string moduleManifestPath, out string } } - if (pwsh.HadErrors) + // Validate the result object directly + if (results.Any()) { - if (results.Any()) + PSModuleInfo psModuleInfoObj = results[0].BaseObject as PSModuleInfo; + if (string.IsNullOrWhiteSpace(psModuleInfoObj.Author)) { - PSModuleInfo psModuleInfoObj = results[0].BaseObject as PSModuleInfo; - if (string.IsNullOrWhiteSpace(psModuleInfoObj.Author)) - { - errorMsg = "No author was provided in the module manifest. The module manifest must specify a version, author and description. Run 'Test-ModuleManifest' to validate the file."; - } - else if (string.IsNullOrWhiteSpace(psModuleInfoObj.Description)) - { - errorMsg = "No description was provided in the module manifest. The module manifest must specify a version, author and description. Run 'Test-ModuleManifest' to validate the file."; - } - else if (psModuleInfoObj.Version == null) - { - errorMsg = "No version or an incorrectly formatted version was provided in the module manifest. The module manifest must specify a version, author and description. Run 'Test-ModuleManifest' to validate the file."; - } + errorMsg = "No author was provided in the module manifest. The module manifest must specify a version, author and description. Run 'Test-ModuleManifest' to validate the file."; + return false; } - - if (string.IsNullOrEmpty(errorMsg)) + else if (string.IsNullOrWhiteSpace(psModuleInfoObj.Description)) { - // Surface any inner error messages - var innerErrorMsg = (pwsh.Streams.Error.Count > 0) ? pwsh.Streams.Error[0].ToString() : string.Empty; - errorMsg = $"Module manifest file validation failed with error: {innerErrorMsg}. Run 'Test-ModuleManifest' to validate the module manifest."; + errorMsg = "No description was provided in the module manifest. The module manifest must specify a version, author and description. Run 'Test-ModuleManifest' to validate the file."; + return false; } - + else if (psModuleInfoObj.Version == null) + { + errorMsg = "No version or an incorrectly formatted version was provided in the module manifest. The module manifest must specify a version, author and description. Run 'Test-ModuleManifest' to validate the file."; + return false; + } + } + + // Check for any errors from Test-ModuleManifest + if (pwsh.HadErrors) + { + var innerErrorMsg = (pwsh.Streams.Error.Count > 0) ? pwsh.Streams.Error[0].ToString() : string.Empty; + errorMsg = $"Module manifest file validation failed with error: {innerErrorMsg}. Run 'Test-ModuleManifest' to validate the module manifest."; return false; } }