Skip to content

[pkg firewall] port the JSON editing primitives to PowerShell - #29

Open
dekkagaijin wants to merge 1 commit into
vscode-fw-5-bash-wiringfrom
vscode-fw-6-powershell-json
Open

[pkg firewall] port the JSON editing primitives to PowerShell#29
dekkagaijin wants to merge 1 commit into
vscode-fw-5-bash-wiringfrom
vscode-fw-6-powershell-json

Conversation

@dekkagaijin

Copy link
Copy Markdown
Contributor

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

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
dekkagaijin force-pushed the vscode-fw-6-powershell-json branch from 804cb62 to c5b82be Compare August 6, 2026 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant