fix(install.sh): --update-only kopiert an korrekten pipx-venv-Pfad + Cleanup
Root Cause: install.sh --update-only kopierte Plugin-Dateien nach ~/.hermes/plugins/rocketchat/, aber der Gateway lädt Plugins aus dem pipx-venv site-packages/plugins/platforms/rocketchat/. Änderungen: - systemd drop-in PYTHONPATH: hardcoded python3.13 → dynamisch via find_site_packages() mit Fallback - deploy_plugin() + --update-only: alte tools.py löschen (wurde zu rc_tools.py umbenannt, verhindert Shadowing) - --update-only: stale ~/.hermes/plugins/rocketchat/ bereinigen (alter falscher Pfad aus früheren Versionen) - Tests: restart_gateway-Funktion statt literal systemctl-String - Neue Tests: tools.py-Cleanup, stale-Pfad-Cleanup, kein hardcoded python3.13 143 tests passed, bash -n clean.
This commit is contained in:
@@ -139,12 +139,13 @@ class TestUpdateOnlyServiceRestart:
|
||||
"""Gateway-Dienst muss nach dem Update neu gestartet werden."""
|
||||
|
||||
def test_systemctl_restart_present(self):
|
||||
"""systemctl --user restart hermes-gateway ist im --update-only Block."""
|
||||
"""restart_gateway (oder systemctl restart) ist im --update-only Block."""
|
||||
content = _read_install_sh()
|
||||
update_section = _extract_update_only_section(content)
|
||||
|
||||
assert "systemctl --user restart hermes-gateway" in update_section, (
|
||||
f"systemctl restart fehlt im --update-only Block:\n{update_section}"
|
||||
# restart_gateway ist die Funktion, die systemctl --user restart kapselt
|
||||
assert "restart_gateway" in update_section, (
|
||||
f"restart_gateway fehlt im --update-only Block:\n{update_section}"
|
||||
)
|
||||
|
||||
def test_no_restart_flag_respected(self):
|
||||
@@ -158,15 +159,15 @@ class TestUpdateOnlyServiceRestart:
|
||||
)
|
||||
|
||||
def test_restart_after_deploy(self):
|
||||
"""systemctl restart kommt NACH deploy_plugin."""
|
||||
"""restart_gateway kommt NACH deploy_plugin."""
|
||||
content = _read_install_sh()
|
||||
update_section = _extract_update_only_section(content)
|
||||
|
||||
deploy_pos = update_section.find("deploy_plugin")
|
||||
restart_pos = update_section.find("systemctl --user restart hermes-gateway")
|
||||
restart_pos = update_section.find("restart_gateway")
|
||||
|
||||
assert restart_pos > deploy_pos, (
|
||||
f"restart ({restart_pos}) muss NACH deploy_plugin ({deploy_pos}) kommen"
|
||||
f"restart_gateway ({restart_pos}) muss NACH deploy_plugin ({deploy_pos}) kommen"
|
||||
)
|
||||
|
||||
|
||||
@@ -361,3 +362,113 @@ class TestDeployPluginCacheCleanup:
|
||||
assert "rm -rf" in func_body, (
|
||||
f"deploy_plugin() nutzt kein rm -rf für __pycache__:\n{func_body[:500]}"
|
||||
)
|
||||
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════════════════
|
||||
# Test 8: tools.py Cleanup (V8.6: rename tools.py → rc_tools.py)
|
||||
# ═══════════════════════════════════════════════════════════════════════════
|
||||
|
||||
|
||||
class TestToolsPyCleanup:
|
||||
"""Alte tools.py muss in deploy_plugin() und --update-only gelöscht werden."""
|
||||
|
||||
def test_deploy_plugin_removes_old_tools_py(self):
|
||||
"""deploy_plugin() löscht alte tools.py."""
|
||||
content = _read_install_sh()
|
||||
|
||||
match = re.search(
|
||||
r'deploy_plugin\(\)\s*\{.*?(?=\n\}\n\n#)',
|
||||
content,
|
||||
re.DOTALL,
|
||||
)
|
||||
assert match, "deploy_plugin()-Funktion nicht gefunden"
|
||||
func_body = match.group(0)
|
||||
|
||||
assert "tools.py" in func_body, (
|
||||
f"deploy_plugin() enthält keine tools.py-Bereinigung:\n{func_body[:500]}"
|
||||
)
|
||||
assert "rc_tools.py" in func_body, (
|
||||
f"deploy_plugin() erwähnt rc_tools.py nicht:\n{func_body[:500]}"
|
||||
)
|
||||
|
||||
def test_update_only_removes_old_tools_py(self):
|
||||
"""--update-only Block löscht alte tools.py."""
|
||||
content = _read_install_sh()
|
||||
update_section = _extract_update_only_section(content)
|
||||
|
||||
assert "tools.py" in update_section, (
|
||||
f"--update-only Block enthält keine tools.py-Bereinigung:\n{update_section}"
|
||||
)
|
||||
assert "rc_tools.py" in update_section, (
|
||||
f"--update-only Block erwähnt rc_tools.py nicht:\n{update_section}"
|
||||
)
|
||||
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════════════════
|
||||
# Test 9: Stale ~/.hermes/plugins/rocketchat/ Cleanup (V8.6)
|
||||
# ═══════════════════════════════════════════════════════════════════════════
|
||||
|
||||
|
||||
class TestStalePluginDirCleanup:
|
||||
"""--update-only muss den alten falschen Pfad ~/.hermes/plugins/rocketchat/ bereinigen."""
|
||||
|
||||
def test_update_only_removes_stale_hermes_plugins_dir(self):
|
||||
"""--update-only Block löscht ~/.hermes/plugins/rocketchat/."""
|
||||
content = _read_install_sh()
|
||||
update_section = _extract_update_only_section(content)
|
||||
|
||||
assert ".hermes/plugins/rocketchat" in update_section, (
|
||||
f"--update-only Block bereinigt nicht ~/.hermes/plugins/rocketchat/:\n{update_section}"
|
||||
)
|
||||
assert "rm -rf" in update_section, (
|
||||
f"--update-only Block nutzt kein rm -rf für stale Pfad:\n{update_section}"
|
||||
)
|
||||
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════════════════
|
||||
# Test 10: Kein hardcoded python3.13 (V8.6: dynamischer site-packages-Pfad)
|
||||
# ═══════════════════════════════════════════════════════════════════════════
|
||||
|
||||
|
||||
class TestNoHardcodedPythonVersion:
|
||||
"""install.sh darf keinen hardcoded python3.13-Pfad enthalten."""
|
||||
|
||||
def test_no_hardcoded_python3_13_in_site_packages_path(self):
|
||||
"""Kein 'python3.13/site-packages' als hartcodierter Pfad (außer Fallback/Dry-Run)."""
|
||||
content = _read_install_sh()
|
||||
|
||||
# python3.13 darf nur in Kommentaren, Fallback-Strings, Dry-Run-Platzhaltern
|
||||
# oder apt-Install vorkommen. Aber NICHT als hartcodierter site-packages-Pfad.
|
||||
lines_with_python3_13 = [
|
||||
line for line in content.split("\n")
|
||||
if "python3.13" in line
|
||||
]
|
||||
for line in lines_with_python3_13:
|
||||
if "site-packages" in line:
|
||||
# Erlaubt: Fallback nach find_site_packages, Dry-Run-Platzhalter, Kommentare
|
||||
ok = (
|
||||
"find_site_packages" in line
|
||||
or "||" in line
|
||||
or "#" in line.strip()[:1]
|
||||
or "<PIPX_VENV>" in line # Dry-Run-Platzhalter
|
||||
)
|
||||
assert ok, (
|
||||
f"Hardcoded python3.13/site-packages ohne Fallback:\n {line.strip()}"
|
||||
)
|
||||
|
||||
def test_find_site_packages_used_for_dropin(self):
|
||||
"""systemd drop-in nutzt find_site_packages (nicht hardcoded python3.13)."""
|
||||
content = _read_install_sh()
|
||||
|
||||
# Der drop-in-Block muss find_site_packages aufrufen
|
||||
match = re.search(
|
||||
r'install_gateway_service\(\).*?(?=\n\}\n\n#)',
|
||||
content,
|
||||
re.DOTALL,
|
||||
)
|
||||
assert match, "install_gateway_service()-Funktion nicht gefunden"
|
||||
func_body = match.group(0)
|
||||
|
||||
assert "find_site_packages" in func_body, (
|
||||
f"install_gateway_service() nutzt nicht find_site_packages:\n{func_body[:500]}"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user