From 2a7fade341a08577255b9a0ca100576bc832b393 Mon Sep 17 00:00:00 2001 From: "Bernd (Hermes)" Date: Sat, 1 Aug 2026 21:14:31 +0200 Subject: [PATCH] fix: align PID-Sentinel tests with gateway_pid detection_source Mock _check_gateway_pid_alive=False in 7 tests that test secondary/ tertiary/quaternary detection paths, since the PID-Sentinel (PRIMARY) now always returns True under pytest (parent process exists). Production-Impact: none (test-only change) --- plugin/archivar/tests/test_presence_engine.py | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/plugin/archivar/tests/test_presence_engine.py b/plugin/archivar/tests/test_presence_engine.py index 341c583..7df3412 100644 --- a/plugin/archivar/tests/test_presence_engine.py +++ b/plugin/archivar/tests/test_presence_engine.py @@ -1362,7 +1362,8 @@ class TestDetectionTimerPgrepSelfExclude: own_pid = os.getpid() # Mock subprocess.run: pgrep returns only our own PID - with patch('plugin.archivar.presence_engine.subprocess.run') as mock_run: + with patch('plugin.archivar.presence_engine.subprocess.run') as mock_run, \ + patch.object(DetectionTimer, '_check_gateway_pid_alive', return_value=False): mock_run.return_value = MagicMock( stdout=f"{own_pid}\n", stderr="", @@ -1425,7 +1426,8 @@ class TestDetectionTimerOnChangeCallback: MagicMock(stdout=f"{own_pid}\n", stderr="", returncode=0), ] - with patch('plugin.archivar.presence_engine.subprocess.run') as mock_run: + with patch('plugin.archivar.presence_engine.subprocess.run') as mock_run, \ + patch.object(DetectionTimer, '_check_gateway_pid_alive', return_value=False): mock_run.side_effect = mock_results dt = DetectionTimer( @@ -2088,7 +2090,8 @@ class TestDetectionTimerPluginState: }) own_pid = os.getpid() - with patch('plugin.archivar.presence_engine.subprocess.run') as mock_run: + with patch('plugin.archivar.presence_engine.subprocess.run') as mock_run, \ + patch.object(DetectionTimer, '_check_gateway_pid_alive', return_value=False): mock_run.return_value = MagicMock( stdout=f"{own_pid}\n", stderr="", @@ -2215,7 +2218,8 @@ class TestDetectionSourceTelemetry: detection_interval=0.1, plugin_state_path=state_path, ) - dt.check() + with patch.object(DetectionTimer, '_check_gateway_pid_alive', return_value=False): + dt.check() assert routing_telemetry.heartbeat_detection_source == "plugin_state" def test_detection_source_none_when_inactive(self): @@ -2226,7 +2230,8 @@ class TestDetectionSourceTelemetry: routing_telemetry.heartbeat_detection_source = "none" own_pid = os.getpid() - with patch('plugin.archivar.presence_engine.subprocess.run') as mock_run: + with patch('plugin.archivar.presence_engine.subprocess.run') as mock_run, \ + patch.object(DetectionTimer, '_check_gateway_pid_alive', return_value=False): mock_run.return_value = MagicMock( stdout=f"{own_pid}\n", stderr="", @@ -2248,7 +2253,8 @@ class TestDetectionSourceTelemetry: routing_telemetry.heartbeat_detection_source = "none" own_pid = os.getpid() - with patch('plugin.archivar.presence_engine.subprocess.run') as mock_run: + with patch('plugin.archivar.presence_engine.subprocess.run') as mock_run, \ + patch.object(DetectionTimer, '_check_gateway_pid_alive', return_value=False): mock_run.return_value = MagicMock( stdout=f"{own_pid}\n99999\n", stderr="", @@ -2276,7 +2282,8 @@ class TestDetectionSourceTelemetry: gw_path = f.name try: - with patch('plugin.archivar.presence_engine.subprocess.run') as mock_run: + with patch('plugin.archivar.presence_engine.subprocess.run') as mock_run, \ + patch.object(DetectionTimer, '_check_gateway_pid_alive', return_value=False): dt = DetectionTimer( gateway_state_path=gw_path, detection_interval=0.1,