Repository navigation
Web UI saves keep router.yaml's comments and layout (#11) - #54
Merged
Merged
Conversation
…ged values are edited
Every save from the web UI went JSON -> map -> yaml.Marshal: all comments dropped, keys sorted.
- yamledit.go: the live file and the page's config are both encoded canonically; where they differ
the live file's text is edited — scalars in place (quoting kept), entries added or cut out (their
comments too, blank separators kept), lists matched by `name`, flow collections edited inside
(alignment and line breaks kept), `[]` / `{}` that get content become blocks. Values the defaults
derive from a changed setting are spelled out as the page had them.
- The result must decode to exactly the submitted config, else the canonical form is written
(comments lost, logged).
- Tests: unchanged save byte-identical (home, lab); every edit kind touches only its own lines; all
608 scalars of the lab config edited in place one by one; anchors / multi-document refused.
Closes #11
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.
What
mr/yamledit.go: a web UI save no longer re-encodes router.yaml. The live file and the submitted config are both decoded intoConfigand encoded canonically (struct order, omitempty); where the two canonical trees differ, the live file's text is edited:username: "…"stays double-quoted);name(else by position); reordered named items move with their lines; unnamed lists that change length are rewritten;{name: …, proto: […]},[a, b]) are edited inside — alignment padding and line breaks stay; plain values that would read as syntax inside a flow (::10) are quoted;[]/{}that receive content become block form;The result must decode (with defaults) to exactly the submitted config; otherwise the canonical encoding is written, as before (comments lost), and the reason is logged. The
# written by the web UIheader is no longer prepended on every save.Why
configFromJSONwent JSON → map →yaml.Marshal: saving once from the web UI dropped every comment of a hand-written router.yaml and sorted all keys, and turned a one-field change into a whole-file git diff.Verification
tools/ci.shpasses (private and public trees).mr/yamledit_test.go): a save without changes is byte-identical for the example config and the lab config (all features); each kind of edit changes only its own line(s) — scalar, list-item scalar with a trailing comment, quoted string, sysctl map, inline list, a value inside an aligned flow item, appended flow item, removed named item, new top-level section, optional key off / on, reorder.::10in flows, multi-line flow collections, blank-line handling and the derived-default case.Closes #11
https://claude.ai/code/session_01HWeUjo1dmS7gBkCYHrVjCr