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:
+23
-1
@@ -467,6 +467,12 @@ deploy_plugin() {
|
||||
find "$dst" -name '__pycache__' -type d -exec rm -rf {} + 2>/dev/null || true
|
||||
find "$dst" -name '*.pyc' -delete 2>/dev/null || true
|
||||
|
||||
# V8.6: Alte tools.py löschen (wurde zu rc_tools.py umbenannt, P3-Fix)
|
||||
if [ -f "$dst/tools.py" ]; then
|
||||
rm -f "$dst/tools.py"
|
||||
log "Alte tools.py gelöscht (ersetzt durch rc_tools.py)"
|
||||
fi
|
||||
|
||||
# plugin.yaml am richtigen Ort? Datei liegt in plugin/plugin.yaml
|
||||
# → kopiert als $dst/plugin.yaml. Korrekt.
|
||||
local count
|
||||
@@ -907,11 +913,15 @@ install_gateway_service() {
|
||||
local dropin_dir="$HOME/.config/systemd/user/hermes-gateway.service.d"
|
||||
local dropin="$dropin_dir/env.conf"
|
||||
mkdir -p "$dropin_dir"
|
||||
# Dynamischen site-packages-Pfad ermitteln (nicht hardcoded python3.13)
|
||||
local _sp
|
||||
_sp="$(find_site_packages "$PIPX_VENV")"
|
||||
[ -n "$_sp" ] || _sp="$PIPX_VENV/lib/python3.13/site-packages"
|
||||
cat > "$dropin" <<EOF
|
||||
[Service]
|
||||
EnvironmentFile=%h/.config/hermes/rocketchat.env
|
||||
EnvironmentFile=%h/.hermes/.env
|
||||
Environment=PYTHONPATH=$PIPX_VENV/lib/python3.13/site-packages/plugins/platforms/rocketchat
|
||||
Environment=PYTHONPATH=${_sp}/plugins/platforms/rocketchat
|
||||
Environment=MULTIROOM_AGENT=$RC_MULTIROOM
|
||||
Environment=OLLAMA_KEEP_ALIVE=$OLLAMA_KEEP_ALIVE
|
||||
EOF
|
||||
@@ -1446,6 +1456,18 @@ if $UPDATE_ONLY; then
|
||||
find "$_update_dst" -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
|
||||
find "$_update_dst" -name '*.pyc' -delete 2>/dev/null || true
|
||||
ok "__pycache__ nach Deployment gelöscht"
|
||||
|
||||
# V8.6: Alte tools.py löschen (wurde zu rc_tools.py umbenannt, P3-Fix)
|
||||
if [ -f "$_update_dst/tools.py" ]; then
|
||||
rm -f "$_update_dst/tools.py"
|
||||
log "Alte tools.py gelöscht (ersetzt durch rc_tools.py)"
|
||||
fi
|
||||
|
||||
# V8.6: Stale ~/.hermes/plugins/rocketchat/ bereinigen (alter falscher Pfad)
|
||||
if [ -d "$HOME/.hermes/plugins/rocketchat" ]; then
|
||||
rm -rf "$HOME/.hermes/plugins/rocketchat"
|
||||
log "Stale ~/.hermes/plugins/rocketchat/ gelöscht (alter falscher Pfad)"
|
||||
fi
|
||||
else
|
||||
printf '%s[dry]%s find %s -type d -name __pycache__ -exec rm -rf {} +\n' "$C_YELLOW" "$C_RESET" "$_update_dst"
|
||||
fi
|
||||
|
||||
@@ -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