Skip to content

Keep whitespace-only lines in config-remote-sync block scalars - #8119

Open
ilyakuz-db wants to merge 13 commits into
mainfrom
ilya/config-sync-block-scalar-whitespace
Open

ilyakuz-db wants to merge 13 commits into
mainfrom
ilya/config-sync-block-scalar-whitespace

Conversation

@ilyakuz-db

@ilyakuz-db ilyakuz-db commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Changes

  • restoreBlankLines treats only empty lines as blank lines, so whitespace-only lines the encoder writes inside block scalars keep their whitespace.
  • preserveBlankLines keeps 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.
  • A block scalar under a list item key (- 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.
  • A value with whitespace-only lines that config-remote-sync adds under a null parent is written double-quoted, so a later sync that rewrites the file cannot empty those lines.

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, restoreBlankLines stripped 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.go for synced values and untouched block scalars; the space case fails without the fix on v4. The new local acceptance test config-remote-sync/whitespace_only_lines syncs 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. Local config-remote-sync acceptance tests pass. The head commit requests the aws runs of formatting_preserved, config_edits, multiple_files and job_fields.

Status Check Revision Comments
✅ Local review 9ccea0d (latest) Codex approve on this head after merging main, 1 test-only P2 noted; auto review: Claude approve, 2 P2s noted; Codex no findings
⚠️ Design review 9ccea0d (latest) SIMPLER PATH: ship only the null-parent quoting, move the tab and keep-chomping fixes to a follow-up
✅ E2E validation 9ccea0d (latest) passed; requested 4 aws test dirs
➖ Isaac review 9ccea0d (latest) n/a on this repo
✅ Code owners review 9ccea0d (latest) approved by andrewnester, with a note on space-only lines in untouched blocks (unchanged from main)
✅ CI / merge conflicts 9ccea0d (latest) merged main, no conflicts; all checks green

✅ success · ⏳ pending · ⚠️ warning · ❌ failed · ➖ n/a

This pull request and its description were written by Isaac.

@ilyakuz-db
ilyakuz-db requested review from a team as code owners November 27, 2026 13:28
@github-actions github-actions Bot added the DABs DABs related issues label Nov 27, 2026
@ilyakuz-db ilyakuz-db self-assigned this Nov 27, 2026

@review-oss-bot review-oss-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Comment thread bundle/configsync/patch.go Outdated
// and keep chomping (+) keeps all of them.
n := 0
for j, blank := range pendingBlanks {
if keepsTabLines && (keepsTrailingLines || strings.HasSuffix(blank, "\t")) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

@eng-dev-ecosystem-bot

eng-dev-ecosystem-bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Integration test report

Commit: 9ccea0d

Run: 46048860560

Env 🤯​MISS ✅​pass 🙈​skip Time
✅​ aws linux-2core-8gb 186 18 4:27
✅​ aws-windows-latest-4core-16gb 174 22 3:05
🤯​ azure linux-2core-8gb 4 173 18 4:27
🤯​ azure-windows-latest-4core-16gb 4 173 18 2:47
🤯​ gcp linux-2core-8gb 4 174 18 4:27
🤯​ gcp-windows-latest-4core-16gb 4 174 18 3:03
Test Name azure linux-2core-8gb azure-windows-latest-4core-16gb gcp linux-2core-8gb gcp-windows-latest-4core-16gb
🤯​ TestAccept/bundle/config-remote-sync/config_edits 🤯​M 🤯​M 🤯​M 🤯​M
🤯​ TestAccept/bundle/config-remote-sync/formatting_preserved 🤯​M 🤯​M 🤯​M 🤯​M
🤯​ TestAccept/bundle/config-remote-sync/job_fields 🤯​M 🤯​M 🤯​M 🤯​M
🤯​ TestAccept/bundle/config-remote-sync/multiple_files 🤯​M 🤯​M 🤯​M 🤯​M
Top 6 slowest tests (at least 2 minutes):
duration env testname
4:27 azure linux-2core-8gb TestAccept
4:21 gcp linux-2core-8gb TestAccept
3:20 aws linux-2core-8gb TestAccept
3:01 gcp-windows-latest-4core-16gb TestAccept
3:01 aws-windows-latest-4core-16gb TestAccept
2:46 azure-windows-latest-4core-16gb TestAccept

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
@github-actions

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Regression test report ✅

Commit: 9ccea0d87 | Workflow run

Selected 1 changed tests (limit=20, 0 not selected)

10 tests: regression=2 unreleased=0 coverage=8 failing=0
test branch main (dccdf47) latest (v1.28.0)
TestAccept/bundle/config-remote-sync/config_edits/DMS= ✅ ✅ ✅
TestAccept/bundle/config-remote-sync/config_edits/DMS=true ✅ ✅ ✅
TestAccept/bundle/config-remote-sync/formatting_preserved/DMS= ✅ ✅ ✅
TestAccept/bundle/config-remote-sync/formatting_preserved/DMS=true ✅ ✅ ✅
TestAccept/bundle/config-remote-sync/job_fields/DMS= ✅ ✅ ✅
TestAccept/bundle/config-remote-sync/job_fields/DMS=true ✅ ✅ ✅
TestAccept/bundle/config-remote-sync/multiple_files/DMS= ✅ ✅ ✅
TestAccept/bundle/config-remote-sync/multiple_files/DMS=true ✅ ✅ ✅
TestAccept/bundle/config-remote-sync/whitespace_only_lines/DMS= ✅ ❌ ✅
TestAccept/bundle/config-remote-sync/whitespace_only_lines/DMS=true ✅ ❌ ✅
TestAccept/bundle/config-remote-sync/whitespace_only_lines/DMS=: branch ✅ | main (dccdf47) ❌ | latest (v1.28.0) ✅

main (dccdf47):

acceptance_test.go:1402: Diff:
        --- bundle/config-remote-sync/whitespace_only_lines/output.txt
        +++ /tmp/TestAcceptbundleconfig-remote-syncwhitespace_only_linesDMS=392782997/002/output.txt
        @@ -16,22 +16,29 @@
         >>> diff.py databricks.yml.backup databricks.yml
         --- databricks.yml.backup
         +++ databricks.yml
        -@@ -12,5 +12,6 @@
        +@@ -12,5 +12,9 @@
                      node_type_id: [NODE_TYPE_ID]
                      num_workers: 1
         -            spark_env_vars: null
         +            spark_env_vars:
        -+              BANNER: "line one\n    \nline three"
        ++              BANNER: |-
        ++                line one
        ++
        ++                line three
                tasks:
                  - task_key: main
         
         >>> [CLI] bundle validate -o json
        -json.resources.jobs.my_job.job_clusters[0].new_cluster.spark_env_vars.BANNER = "line one\n    \nline three";
        +json.resources.jobs.my_job.job_clusters[0].new_cluster.spark_env_vars.BANNER = "line one\n\nline three";
         
         >>> [CLI] bundle config-remote-sync --save
        -No changes detected.
        +Detected changes in 1 resource(s):
         
        +Resource: resources.jobs.my_job
        +  job_clusters[job_cluster_key='main'].new_cluster.spark_env_vars['BANNER']: replace
         
        +
        +
         >>> [CLI] bundle config-remote-sync --save
         Detected changes in 1 resource(s):
TestAccept/bundle/config-remote-sync/whitespace_only_lines/DMS=true: branch ✅ | main (dccdf47) ❌ | latest (v1.28.0) ✅

main (dccdf47):

acceptance_test.go:1402: Diff:
        --- bundle/config-remote-sync/whitespace_only_lines/output.txt
        +++ /tmp/TestAcceptbundleconfig-remote-syncwhitespace_only_linesDMS=t936690613/002/output.txt
        @@ -16,22 +16,29 @@
         >>> diff.py databricks.yml.backup databricks.yml
         --- databricks.yml.backup
         +++ databricks.yml
        -@@ -12,5 +12,6 @@
        +@@ -12,5 +12,9 @@
                      node_type_id: [NODE_TYPE_ID]
                      num_workers: 1
         -            spark_env_vars: null
         +            spark_env_vars:
        -+              BANNER: "line one\n    \nline three"
        ++              BANNER: |-
        ++                line one
        ++
        ++                line three
                tasks:
                  - task_key: main
         
         >>> [CLI] bundle validate -o json
        -json.resources.jobs.my_job.job_clusters[0].new_cluster.spark_env_vars.BANNER = "line one\n    \nline three";
        +json.resources.jobs.my_job.job_clusters[0].new_cluster.spark_env_vars.BANNER = "line one\n\nline three";
         
         >>> [CLI] bundle config-remote-sync --save
        -No changes detected.
        +Detected changes in 1 resource(s):
         
        +Resource: resources.jobs.my_job
        +  job_clusters[job_cluster_key='main'].new_cluster.spark_env_vars['BANNER']: replace
         
        +
        +
         >>> [CLI] bundle config-remote-sync --save
         Detected changes in 1 resource(s):

func appendBlockScalarBlanks(result, blanks []string, keepTabLines bool) []string {
for _, blank := range blanks {
if !keepTabLines || !strings.HasSuffix(blank, "\t") {
blank = ""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

ilyakuz-db and others added 3 commits November 27, 2026 16:49
…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 andrewnester left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space-only lines in untouched block scalars are still emptied on every save, which changes those values.

@ilyakuz-db

Copy link
Copy Markdown
Contributor Author

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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

DABs DABs related issues factory-generated

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants