From 4baded2aacd67162334558035f54ca931e5ef2a4 Mon Sep 17 00:00:00 2001 From: Ole Herman Schumacher Elgesem Date: Wed, 22 Apr 2026 00:07:32 +0200 Subject: [PATCH] cfengine format: Fixed newline issue when mixing single line promises with multi line promises Co-authored-by: Claude Opus 4.6 (1M context) Signed-off-by: Ole Herman Schumacher Elgesem --- src/cfengine_cli/format.py | 5 +++ tests/format/009_single_line.expected.cf | 39 ++++++++++++++++++++++++ tests/format/009_single_line.input.cf | 39 ++++++++++++++++++++++++ 3 files changed, 83 insertions(+) diff --git a/src/cfengine_cli/format.py b/src/cfengine_cli/format.py index 3ff77b4..bb13648 100644 --- a/src/cfengine_cli/format.py +++ b/src/cfengine_cli/format.py @@ -437,6 +437,11 @@ def can_single_line_promise(node: Node, indent: int, line_length: int) -> bool: next_sib = node.next_named_sibling while next_sib and next_sib.type == "macro": next_sib = next_sib.next_named_sibling + + if not attrs and not _has_stakeholder(children): + # Promises without attributes and without stakeholder are + # always single line + return True if len(attrs) > 1: # We always want to multiline a promise with multiple attributes # even if it would fit on one line, i.e this should be split: diff --git a/tests/format/009_single_line.expected.cf b/tests/format/009_single_line.expected.cf index c17129c..915a621 100644 --- a/tests/format/009_single_line.expected.cf +++ b/tests/format/009_single_line.expected.cf @@ -17,3 +17,42 @@ bundle agent main "libltdl7" package_policy => "delete"; "libltdl-dev" package_policy => "delete"; } + +bundle agent mix +{ + reports: + DEBUG|DEBUG_cfe_internal_cleanup_agent_reports:: + "DEBUG $(this.bundle): Size of '$(files)' = '$(reports_size[$(files)])'"; + "DEBUG $(this.bundle): Size of all reports = '$(total_report_size)'"; + + "DEBUG $(this.bundle): Client history purge triggered" + if => "cfe_internal_purge_reports"; + + "DEBUG $(this.bundle): Size of '$(files)' = '$(reports_size[$(files)])'"; + "DEBUG $(this.bundle): Size of all reports = '$(total_report_size)'"; + "DEBUG $(this.bundle): Purge threshold = '$(def.max_client_history_size)'"; + + "DEBUG $(this.bundle): Client history purge triggered" + if => "cfe_internal_purge_reports"; + + "DEBUG $(this.bundle): Size of '$(files)' = '$(reports_size[$(files)])'"; + "DEBUG $(this.bundle): Size of all reports = '$(total_report_size)'"; + "DEBUG $(this.bundle): Purge threshold = '$(def.max_client_history_size)'"; + "DEBUG $(this.bundle): Size of all reports = '$(total_report_size)'"; + "DEBUG $(this.bundle): Purge threshold = '$(def.max_client_history_size)'"; + + "DEBUG $(this.bundle): Client history purge triggered" + if => "cfe_internal_purge_reports"; + + "DEBUG $(this.bundle): Client history purge triggered" + if => "cfe_internal_purge_reports"; + + "DEBUG $(this.bundle): Client history purge triggered" + if => "cfe_internal_purge_reports"; + + "DEBUG $(this.bundle): Size of '$(files)' = '$(reports_size[$(files)])'"; + "DEBUG $(this.bundle): Size of all reports = '$(total_report_size)'"; + "DEBUG $(this.bundle): Purge threshold = '$(def.max_client_history_size)'"; + "DEBUG $(this.bundle): Size of all reports = '$(total_report_size)'"; + "DEBUG $(this.bundle): Purge threshold = '$(def.max_client_history_size)'"; +} diff --git a/tests/format/009_single_line.input.cf b/tests/format/009_single_line.input.cf index b22965d..d967cfa 100644 --- a/tests/format/009_single_line.input.cf +++ b/tests/format/009_single_line.input.cf @@ -35,3 +35,42 @@ bundle agent main "libltdl-dev" package_policy => "delete"; } + +bundle agent mix +{ +reports: +DEBUG|DEBUG_cfe_internal_cleanup_agent_reports:: +"DEBUG $(this.bundle): Size of '$(files)' = '$(reports_size[$(files)])'"; +"DEBUG $(this.bundle): Size of all reports = '$(total_report_size)'"; + +"DEBUG $(this.bundle): Client history purge triggered" + if => "cfe_internal_purge_reports"; + +"DEBUG $(this.bundle): Size of '$(files)' = '$(reports_size[$(files)])'"; +"DEBUG $(this.bundle): Size of all reports = '$(total_report_size)'"; +"DEBUG $(this.bundle): Purge threshold = '$(def.max_client_history_size)'"; + +"DEBUG $(this.bundle): Client history purge triggered" + if => "cfe_internal_purge_reports"; + +"DEBUG $(this.bundle): Size of '$(files)' = '$(reports_size[$(files)])'"; +"DEBUG $(this.bundle): Size of all reports = '$(total_report_size)'"; +"DEBUG $(this.bundle): Purge threshold = '$(def.max_client_history_size)'"; +"DEBUG $(this.bundle): Size of all reports = '$(total_report_size)'"; +"DEBUG $(this.bundle): Purge threshold = '$(def.max_client_history_size)'"; + +"DEBUG $(this.bundle): Client history purge triggered" + if => "cfe_internal_purge_reports"; + +"DEBUG $(this.bundle): Client history purge triggered" + if => "cfe_internal_purge_reports"; + +"DEBUG $(this.bundle): Client history purge triggered" + if => "cfe_internal_purge_reports"; + +"DEBUG $(this.bundle): Size of '$(files)' = '$(reports_size[$(files)])'"; +"DEBUG $(this.bundle): Size of all reports = '$(total_report_size)'"; +"DEBUG $(this.bundle): Purge threshold = '$(def.max_client_history_size)'"; +"DEBUG $(this.bundle): Size of all reports = '$(total_report_size)'"; +"DEBUG $(this.bundle): Purge threshold = '$(def.max_client_history_size)'"; +}