-
Notifications
You must be signed in to change notification settings - Fork 102
Fix PSModuleInfo property deserialization in ValidateModuleManifest #1909
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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>
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
@copilot in the file Utils.cs after the change in the previous commit, do not check whether pwsh.HadErrors. Instead do the subsequent checks on the result object. |
…dErrors 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>
Done. Changed the validation logic to check Author, Description, and Version properties directly on the result object, rather than only when Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
PR Summary
Utils.ValidateModuleManifest()fails with false positive "No author was provided" errors becausePSModuleInfoproperties return empty strings when deserialized across runspace boundaries.PR Context
PowerShell.Create()instantiates a new runspace. Objects returned from cmdlets executed in that runspace are serialized when crossing back to the calling context. During this serialization/deserialization,PSModuleInfoproperties (Author,Description,Version) lose their values.Changes:
src/code/Utils.cs(line 1378): UsePowerShell.Create(RunspaceMode.CurrentRunspace)instead ofPowerShell.Create()src/code/Utils.cs(lines 1403-1430): Restructured validation logic to check PSModuleInfo properties directly on the result object, regardless ofpwsh.HadErrorsstatetest/PublishPSResourceTests/PublishPSResource.Tests.ps1: Add test case validating manifest validation without-SkipModuleManifestValidateBefore:
After:
Running
Test-ModuleManifestin the current runspace eliminates the serialization boundary, preserving object properties. The validation logic now checks properties directly on the result object rather than only whenpwsh.HadErrorsis true, ensuring proper validation with CurrentRunspace mode.PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.Original prompt
This section details on the original issue you should resolve
<issue_title>Bug: PSModuleInfo.Author returns empty string when called via PowerShell Runspace</issue_title>
<issue_description>## 🐛 Bug Description
Utils.ValidateModuleManifest()fails with false positive "No author was provided" error when called via[PowerShell]::Create()runspace, even though the module manifest contains a validAuthorfield.The issue occurs because PSModuleInfo.Author property returns empty string when the object is deserialized across PowerShell runspace boundary.
📍 Affected Code
File:
src/code/Utils.csLines: 1388-1403
🔬 Root Cause
PSModuleInfo property deserialization fails when object crosses PowerShell runspace boundary.
Test Case 1: Direct Call (Works ✅)
Test Case 2: Runspace Call (Fails ❌)
Comparison Table:
Test-ModuleManifest -Path'GrexyLoco'[PowerShell]::Create()''(empty)False💥 Impact
Symptom:
Publish-PSResourcethrows error:Workaround Required:
This forces users to bypass validation entirely, which is not ideal for catching actual manifest issues.
🔧 Suggested Fix
Option 1: Use direct Test-ModuleManifest call (preferred)
Option 2: Serialize specific properties explicitly
Option 3: Add null/empty check with better error message
🧪 Reproduction Steps
Author = 'TestAuthor'Publish-PSResource -Path ./Module -Repository MyRepoTest-ModuleManifest→ works correctly📋 Environment
.psd1with all required fields includingAuthor📎 References
✅ Expected Behavior
ValidateModuleManifest()should correctly readAuthorproperty from module manifest regardless of execution context (direct vs runspace).❌ Actual Behavior
Authorproperty returns empty stri...💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.