Skip to content

fix(connect): keep comments after the connect-config extension on clean - #449

Closed
avocado-connect[bot] wants to merge 1 commit into
mainfrom
connect/mention-7244627265
Closed

avocado-connect[bot] wants to merge 1 commit into
mainfrom
connect/mention-7244627265

Conversation

@avocado-connect

Copy link
Copy Markdown

Issue

Fixes #447: connect clean deletes comments after the avocado-ext-connect-config block.

avocado connect clean removes the avocado-ext-connect-config extension definition. It also deleted the blank lines and comments after that definition. That means a comment above the next extension is lost. If connect-config is the last extension, a column-0 section header such as ## Runtimes is lost too. Expected: only the connect-config definition and its runtime entry are removed.

Root cause

remove_extension_definition (src/utils/config_edit.rs) moved the end of the block forward on every blank or comment line after the extension, at any indent. It stopped only at the next key. So everything between the last child line and the next key was deleted.

remove_runtime_extension_entry removes only the matching - avocado-ext-connect-config line, so it doesn't have this bug.

Fix

The block now ends at its last child line that is indented deeper than the extension key. A blank line or comment is part of the block only if a child line comes after it. Trailing blank lines and comments stay with whatever comes next. This is the same rule #443 uses for the top-level connect: block. Once #443 lands, the two loops could share one helper.

Reproduction

I ran avocado connect clean (main, 2342bc8) on the avocado.yaml from the issue.

Before, # Sensor support and the blank line before it were removed:

       hello: '*'
-  avocado-ext-connect-config:
-    types:
-    - confext
-    version: "0.1.0"
-    overlay: overlay
-
-  # Sensor support
   sensors:

After, only the extension definition is removed:

       hello: '*'
-  avocado-ext-connect-config:
-    types:
-    - confext
-    version: "0.1.0"
-    overlay: overlay
 
   # Sensor support
   sensors:

With connect-config as the last extension, the ## / ## Runtimes / ## header used to be deleted. It's now kept.

I parsed the before and after files, and they give the same config: the same extensions and the same runtime lists. The bug changed only the text of avocado.yaml, never what install, build or provision see.

Tests

  • Added test_remove_connect_config_extension_keeps_comment_above_next_extension and test_remove_connect_config_extension_keeps_header_after_last_extension. Both fail on main and pass with this fix. Both check the exact output and that it still parses as YAML.
  • cargo fmt --check, cargo clippy --all-targets -- -D warnings and the full cargo test pass.

Hardware

The jetson-orin-nano isn't set up as a test board on the bench. I'll post the Thor board result on #447 and as a rubicon / jetson-agx-thor check on this commit.

Please squash merge.

remove_extension_definition counted every blank line and comment after
avocado-ext-connect-config as part of its block, so connect clean deleted
a comment above the next extension, or a column-0 section header after the
last one. The block now ends at its last child line; trailing blanks and
comments stay with what follows.

Fixes #447

Copilot AI 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.

🟢 Approval recommended

No active review issues remain for the configuration-cleanup change that preserves trailing comments and blank lines.

No open issues 🎉

What changed in this PR

Fixes #447 by preserving comments and blank lines after avocado-ext-connect-config when avocado connect clean edits avocado.yaml.

Changes:

  • Ends extension deletion at the last nonblank, non-comment child line, preserving trailing comments and spacing.
  • Adds regression tests for comments above the next extension and section headers after the last extension, checking exact output and YAML validity.
  • Documents the fix in the changelog.
File Description
src/​utils/​config_edit.rs Adjusts the deletion boundary and adds two comment-preservation regression tests.
CHANGELOG.md Adds an unreleased entry describing the cleanup fix.

Review effort: Balanced

@nicksinas

Copy link
Copy Markdown
Contributor

duplicate of #448

@nicksinas nicksinas closed this Nov 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

connect clean deletes comments after the avocado-ext-connect-config block

2 participants