From c829c4cf5a79e88db49fdc4e3a8c10f69bd13158 Mon Sep 17 00:00:00 2001 From: "Jokob @NetAlertX" <96159884+jokob-sk@users.noreply.github.com> Date: Mon, 25 May 2026 11:32:59 +0000 Subject: [PATCH] Enhance node name extraction logic to accurately classify file formats for PUSH and PULL modes --- test/plugins/test_sync_protocol.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/test/plugins/test_sync_protocol.py b/test/plugins/test_sync_protocol.py index c765394f..ac2da79c 100644 --- a/test/plugins/test_sync_protocol.py +++ b/test/plugins/test_sync_protocol.py @@ -70,15 +70,17 @@ def _get_data(api_token, node_url): def _node_name_from_filename(file_name: str) -> str: """Mirror of the node-name extraction in sync.main() (Mode 3). - Real file formats produced by the system: - PUSH (post-decode): last_result.PLUGIN.decoded.NodeName.N.log - — split on '.decoded.' marker, strip .N.log with rsplit from the right - PULL: last_result.NodeName.log - — strip 'last_result.' prefix and '.log' suffix + PUSH shape: last_result.PLUGIN.(decoded|encoded).NodeName.N.log + — marker present AND the second-to-last segment (before .log) is a digit + PULL shape: last_result.NodeName.log + — no marker, or marker present but no digit counter + (e.g. node name is 'office.encoded.lab') Both forms handle dots anywhere in PLUGIN or NodeName. """ - if '.decoded.' in file_name or '.encoded.' in file_name: + marker_present = '.decoded.' in file_name or '.encoded.' in file_name + is_push = marker_present and file_name.rsplit('.', 2)[1].isdigit() + if is_push: marker = '.decoded.' if '.decoded.' in file_name else '.encoded.' _, after = file_name.split(marker, 1) return after.rsplit('.', 2)[0] @@ -366,6 +368,12 @@ class TestNodeNameExtraction: "last_result.A.B.decoded.x.y.z.1.log" ) == "x.y.z" + def test_pull_with_encoded_in_node_name(self): + # Regression: PULL file whose node name contains '.encoded.' must NOT + # be mis-classified as a PUSH artifact (no digit counter → PULL branch). + assert _node_name_from_filename("last_result.office.encoded.lab.log") == "office.encoded.lab" + assert _node_name_from_filename("last_result.site.decoded.backup.log") == "site.decoded.backup" + # =========================================================================== # CurrentScan candidates filter (Mode 3 – RECEIVE)