Preserve all formatting on YAML --preserve set (no more flow-style collapse)#11
Merged
Merged
Conversation
The --preserve set fast path only handled editing an existing single-line
scalar. New keys (and missing intermediate maps) fell through to the node
re-encode path, which reformats the WHOLE document: multi-line flow-style
collections (args: [ ... ] / annotations: { ... } spanning lines) collapsed
to one long line and blank lines were dropped. The targeted value was correct,
but the diff was far noisier than the single intended change.
Add a surgical insert path that anchors at the deepest existing block mapping
along the path and splices in just the missing tail (a leaf key, or a nested
block when intermediate maps are absent too). Everything outside the inserted
line(s) stays byte-for-byte identical, and the result is still validated by
re-parsing before it is accepted; anything it can't do surgically (flow-style
parents, non-scalar values, indexing into a scalar) defers to the safe
fallback as before.
Add byte-for-byte tests covering multi-line flow preservation on insert,
blank lines, top-level and nested-map creation, ambiguous-string quoting,
no-trailing-newline, and the insert-under-scalar error.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Problem
pipekit <fmt> set --preservepromises a surgical edit — change only the targeted value, touch nothing else. That held for editing an existing single-line scalar, but inserting a new key (e.g. bumping a chart'simage.tagwhen the key isn't there yet) fell through to the node re-encode fallback, which reformats the entire document:args: ['--config', '/etc/app.yaml'].The data was always correct (it re-parses to the same structure), but the diff was far noisier than the one intended change — exactly the thing
--preserveexists to avoid.Fix
Add a surgical insert path between the scalar-splice fast path and the re-encode fallback. It:
Net effect: everything outside the inserted line(s) stays byte-for-byte identical.
Before / after
Inserting
.image.tag=v1.4.0into a values file that has a multi-lineargs: [ ... ]andpodAnnotations: { ... }elsewhere now produces a single-line diff (+ tag: v1.4.0); previously every multi-line flow block collapsed.Tests
New byte-for-byte coverage:
[...]and{...}) preserved on insertenabled: "yes")All 275 tests pass;
go vetclean.🤖 Generated with Claude Code