From 5c59e039e178941551d5d00b061ff5830792118e Mon Sep 17 00:00:00 2001 From: Ole Herman Schumacher Elgesem Date: Wed, 6 May 2026 15:47:58 +0200 Subject: [PATCH 1/2] cfengine lint: Added check for wrong promise block type Co-authored-by: Claude Opus 4.7 (1M context) Signed-off-by: Ole Herman Schumacher Elgesem --- src/cfengine_cli/lint.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/cfengine_cli/lint.py b/src/cfengine_cli/lint.py index 0a75992..c4e2121 100644 --- a/src/cfengine_cli/lint.py +++ b/src/cfengine_cli/lint.py @@ -609,6 +609,11 @@ def _lint_block_type(node: Node, state: State, location: str, syntax_data: Synta f"Error: Bundle type must be one of ({', '.join(syntax_data.BUILTIN_BUNDLE_TYPES)}), not '{_text(node)}' {location}", node, ) + if node.type == "promise_block_type" and _text(node) != "agent": + raise ValidationError( + f"Error: Promise type must be 'agent', not '{_text(node)}' {location}", + node, + ) def _lint_block_name(node: Node, state: State, location: str, syntax_data: SyntaxData): From eb3b6c244a9c843631de565551fdee3211a004c0 Mon Sep 17 00:00:00 2001 From: Ole Herman Schumacher Elgesem Date: Wed, 6 May 2026 15:51:13 +0200 Subject: [PATCH 2/2] tests: Renamed and expanded block type test Co-authored-by: Claude Opus 4.7 (1M context) Signed-off-by: Ole Herman Schumacher Elgesem --- tests/lint/004_block_type.cf | 11 +++++++++++ tests/lint/004_block_type.expected.txt | 11 +++++++++++ tests/lint/004_block_type.x.cf | 11 +++++++++++ tests/lint/004_bundle_type.cf | 5 ----- tests/lint/004_bundle_type.expected.txt | 6 ------ tests/lint/004_bundle_type.x.cf | 5 ----- 6 files changed, 33 insertions(+), 16 deletions(-) create mode 100644 tests/lint/004_block_type.cf create mode 100644 tests/lint/004_block_type.expected.txt create mode 100644 tests/lint/004_block_type.x.cf delete mode 100644 tests/lint/004_bundle_type.cf delete mode 100644 tests/lint/004_bundle_type.expected.txt delete mode 100644 tests/lint/004_bundle_type.x.cf diff --git a/tests/lint/004_block_type.cf b/tests/lint/004_block_type.cf new file mode 100644 index 0000000..6fc147e --- /dev/null +++ b/tests/lint/004_block_type.cf @@ -0,0 +1,11 @@ +bundle common my_bundle +{ + vars: + "x" string => "value"; +} + +promise agent my_promise_type +{ + path => "/bin/true"; + interpreter => "/bin/bash"; +} diff --git a/tests/lint/004_block_type.expected.txt b/tests/lint/004_block_type.expected.txt new file mode 100644 index 0000000..f486b08 --- /dev/null +++ b/tests/lint/004_block_type.expected.txt @@ -0,0 +1,11 @@ + +bundle notavalidtype my_bundle + ^-----------^ +Error: Bundle type must be one of (agent, common, edit_line, edit_xml, monitor, server), not 'notavalidtype' at tests/lint/004_block_type.x.cf:1:8 + + +promise server my_promise_type + ^----^ +Error: Promise type must be 'agent', not 'server' at tests/lint/004_block_type.x.cf:7:9 +FAIL: tests/lint/004_block_type.x.cf (2 errors) +Failure, 2 errors in total. diff --git a/tests/lint/004_block_type.x.cf b/tests/lint/004_block_type.x.cf new file mode 100644 index 0000000..3a2290e --- /dev/null +++ b/tests/lint/004_block_type.x.cf @@ -0,0 +1,11 @@ +bundle notavalidtype my_bundle +{ + reports: + "Hello"; +} + +promise server my_promise_type +{ + path => "/bin/true"; + interpreter => "/bin/bash"; +} diff --git a/tests/lint/004_bundle_type.cf b/tests/lint/004_bundle_type.cf deleted file mode 100644 index cff6057..0000000 --- a/tests/lint/004_bundle_type.cf +++ /dev/null @@ -1,5 +0,0 @@ -bundle common my_bundle -{ - vars: - "x" string => "value"; -} diff --git a/tests/lint/004_bundle_type.expected.txt b/tests/lint/004_bundle_type.expected.txt deleted file mode 100644 index b650af3..0000000 --- a/tests/lint/004_bundle_type.expected.txt +++ /dev/null @@ -1,6 +0,0 @@ - -bundle notavalidtype my_bundle - ^-----------^ -Error: Bundle type must be one of (agent, common, edit_line, edit_xml, monitor, server), not 'notavalidtype' at tests/lint/004_bundle_type.x.cf:1:8 -FAIL: tests/lint/004_bundle_type.x.cf (1 error) -Failure, 1 error in total. diff --git a/tests/lint/004_bundle_type.x.cf b/tests/lint/004_bundle_type.x.cf deleted file mode 100644 index 3503de6..0000000 --- a/tests/lint/004_bundle_type.x.cf +++ /dev/null @@ -1,5 +0,0 @@ -bundle notavalidtype my_bundle -{ - reports: - "Hello"; -}