Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed
- **`avocado connect clean` keeps comments after the connect-config
extension.** Removing `avocado-ext-connect-config` deleted the blank lines
and comments that followed it, such as a comment above the next extension
or a section header after the last one. They now stay with what comes next.

## [1.2.0] - 2026-11-19

### Added
Expand Down
98 changes: 96 additions & 2 deletions src/utils/config_edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -989,11 +989,13 @@ fn remove_extension_definition(content: &str, ext_name: &str) -> Result<String>
.ok_or_else(|| anyhow::anyhow!("Extension '{ext_name}' not found in avocado.yaml"))?;
let ext_def_indent = leading_spaces(lines[ext_line]);

// Find end of this extension's block (all lines indented deeper)
// Find end of this extension's block: its last line indented deeper.
// Blank lines and comments after that line belong to whatever comes
// next (a comment above the next extension, a section header), so they
// only join the block when a deeper child line follows them.
let mut block_end = ext_line + 1;
for (i, line) in lines.iter().enumerate().skip(ext_line + 1) {
if line.trim().is_empty() || line.trim().starts_with('#') {
block_end = i + 1;
continue;
}
let indent = leading_spaces(line);
Expand Down Expand Up @@ -2087,6 +2089,98 @@ extensions:
assert!(result.contains("- avocado-ext-tunnels"));
}

#[test]
fn test_remove_connect_config_extension_keeps_comment_above_next_extension() {
let config = r#"extensions:
app:
packages:
hello: '*'
avocado-ext-connect-config:
types:
- confext
version: "0.1.0"
overlay: overlay

# Sensor support
sensors:
packages:
i2c-tools: '*'

##
## Runtimes
##
runtimes:
dev:
extensions:
- app
- avocado-ext-connect-config
- sensors
"#;
let expected = r#"extensions:
app:
packages:
hello: '*'

# Sensor support
sensors:
packages:
i2c-tools: '*'

##
## Runtimes
##
runtimes:
dev:
extensions:
- app
- sensors
"#;
let (result, changed) = remove_connect_config_extension_in_yaml(config, "dev").unwrap();
assert!(changed);
assert_eq!(result, expected);
let _: serde_yaml::Value = serde_yaml::from_str(&result).unwrap();
}

#[test]
fn test_remove_connect_config_extension_keeps_header_after_last_extension() {
let config = r#"extensions:
sensors:
packages:
i2c-tools: '*'
avocado-ext-connect-config:
types:
- confext
version: "0.1.0"
overlay: overlay

##
## Runtimes
##
runtimes:
dev:
extensions:
- sensors
- avocado-ext-connect-config
"#;
let expected = r#"extensions:
sensors:
packages:
i2c-tools: '*'

##
## Runtimes
##
runtimes:
dev:
extensions:
- sensors
"#;
let (result, changed) = remove_connect_config_extension_in_yaml(config, "dev").unwrap();
assert!(changed);
assert_eq!(result, expected);
let _: serde_yaml::Value = serde_yaml::from_str(&result).unwrap();
}

#[test]
fn test_remove_connect_config_extension_not_present() {
let config = r#"runtimes:
Expand Down
Loading