feat(acls): add HuJSON formatting and validation - #628
Open
KnowItAllKing wants to merge 3 commits into
Open
Conversation
There was a problem hiding this comment.
ℹ️ No blocking issues — two minor observations inline.
Reviewed changes
- Comment-preserving formatting (
app/utils/acl-policy.ts) — addsformatPolicyon top ofjsonc-parser'sformat, and rewritesparsePolicyontoparseTreewithallowTrailingComma: true. The move offscanHuJson-then-JSON.parsealso fixes a latent bug where the trailing-comma regex corrupted,}/,]sequences inside string values. - Live diagnostics (
cm.client.tsx) — a CodeMirror linter plus a status bar surfacevalidatePolicyerrors inline, and a Format button reflows the buffer. - Save gating (
overview.tsx,acl-action.ts) — the Save button disables on empty or invalid policy, and the action re-validates server-side before forwarding to Headscale. - Docs & changelog —
docs/features/acls.mdand a# Nextchangelog entry describe the new editor behavior. - Tests — unit coverage for
formatPolicy,validatePolicy, the string-corruption regression, and the new action guard.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
… as neutral Formatting now keeps existing line breaks so blank-line groupings and inline arrays in hand-written policies survive. An empty policy is no longer reported as a syntax error; the editor shows a neutral "No policy yet" state instead.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Empty-policy neutrality (
acl-policy.ts,cm.client.tsx) —validatePolicyno longer reports an empty policy as a syntax error, and the editor shows a neutral "No policy yet" state with aCircleDashedicon instead of a red error on first run. The Format button is disabled while empty. - Line-preserving formatting (
acl-policy.ts) —formatPolicyswitched tokeepLines: true, so blank-line section groupings and inline arrays survive formatting while indentation and spacing are still normalized. - Nix hash bump (
nix/package.nix) — the dependency hash now matches thejsonc-parserand@codemirror/lintadditions from the earlier commit. - Tests — updated and extended to cover
keepLineslayout preservation, empty-policy neutrality, and non-formatting of empty input.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
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
Testing
Follow-up to #607 and #608.