Repository navigation
Add @generatePwshEnv PowerShell code generator - #1314
Open
jsskeen-utah wants to merge 2 commits into
Open
jsskeen-utah wants to merge 2 commits into
jsskeen-utah wants to merge 2 commits into
Conversation
Generates a .ps1 file that compiles the C# output from @generateCsharpEnv with Add-Type and returns the typed object from Get-Env. The C# class decrypts and validates the env blob, so the PowerShell side only wraps it.
Contributor
There was a problem hiding this comment.
Important
The generated loader cannot compile on PowerShell 7.2 or 7.3 despite advertising support for both.
Approach: Reusing the C# loader is sound, but the PowerShell runtime requirement must match the emitted code.
Reviewed changes include generator registration, emitted scripts, tests, and documentation.
- PowerShell loader: Adds typed loading, sensitive-key listing, customizable function names, and schema-hashed type reuse.
- Help and documentation: Adds property help, integration instructions, reference entries, and navigation.
- Validation: All 146 code-generation tests passed; plaintext loading, repeated dot-sourcing, help, and encrypted loading worked on PowerShell 7.6.10.
gpt-6.1-sol | 𝕏
The generated C# uses the AesGcm tag-size constructor, which only exists on .NET 8. PowerShell 7.2 and 7.3 run on .NET 6 and 7, and their compilers do not support the C# 11 required members that the shared C# output uses. The generated module now checks the PowerShell version first and throws a clear error on older versions.
Contributor
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes since the prior review align the runtime requirement with the generated C#.
- Enforced PowerShell 7.4: Added an explicit version check before compilation.
- Aligned documentation: Updated generated help and both documentation pages to require 7.4+.
- Added regression coverage: Verified all 147 code-generation tests pass, plus runtime guard rejection and successful compilation on PowerShell 7.6.10. PowerShell 7.4 itself was not available for execution.
gpt-6.1-sol | 𝕏
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Adds a
@generatePwshEnvcode generator. It writes a.ps1file that compiles the C# output from@generateCsharpEnvwithAdd-Typeand returns the typed object fromGet-Env. The C# class does the parsing, decryption, and validation, so the PowerShell side only wraps it.Property types and
Get-Helpproperty descriptions are read from the generated C# declarations, so they can't drift from the class.functionName=sets the function name (defaultGet-Env). It must be Verb-Noun.Requires PowerShell 7.4+ (.NET 8). The generated C# uses the
AesGcmtag-size constructor, which only exists on .NET 8, and the shared C# output uses C# 11requiredmembers that PowerShell 7.2 and 7.3 can't compile. The generated module checks the version first and throws a clear error on older versions.Windows PowerShell 5.1 is not a target. Its .NET Framework runtime can't load the generated code, and the C# output needs the modern .NET APIs. PowerShell 7 is the path Microsoft is taking for in-box PowerShell (see PowerShell 7 is coming to Windows), but 5.1 stays on existing Windows versions, so users on those will need to install PowerShell 7.4+ to use this generator.
Known limitation
A key whose name clashes with a member the generated C# class defines makes the module fail to compile. This affects
LOAD(clashes withLoad()),SensitiveKeys,DecryptBlob, and theobjectmembers (GetType,ToString,Equals,GetHashCode,MemberwiseClone,Finalize). The bug is in the C# emitter, not this PR: #1313. The PowerShell output inherits it and needs no change once that is fixed.Evidence
packages/varlock/src/env-graph/test/type-generationpasses (146 tests), including newpwsh.test.tscoverage for the wrapper,functionName, the namespace hash, and help generation.pwsh 7: dot-sourcing twice in one session, property types,Get-Help -Full, and a blob encrypted by varlock's ownencryptEnvBlobSyncloading correctly.varlock run --inject blob -- pwsh ./test.ps1against a schema with@encryptInjectedEnv.Merge Danger
Door: two-way. The change adds a decorator and new files. Nothing existing changes behavior, and the C# emitter is untouched.
Blast radius: limited to schemas that opt in with
@generatePwshEnv.