Skip to content

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

Open
avocado-connect[bot] wants to merge 1 commit into
mainfrom
connect/issue-447
Open

avocado-connect[bot] wants to merge 1 commit into
mainfrom
connect/issue-447

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 from avocado.yaml. The report says it also deletes blank lines and comments that follow that block, such as a comment above the next extension, or a column-0 section header when connect-config is the last extension. Expected: only the block and its runtime list entry go away.

The bug is in a pure text edit of avocado.yaml, so it was reproduced and fixed with host unit tests and a run of the built binary. No board run: nothing on the device changes, and the edited file is byte-identical apart from the removed lines.

Root cause

remove_extension_definition (src/utils/config_edit.rs) found the end of the extension block by extending block_end over every blank or comment line, at any indent, until it hit a real line at the key's indent. Everything up to the next key was deleted with the block.

Fix

Same rule as #443 uses for top-level blocks:

  • The block ends at its last real child line (deeper than the key).
  • Comments indented deeper than the key right after that line still belong to the block (blank lines between them go too).
  • Anything else (blank lines, comments at the key's indent or column 0) stays with what follows.
  • When connect-config is the first extension, the blank lines after it are dropped too, so no blank line is left right under extensions:.

The other removal helpers were checked: remove_runtime_extension_entry and remove_packages_from_yaml drop only matching lines inside their range, so comments survive there. remove_connect_fields_in_yaml has the same loop and is fixed by #443.

Reproduction

Three new unit tests on the pure functions: a comment above the next extension stays; a column-0 ## header after the last extension stays (and an indented trailing comment inside the block goes with it); removing the first extension leaves no blank line under extensions:. The first two also parse the result as YAML.

Before (main):

test_remove_connect_config_extension_keeps_comment_above_next_extension --- FAILED
  left: "...hello: '*'\n  sensors:\n..."            # "# Sensor support" and the blank line gone
test_remove_connect_config_extension_keeps_header_after_last_extension --- FAILED
  left: "...hello: '*'\nruntimes:\n..."             # "## Runtimes" header gone
test result: FAILED. 3 passed; 2 failed

After:

test result: ok. 37 passed; 0 failed   (config_edit)

avocado connect clean (built from this branch) on the issue's example file:

   app:
     packages:
       hello: '*'
-  avocado-ext-connect-config:
-    types:
-    - confext
-    version: "0.1.0"
-    overlay: overlay
 
   # Sensor support
   sensors:
@@
   dev:
     extensions:
       - app
-      - avocado-ext-connect-config
       - sensors

cargo fmt, cargo clippy --all-targets -- -D warnings and the full cargo test pass locally.

Please squash merge (bot commits are unsigned; the squash commit is signed by GitHub).

remove_extension_definition counted every blank and comment line after
the extension as part of its block, at any indent, 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 real child line. Comments indented deeper
than the key right after it still go with the block; anything else stays
with the next key. When the extension is the first one, no blank line is
left under extensions:.

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.

🔵 Needs a closer look

Human judgment is needed to decide whether to waive Issue #447’s required Jetson before/after validation and Rubicon hardware status check, since the PR reports only host validation for this text-only fix.

No open issues 🎉

What changed in this PR

Fixes #447 by narrowing the extension block removed by avocado connect clean, preserving comments and spacing that belong to the following configuration.

Changes:

  • Preserves comments after the connect-config extension while removing its indented trailing comments and avoiding a blank line directly under extensions:.
  • Adds three regression tests covering next-extension comments, trailing section headers, and first-extension spacing.
  • Documents the fix in the changelog.
File Description
src/​utils/​config_edit.rs Adjusts extension-removal boundaries and adds regression tests, including YAML validity checks.
CHANGELOG.md Adds an unreleased entry describing comment preservation during connect clean.

Review effort: Balanced

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

1 participant