Repository navigation
Keep whitespace-only lines in config-remote-sync block scalars - #8119
ilyakuz-db wants to merge 13 commits into
Conversation
…k-scalar-whitespace
aws: TestAccept/bundle/config-remote-sync/formatting_preserved TestAccept/bundle/config-remote-sync/config_edits TestAccept/bundle/config-remote-sync/multiple_files TestAccept/bundle/config-remote-sync/job_fields
There was a problem hiding this comment.
Automated review at 9b7f048. Each finding was verified against the code.
Not ready yet: 1 blocking issue(s), tagged [blocking].
This PR keeps whitespace-only lines in block scalars that config-remote-sync writes or passes through. It does this by making restoreBlankLines treat only truly empty lines as blank, keeping tab lines and |+ trailing lines in untouched literal scalars, and ending - key: | scalars at the key's column. The restoreBlankLines fix holds up. The new block-end logic introduces a regression: keep-chomped scalars under list item keys can now lose their trailing newlines when an unrelated field is synced. There is also no changelog fragment for a change users will see.
Comments outside the changed lines
- [nice to have]
bundle/configsync/patch.go: This changes what config-remote-sync writes to users' YAML files: whitespace-only lines in synced values are now kept, and so are|+trailing lines and blank lines after- key: |. The tab-line bug also exists in a released version. Can you add a.nextchanges/bundles/fragment, or say why this doesn't need one?
| // and keep chomping (+) keeps all of them. | ||
| n := 0 | ||
| for j, blank := range pendingBlanks { | ||
| if keepsTabLines && (keepsTrailingLines || strings.HasSuffix(blank, "\t")) { |
There was a problem hiding this comment.
[blocking] Trailing blank lines are kept only when keepsTabLines is set, and that flag is never set for folded scalars. keepsTrailingLines is also limited to | (L620). Take - description: >+\n first\n\n task_key: x and sync an unrelated field. The new blockScalarParentIndent ends the scalar at task_key, the blank line becomes a marker, and yaml.v3 parses the untouched value as "first\n" instead of "first\n\n". In base the block ran on past task_key, so the blank line stayed. An empty - key: |+ hits the same bug, because keepsTabLines only turns on after the first content line. Could keep chomping keep the trailing lines (emptied) on its own, independent of tab handling, for >+ too, with a round-trip test for these list cases? The folded block scalar empties tab lines case would then expect an empty line, not a marker.
✅ Integration test reportCommit: 9ccea0d
Top 6 slowest tests (at least 2 minutes):
|
aws: TestAccept/bundle/config-remote-sync/formatting_preserved TestAccept/bundle/config-remote-sync/config_edits TestAccept/bundle/config-remote-sync/multiple_files TestAccept/bundle/config-remote-sync/job_fields
Regression test report ✅Commit: Selected 1 changed tests (limit=20, 0 not selected) 10 tests: regression=2 unreleased=0 coverage=8 failing=0
TestAccept/bundle/config-remote-sync/whitespace_only_lines/DMS=: branch ✅ | main (dccdf47) ❌ | latest (v1.28.0) ✅main (dccdf47): TestAccept/bundle/config-remote-sync/whitespace_only_lines/DMS=true: branch ✅ | main (dccdf47) ❌ | latest (v1.28.0) ✅main (dccdf47): |
| func appendBlockScalarBlanks(result, blanks []string, keepTabLines bool) []string { | ||
| for _, blank := range blanks { | ||
| if !keepTabLines || !strings.HasSuffix(blank, "\t") { | ||
| blank = "" |
There was a problem hiding this comment.
The null-parent add writes a block with a space-only line, but the next sync that rewrites the file empties it here and changes the value. Could the add double-quote such values instead?
…arent aws: TestAccept/bundle/config-remote-sync/formatting_preserved TestAccept/bundle/config-remote-sync/config_edits TestAccept/bundle/config-remote-sync/multiple_files TestAccept/bundle/config-remote-sync/job_fields Co-authored-by: Isaac <no-reply@databricks.com>
…t item keys aws: TestAccept/bundle/config-remote-sync/formatting_preserved TestAccept/bundle/config-remote-sync/config_edits TestAccept/bundle/config-remote-sync/multiple_files TestAccept/bundle/config-remote-sync/job_fields Co-authored-by: Isaac <no-reply@databricks.com>
…handling aws: TestAccept/bundle/config-remote-sync/formatting_preserved TestAccept/bundle/config-remote-sync/config_edits TestAccept/bundle/config-remote-sync/multiple_files TestAccept/bundle/config-remote-sync/job_fields Co-authored-by: Isaac <no-reply@databricks.com>
andrewnester
left a comment
There was a problem hiding this comment.
Space-only lines in untouched block scalars are still emptied on every save, which changes those values.
|
Same as on main: keeping those spaces makes the yaml.v3 patcher rewrite the whole block as a double-quoted string, so this PR keeps the block style. I'll fix both in a follow-up. |
Changes
restoreBlankLinestreats only empty lines as blank lines, so whitespace-only lines the encoder writes inside block scalars keep their whitespace.preserveBlankLineskeeps tab lines and|+trailing lines of untouched literal block scalars. Space-only lines are still emptied as before: yaml.v3, which the patcher uses, would otherwise rewrite the whole block as a double-quoted string.- key: |) now ends at the key's column instead of the dash's, so blank lines after it are kept. Trailing lines of keep-chomped (+) blocks there, folded ones included, stay part of the scalar.Why
Since the go-yaml v4 upgrade, multi-line strings with whitespace-only lines are written as
|blocks instead of double-quoted strings. When config-remote-sync added such a value,restoreBlankLinesstripped the whitespace from those lines and changed the value ("one\n \nthree"became"one\n\nthree"). Tab-only lines were already affected before v4.Follows up on #7987 (comment).
Tests
New unit cases in
bundle/configsync/patch_test.gofor synced values and untouched block scalars; the space case fails without the fix on v4. The new local acceptance testconfig-remote-sync/whitespace_only_linessyncs such a value through a null parent and checks the saved value, that a second sync finds no changes, and that a third sync of another field keeps the value; it fails without the fix. Localconfig-remote-syncacceptance tests pass. The head commit requests the aws runs offormatting_preserved,config_edits,multiple_filesandjob_fields.9ccea0d(latest)9ccea0d(latest)SIMPLER PATH: ship only the null-parent quoting, move the tab and keep-chomping fixes to a follow-up9ccea0d(latest)9ccea0d(latest)9ccea0d(latest)9ccea0d(latest)✅ success · ⏳ pending ·⚠️ warning · ❌ failed · ➖ n/a
This pull request and its description were written by Isaac.