[pkg firewall] JSON editing utilities - #25
Open
dekkagaijin wants to merge 2 commits into
Open
Conversation
First code chunk of the VS Code ecosystem. Nothing calls these yet — they are
added with their tests so the byte-fidelity properties can be reviewed on their
own, ahead of the lifecycle that uses them.
VS Code's product.json is the only config target here that is JSON, so it can
carry neither a '#' sentinel nor an ${ENDOR_*} reference, and it must be edited
in place with byte-exact restore. That rules out reserialization, and there is
no jq or python3 guarantee on a stock macOS or a minimal Linux image, so these
are line-oriented awk editors over the depth-1 object. plutil is not an option
either: it reorders every top-level key and minifies, and `plutil -lint` does
not even validate JSON.
endor_b64url / endor_b64d base64url on stdin, matching endor_b64
endor_redact_ak strip the _ak/<token> path segment
endor_file_has_final_newline
endor_replace_contents_inplace preserves inode, mode, owner and the
source's final-newline state
endor_json_top_string depth-1 scalar, ignoring nested keys
endor_json_extract_top_object raw lines of a depth-1 object
endor_json_merge_object_keys key-level set and delete, commas recomputed
endor_json_replace_top_object verbatim splice-back, for restore
endor_json_insert_top_line / endor_json_remove_top_key
endor_json_validate
Two properties are the whole point, and both are asserted:
- An edit touches only the keys it claims to. The patch is one key set and one
removed; the diff against a pristine file is 3 lines, not a reserialized
2963.
- Restore is byte-exact. Shipped product.json has no final newline while awk
always emits one, so the newline state is normalised back on write —
otherwise every patch would dirty the last line and no restore could ever
match.
Deleting or appending the last entry in an object must not leave a trailing
comma, so the merge recomputes entry-terminating commas rather than editing
lines in isolation. On input it cannot handle (minified, not line-oriented) each
editor declines with a non-zero return and leaves the file untouched, rather
than guessing.
endor_json_validate also rejects trailing commas structurally: node is not
always resolvable, and a trailing comma is precisely the malformation a bad
comma rewrite produces.
Tests: 43 assertions against a synthetic tests/fixtures/product.json — shaped
like a shipped one (tab-indented, LF, no final newline, extensionsGallery at
depth 1) but not tied to a VS Code build, so assertions like "16 accessSKUs"
don't start failing on VS Code's release schedule. Also covers 4-space
indentation, a sole-entry delete, and minified input.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
dekkagaijin
force-pushed
the
vscode-fw-2-json-primitives
branch
from
August 6, 2026 16:10
d41d530 to
20b8435
Compare
The harness is sourced, so the constants it defines are read by the suites and never by the file itself, which shellcheck cannot see from a single-file lint. Declare that once at the top rather than per variable. REPO_DIR and FIXTURE_LINES had no reader at all; the 74-line fact is already recorded in tests/README.md. run-all.sh runs without -e, so an unguarded cd would have let suite discovery glob the caller's directory instead of failing.
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 #24
First code chunk of the VS Code ecosystem. TBH I'm not sure we shouldn't just require
jqto be installed (and use powershell's json utilities on Windows), but here's what Claude came up with. Nothing calls these yet, they are added with their tests so the byte-fidelity properties can be reviewed on their own (ahead of the lifecycle that uses them).VS Code's product.json is the only config target here that is JSON, so it can carry neither a '#' sentinel nor an ${ENDOR_*} reference, and it must be edited in place with byte-exact restore. That rules out reserialization, and there is no jq or python3 guarantee on a stock macOS or a minimal Linux image, so these are line-oriented awk editors over the depth-1 object. plutil is not an option either: it reorders every top-level key and minifies, and
plutil -lintdoes not even validate JSON.endor_b64url / endor_b64d base64url on stdin, matching endor_b64
endor_redact_ak strip the _ak/ path segment
endor_file_has_final_newline
endor_replace_contents_inplace preserves inode, mode, owner and the
source's final-newline state
endor_json_top_string depth-1 scalar, ignoring nested keys
endor_json_extract_top_object raw lines of a depth-1 object
endor_json_merge_object_keys key-level set and delete, commas recomputed
endor_json_replace_top_object verbatim splice-back, for restore
endor_json_insert_top_line / endor_json_remove_top_key
endor_json_validate
Two properties are the whole point, and both are asserted:
Deleting or appending the last entry in an object must not leave a trailing comma, so the merge recomputes entry-terminating commas rather than editing lines in isolation. On input it cannot handle (minified, not line-oriented) each editor declines with a non-zero return and leaves the file untouched, rather than guessing.
endor_json_validate also rejects trailing commas structurally: node is not always resolvable, and a trailing comma is precisely the malformation a bad comma rewrite produces.
Tests: 43 assertions against a synthetic tests/fixtures/product.json — shaped like a shipped one (tab-indented, LF, no final newline, extensionsGallery at depth 1) but not tied to a VS Code build, so assertions like "16 accessSKUs" don't start failing on VS Code's release schedule. Also covers 4-space indentation, a sole-entry delete, and minified input.
https://endorlabs.atlassian.net/browse/LM-452