From c5b82be8b7e20aa311b8ae11cf8d546c86371c2b Mon Sep 17 00:00:00 2001 From: Jake Sanders Date: Tue, 4 Aug 2026 15:36:29 -0700 Subject: [PATCH] package-firewall: port the JSON editing primitives to PowerShell MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- package-firewall/powershell/lib/common.ps1 | 306 ++++++++++++++++++ package-firewall/tests/README.md | 12 +- package-firewall/tests/powershell/Harness.ps1 | 50 +++ .../tests/powershell/json-primitives.ps1 | 177 ++++++++++ package-firewall/tests/run-all.ps1 | 57 ++++ 5 files changed, 599 insertions(+), 3 deletions(-) create mode 100644 package-firewall/tests/powershell/Harness.ps1 create mode 100644 package-firewall/tests/powershell/json-primitives.ps1 create mode 100755 package-firewall/tests/run-all.ps1 diff --git a/package-firewall/powershell/lib/common.ps1 b/package-firewall/powershell/lib/common.ps1 index 62eaa17..b456bed 100644 --- a/package-firewall/powershell/lib/common.ps1 +++ b/package-firewall/powershell/lib/common.ps1 @@ -19,6 +19,10 @@ # Remove-XmlBlock ... — strips Endor XML block from settings.xml # Test-KeyConflict