fix(presence): pgrep Scanner erkennt hermes-Binary ohne .py-Endung (V8.9)
Bug: _pgrep_hermes_subagents() verlangte arg.endswith('.py') fuer
Python-gestartete hermes-Prozesse. Das schlug fehl bei argv wie
['python3', '/home/bernd/.local/bin/hermes', 'chat', '--profile', 'rainer']
weil 'hermes' ein Binary/Script ohne .py-Endung ist.
Fix: os.path.basename(arg) == 'hermes' statt
'hermes' in basename AND endswith('.py').
Tests: 5 neue Tests in TestPgrepArgvParsing:
- hermes-Binary in argv (Rainers realer Fall)
- generischer Pfad /pfad/zu/hermes
- direktes argv0='hermes'
- -m hermes_cli.main (bestehender Pfad intakt)
- non-hermes Python wird nicht gematcht
This commit is contained in:
@@ -1649,7 +1649,7 @@ class DetectionTimer:
|
||||
if argv[i + 1].startswith("hermes_cli"):
|
||||
is_hermes_python = True
|
||||
break
|
||||
elif "hermes" in os.path.basename(arg) and arg.endswith(".py"):
|
||||
elif os.path.basename(arg) == "hermes":
|
||||
is_hermes_python = True
|
||||
break
|
||||
if is_hermes_python:
|
||||
|
||||
@@ -1404,6 +1404,89 @@ class TestDetectionTimerOnChangeCallback:
|
||||
assert callback_results[1] is False
|
||||
|
||||
|
||||
class TestPgrepArgvParsing:
|
||||
"""V8.9: _pgrep_hermes_subagents() argv-Parsing — erkennt hermes-Binary ohne .py-Endung."""
|
||||
|
||||
def test_hermes_binary_in_argv(self):
|
||||
"""argv = ['python3', '/home/bernd/.local/bin/hermes', 'chat', '--profile', 'rainer'] → match."""
|
||||
from plugin.archivar.presence_engine import DetectionTimer
|
||||
|
||||
# Simuliere /proc/<pid>/cmdline
|
||||
cmdline = b"python3\x00/home/bernd/.local/bin/hermes\x00chat\x00--profile\x00rainer\x00"
|
||||
fake_pid = 99999
|
||||
|
||||
with patch("os.listdir", return_value=[str(fake_pid)]), \
|
||||
patch("os.getpid", return_value=1), \
|
||||
patch.object(DetectionTimer, "_read_gateway_pid", return_value=None):
|
||||
with patch("builtins.open", create=True) as mock_open:
|
||||
mock_open.return_value.__enter__.return_value.read.return_value = cmdline
|
||||
result = DetectionTimer._pgrep_hermes_subagents()
|
||||
assert result == 1, f"Expected 1, got {result}"
|
||||
|
||||
def test_hermes_binary_generic_path(self):
|
||||
"""argv = ['python3', '/pfad/zu/hermes', 'chat', '--profile', 'miguel'] → match."""
|
||||
from plugin.archivar.presence_engine import DetectionTimer
|
||||
|
||||
cmdline = b"python3\x00/pfad/zu/hermes\x00chat\x00--profile\x00miguel\x00"
|
||||
fake_pid = 99998
|
||||
|
||||
with patch("os.listdir", return_value=[str(fake_pid)]), \
|
||||
patch("os.getpid", return_value=1), \
|
||||
patch.object(DetectionTimer, "_read_gateway_pid", return_value=None):
|
||||
with patch("builtins.open", create=True) as mock_open:
|
||||
mock_open.return_value.__enter__.return_value.read.return_value = cmdline
|
||||
result = DetectionTimer._pgrep_hermes_subagents()
|
||||
assert result == 1, f"Expected 1, got {result}"
|
||||
|
||||
def test_hermes_direct_binary(self):
|
||||
"""argv = ['hermes', 'chat', '--profile', 'default'] → match (argv0 == 'hermes')."""
|
||||
from plugin.archivar.presence_engine import DetectionTimer
|
||||
|
||||
cmdline = b"hermes\x00chat\x00--profile\x00default\x00"
|
||||
fake_pid = 99997
|
||||
|
||||
with patch("os.listdir", return_value=[str(fake_pid)]), \
|
||||
patch("os.getpid", return_value=1), \
|
||||
patch.object(DetectionTimer, "_read_gateway_pid", return_value=None):
|
||||
with patch("builtins.open", create=True) as mock_open:
|
||||
mock_open.return_value.__enter__.return_value.read.return_value = cmdline
|
||||
result = DetectionTimer._pgrep_hermes_subagents()
|
||||
assert result == 1, f"Expected 1, got {result}"
|
||||
|
||||
def test_hermes_py_script_still_works(self):
|
||||
"""argv = ['python3', '/path/hermes.py', 'chat', '--profile', 'miguel'] → match (via -m check)."""
|
||||
from plugin.archivar.presence_engine import DetectionTimer
|
||||
|
||||
# .py-Skript wird nicht mehr über endswith('.py') erkannt,
|
||||
# aber '-m hermes_cli.main' funktioniert weiterhin.
|
||||
# Dieser Test stellt sicher, dass der -m-Pfad intakt ist.
|
||||
cmdline = b"python3\x00-m\x00hermes_cli.main\x00chat\x00--profile\x00miguel\x00"
|
||||
fake_pid = 99996
|
||||
|
||||
with patch("os.listdir", return_value=[str(fake_pid)]), \
|
||||
patch("os.getpid", return_value=1), \
|
||||
patch.object(DetectionTimer, "_read_gateway_pid", return_value=None):
|
||||
with patch("builtins.open", create=True) as mock_open:
|
||||
mock_open.return_value.__enter__.return_value.read.return_value = cmdline
|
||||
result = DetectionTimer._pgrep_hermes_subagents()
|
||||
assert result == 1, f"Expected 1, got {result}"
|
||||
|
||||
def test_non_hermes_python_not_matched(self):
|
||||
"""argv = ['python3', '/usr/bin/some_script.py', 'chat', '--profile'] → NO match."""
|
||||
from plugin.archivar.presence_engine import DetectionTimer
|
||||
|
||||
cmdline = b"python3\x00/usr/bin/some_script.py\x00chat\x00--profile\x00default\x00"
|
||||
fake_pid = 99995
|
||||
|
||||
with patch("os.listdir", return_value=[str(fake_pid)]), \
|
||||
patch("os.getpid", return_value=1), \
|
||||
patch.object(DetectionTimer, "_read_gateway_pid", return_value=None):
|
||||
with patch("builtins.open", create=True) as mock_open:
|
||||
mock_open.return_value.__enter__.return_value.read.return_value = cmdline
|
||||
result = DetectionTimer._pgrep_hermes_subagents()
|
||||
assert result == 0, f"Expected 0, got {result}"
|
||||
|
||||
|
||||
class TestPulseControllerStartWithoutDdp:
|
||||
"""P1-1: PulseController.start() ohne DDP-Bindung → log warning, kein Crash."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user