[pkg firewall] port the JSON editing primitives to PowerShell - #29
Open
dekkagaijin wants to merge 1 commit into
Open
[pkg firewall] port the JSON editing primitives to PowerShell#29dekkagaijin wants to merge 1 commit into
dekkagaijin wants to merge 1 commit into
Conversation
Start of the Windows port. Mirrors the awk primitives in bash/lib/common.sh function for function, so review is a diff against something already merged. Get-EndorB64Url / Get-EndorB64Decode / Get-EndorVSCodeToken / Get-EndorRedactAk Get-JsonDoc / Set-JsonDoc Get-LineIndent / Get-LineEntryKey Get-JsonTopObjectRange / Get-JsonTopObjectBlock Set-JsonObjectKeys / Set-JsonTopObjectBlock Add-JsonTopLine / Remove-JsonTopKey / Get-JsonTopString Test-JsonValid Line editing rather than ConvertTo-Json, for the same reason the bash side avoids reserialization and more so: ConvertTo-Json re-indents every line, needs -Depth raised on 5.1 (the default of 2 silently truncates), and escapes forward slashes — turning a two-key change into a whole-file rewrite no reviewer can diff. Get-JsonDoc / Set-JsonDoc carry the newline flavour and the final-newline state through an edit, so a CRLF file stays CRLF and a file with no trailing newline keeps not having one. Both are asserted; either would silently break byte-exact restore. Test-JsonValid does a structural trailing-comma check on top of ConvertFrom-Json, because ConvertFrom-Json *accepts* trailing commas in both 5.1 and 7.x — and a trailing comma is precisely the malformation a bad comma rewrite produces. Without the extra check the validator would wave through the one error it exists to catch. (The same check is in the bash validator, where node is not always resolvable.) Why mirror instead of share: the two ports write the same marker key and the same patched lines into the same file, and one fleet may be managed by both scripts. If they drift, one platform's output stops being readable by the other's state machine — which surfaces as a mysterious re-patch loop rather than an error. The suites mirror each other assertion for assertion to keep that from happening quietly. Tests: 45 assertions, matching the bash suite, plus CRLF round-tripping (which the bash side has no equivalent for). run-all.ps1 lets a Windows admin validate without bash or WSL; both runners now discover suites by glob. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
dekkagaijin
force-pushed
the
vscode-fw-6-powershell-json
branch
from
August 6, 2026 16:10
804cb62 to
c5b82be
Compare
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.
Merge after #28
Start of the Windows port. Mirrors the awk primitives in bash/lib/common.sh function for function, so review is a diff against something already merged.
Get-EndorB64Url / Get-EndorB64Decode / Get-EndorVSCodeToken / Get-EndorRedactAk
Get-JsonDoc / Set-JsonDoc
Get-LineIndent / Get-LineEntryKey
Get-JsonTopObjectRange / Get-JsonTopObjectBlock
Set-JsonObjectKeys / Set-JsonTopObjectBlock
Add-JsonTopLine / Remove-JsonTopKey / Get-JsonTopString
Test-JsonValid
Line editing rather than ConvertTo-Json, for the same reason the bash side avoids reserialization and more so: ConvertTo-Json re-indents every line, needs -Depth raised on 5.1 (the default of 2 silently truncates), and escapes forward slashes — turning a two-key change into a whole-file rewrite no reviewer can diff.
Get-JsonDoc / Set-JsonDoc carry the newline flavour and the final-newline state through an edit, so a CRLF file stays CRLF and a file with no trailing newline keeps not having one. Both are asserted; either would silently break byte-exact restore.
Test-JsonValid does a structural trailing-comma check on top of ConvertFrom-Json, because ConvertFrom-Json accepts trailing commas in both 5.1 and 7.x — and a trailing comma is precisely the malformation a bad comma rewrite produces. Without the extra check the validator would wave through the one error it exists to catch. (The same check is in the bash validator, where node is not always resolvable.)
Why mirror instead of share: the two ports write the same marker key and the same patched lines into the same file, and one fleet may be managed by both scripts. If they drift, one platform's output stops being readable by the other's state machine — which surfaces as a mysterious re-patch loop rather than an error. The suites mirror each other assertion for assertion to keep that from happening quietly.
Tests: 45 assertions, matching the bash suite, plus CRLF round-tripping (which the bash side has no equivalent for). run-all.ps1 lets a Windows admin validate without bash or WSL; both runners now discover suites by glob.
https://endorlabs.atlassian.net/browse/LM-452