From 4db463cf14c96060d7b8cc7d6eeb942bb16294be Mon Sep 17 00:00:00 2001 From: Matthew Watson Date: Wed, 1 Jul 2026 16:04:00 +0100 Subject: [PATCH 1/2] Fix `expected` matcher never populating expected_ in GenericAnalyzer The `expected` parameter branch in GenericAnalyzer::init only pre-seeds the base-class items_ map via addItem(); it never populates the expected_ vector. But expected_ is what the initialisation guard, match() and report() all read, so an analyzer whose only matcher is `expected`: * fails to initialise ("was not initialized with any way of checking diagnostics"), which leaves its AnalyzerGroup with no analyzers ("Group '' doesn't contain any analyzers, can't match"), and * never matches incoming statuses even when paired with another matcher, since match() iterates the empty expected_. This is a regression from the ROS 1 implementation, which populated expected_ via getParamVals(expected, expected_) before creating the pre-seeded items. Restore the expected_ population alongside the existing addItem() loop. Signed-off-by: Matthew Watson --- diagnostic_aggregator/src/generic_analyzer.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/diagnostic_aggregator/src/generic_analyzer.cpp b/diagnostic_aggregator/src/generic_analyzer.cpp index 3965b226d..580b6c4a7 100644 --- a/diagnostic_aggregator/src/generic_analyzer.cpp +++ b/diagnostic_aggregator/src/generic_analyzer.cpp @@ -113,7 +113,8 @@ bool GenericAnalyzer::init( RCLCPP_DEBUG( rclcpp::get_logger("GenericAnalyzer"), "GenericAnalyzer '%s' found expected: %s", nice_name_.c_str(), pvalue.value_to_string().c_str()); - for (auto exp : pvalue.as_string_array()) { + expected_ = pvalue.as_string_array(); + for (const auto & exp : expected_) { auto item = std::make_shared(exp); this->addItem(exp, item); } From e89dab8609012eb13ca8132c00a3e4c240e028b2 Mon Sep 17 00:00:00 2001 From: Matthew Watson Date: Wed, 1 Jul 2026 16:31:00 +0100 Subject: [PATCH 2/2] Add regression test for the GenericAnalyzer expected matcher Adds a create-analyzers launch test with an analyzer whose only matcher is `expected`. The success-only "Initialized ... with path '/ExpectedOnly'" log line is asserted, so the test fails (assertWaitFor times out on "not initialized with any way of checking diagnostics") without the fix and passes with it. Verified: fails against the released plugin, passes with the fix applied. Signed-off-by: Matthew Watson --- diagnostic_aggregator/CMakeLists.txt | 3 ++- .../test/expected_only_analyzer.yaml | 11 +++++++++++ .../expected_output/create_expected_only_analyzer.txt | 2 ++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 diagnostic_aggregator/test/expected_only_analyzer.yaml create mode 100644 diagnostic_aggregator/test/expected_output/create_expected_only_analyzer.txt diff --git a/diagnostic_aggregator/CMakeLists.txt b/diagnostic_aggregator/CMakeLists.txt index 2af6b8673..87e745930 100644 --- a/diagnostic_aggregator/CMakeLists.txt +++ b/diagnostic_aggregator/CMakeLists.txt @@ -89,7 +89,8 @@ if(BUILD_TESTING) "primitive_analyzers" "all_analyzers" "analyzer_group" - "empty_root_path") + "empty_root_path" + "expected_only_analyzer") foreach(test_name ${create_analyzers_tests}) file(TO_CMAKE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/test/${test_name}.yaml" PARAMETER_FILE) diff --git a/diagnostic_aggregator/test/expected_only_analyzer.yaml b/diagnostic_aggregator/test/expected_only_analyzer.yaml new file mode 100644 index 000000000..c09456524 --- /dev/null +++ b/diagnostic_aggregator/test/expected_only_analyzer.yaml @@ -0,0 +1,11 @@ +/**: + ros__parameters: + log_level: debug + # Regression test for the `expected` matcher: an analyzer whose ONLY matcher + # is `expected` must still initialise. Prior to the fix this failed because + # the `expected` parameter populated the base-class items_ map but never the + # expected_ vector that the init guard checks, so the analyzer was dropped. + expected_only: + type: 'diagnostic_aggregator/GenericAnalyzer' + path: ExpectedOnly + expected: [ 'some/expected/status' ] diff --git a/diagnostic_aggregator/test/expected_output/create_expected_only_analyzer.txt b/diagnostic_aggregator/test/expected_output/create_expected_only_analyzer.txt new file mode 100644 index 000000000..9e56ce19c --- /dev/null +++ b/diagnostic_aggregator/test/expected_output/create_expected_only_analyzer.txt @@ -0,0 +1,2 @@ +diagnostic_aggregator/GenericAnalyzer 'ExpectedOnly' +/ExpectedOnly