Compare commits
4 Commits
230edb9fdb
...
766aa7ece6
| Author | SHA1 | Date | |
|---|---|---|---|
| 766aa7ece6 | |||
| 3aa1c5ac7f | |||
| a3758954f8 | |||
| 209daf87bc |
+306
-46
@@ -168,7 +168,6 @@ read_env() {
|
||||
COMPRESSION_THRESHOLD="${COMPRESSION_THRESHOLD:-$DEFAULT_COMPRESSION_THRESHOLD}"
|
||||
# Optionale Tunables
|
||||
ROCKETCHAT_HOME_CHANNEL="${ROCKETCHAT_HOME_CHANNEL:-${ROCKETCHAT_ROOM_NAME:-}}"
|
||||
RC_MULTIROOM="${RC_MULTIROOM:-true}" # V8.5 mit Archivar = Default
|
||||
ROCKETCHAT_ALLOW_ALL_USERS="${ROCKETCHAT_ALLOW_ALL_USERS:-true}"
|
||||
GATEWAY_ALLOW_ALL_USERS="${GATEWAY_ALLOW_ALL_USERS:-true}"
|
||||
ROCKETCHAT_PING_SEC="${ROCKETCHAT_PING_SEC:-8}"
|
||||
@@ -183,6 +182,56 @@ read_env() {
|
||||
OLLAMA_KEEP_ALIVE="${OLLAMA_KEEP_ALIVE:--1}"
|
||||
}
|
||||
|
||||
# ──────────────────────────────────────────────────────────────────────────
|
||||
# F98 B16 — effective_multiroom(): EINE Wahrheitsquelle für Multiroom.
|
||||
#
|
||||
# Root-Cause: RC_MULTIROOM="${RC_MULTIROOM:-true}" wurde VOR dem .env-Read
|
||||
# gesetzt. --repair startet eine frische Shell → Variable leer → Default true
|
||||
# greift → FAISS-Stufe 5 + repair_env_file mergen mit falschem Wert, obwohl
|
||||
# der Wizard N gewählt und MULTIROOM_AGENT=false in .env geschrieben hat.
|
||||
#
|
||||
# Diese Funktion liest die Wahrheit aus EINER Quelle (erste gewinnt):
|
||||
# 1. $MULTIROOM_AGENT aus env (wenn exportiert)
|
||||
# 2. grep '^MULTIROOM_AGENT=' ~/.hermes/.env → Wert extrahieren
|
||||
# 3. $RC_MULTIROOM aus env (wenn exportiert)
|
||||
# 4. Default "true" (V8.5 mit Archivar)
|
||||
# Gibt "true" oder "false" auf stdout zurück.
|
||||
# ──────────────────────────────────────────────────────────────────────────
|
||||
effective_multiroom() {
|
||||
# 1. MULTIROOM_AGENT aus env (z.B. wenn systemd-Drop-in gelesen wurde).
|
||||
if [ -n "${MULTIROOM_AGENT:-}" ]; then
|
||||
case "${MULTIROOM_AGENT}" in
|
||||
true|1|yes|on) echo "true"; return 0 ;;
|
||||
false|0|no|off) echo "false"; return 0 ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# 2. MULTIROOM_AGENT aus ~/.hermes/.env (vom Wizard geschrieben).
|
||||
local envfile="$HOME/.hermes/.env"
|
||||
if [ -f "$envfile" ]; then
|
||||
local env_val
|
||||
env_val="$(grep '^MULTIROOM_AGENT=' "$envfile" 2>/dev/null | head -1 | cut -d= -f2- | tr -d '[:space:]')"
|
||||
if [ -n "$env_val" ]; then
|
||||
case "$env_val" in
|
||||
true|1|yes|on) echo "true"; return 0 ;;
|
||||
false|0|no|off) echo "false"; return 0 ;;
|
||||
esac
|
||||
fi
|
||||
fi
|
||||
|
||||
# 3. RC_MULTIROOM aus env (Wizard setzt es in der aktuellen Shell).
|
||||
if [ -n "${RC_MULTIROOM:-}" ]; then
|
||||
case "${RC_MULTIROOM}" in
|
||||
true|1|yes|on) echo "true"; return 0 ;;
|
||||
false|0|no|off) echo "false"; return 0 ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# 4. Default.
|
||||
echo "true"
|
||||
return 0
|
||||
}
|
||||
|
||||
# ──────────────────────────────────────────────────────────────────────────
|
||||
# F98: Auto-Update-Check (Andreas-Direktive 31.08.)
|
||||
# Prüft bei JEDEM Lauf, ob auf Gitea eine neuere Version liegt, und zieht
|
||||
@@ -489,6 +538,48 @@ install_system_deps() {
|
||||
# ──────────────────────────────────────────────────────────────────────────
|
||||
# 2. Hermes Agent installieren
|
||||
# ──────────────────────────────────────────────────────────────────────────
|
||||
# ──────────────────────────────────────────────────────────────────────────
|
||||
# F98 B21 — install_hermes_symlinks(): Dual-Symlink für `hermes`-Kommando.
|
||||
#
|
||||
# Root-Cause: `ln -sf ... $HOME/.local/bin/hermes` allein reicht NICHT —
|
||||
# in einer `sudo -i`-root-Shell (HOME=/root) oder im Profil-Home-Kontext
|
||||
# (~/.hermes/profiles/<name>/home) zeigt $HOME/.local/bin ins Leere, und
|
||||
# `command -v hermes` schlägt fehl. Ein zweiter Symlink nach
|
||||
# /usr/local/bin/hermes funktioniert in JEDEM Kontext ohne Shell-Init.
|
||||
#
|
||||
# Aufruf: install_hermes_symlinks <venv>
|
||||
# 1. Primär: /usr/local/bin/hermes → <venv>/bin/hermes (sudo-Fallback)
|
||||
# 2. Sekundär: $HOME/.local/bin/hermes → <venv>/bin/hermes (immer)
|
||||
# 3. Verifikation: command -v hermes mit /usr/local/bin im PATH
|
||||
# ──────────────────────────────────────────────────────────────────────────
|
||||
install_hermes_symlinks() {
|
||||
local venv="$1"
|
||||
local hermes_bin="$venv/bin/hermes"
|
||||
|
||||
# 1. Primärer Symlink nach /usr/local/bin (funktioniert in jedem Kontext).
|
||||
if [ -e "$hermes_bin" ]; then
|
||||
if ln -sf "$hermes_bin" /usr/local/bin/hermes 2>/dev/null; then
|
||||
ok "hermes-Symlink: /usr/local/bin/hermes -> $hermes_bin"
|
||||
elif sudo ln -sf "$hermes_bin" /usr/local/bin/hermes 2>/dev/null; then
|
||||
ok "hermes-Symlink (sudo): /usr/local/bin/hermes -> $hermes_bin"
|
||||
else
|
||||
warn "hermes-Symlink nach /usr/local/bin konnte nicht angelegt werden — PATH manuell setzen oder mit sudo erneut ausführen"
|
||||
fi
|
||||
fi
|
||||
|
||||
# 2. Sekundärer Symlink nach $HOME/.local/bin (bestehendes Verhalten).
|
||||
mkdir -p "$HOME/.local/bin"
|
||||
ln -sf "$hermes_bin" "$HOME/.local/bin/hermes"
|
||||
export PATH="$HOME/.local/bin:$PATH"
|
||||
|
||||
# 3. Verifikation: command -v hermes muss nach Shell-Init funktionieren.
|
||||
if PATH="/usr/local/bin:/usr/bin:$PATH" command -v hermes >/dev/null 2>&1; then
|
||||
ok "hermes-Kommando im PATH verfügbar"
|
||||
else
|
||||
warn "hermes-Kommando nicht im PATH gefunden — PATH manuell setzen (z.B. export PATH=/usr/local/bin:\$PATH)"
|
||||
fi
|
||||
}
|
||||
|
||||
install_hermes_agent() {
|
||||
banner "2. Hermes Agent"
|
||||
|
||||
@@ -513,10 +604,8 @@ install_hermes_agent() {
|
||||
|| warn "pip upgrade im User-Space-venv fehlgeschlagen"
|
||||
"$hermes_venv/bin/python" -m pip install --quiet hermes-agent \
|
||||
|| die "hermes-agent Installation im User-Space-venv fehlgeschlagen"
|
||||
# Symlink nach ~/.local/bin/hermes
|
||||
mkdir -p "$HOME/.local/bin"
|
||||
ln -sf "$hermes_venv/bin/hermes" "$HOME/.local/bin/hermes"
|
||||
export PATH="$HOME/.local/bin:$PATH"
|
||||
# Dual-Symlink (F98 B21): /usr/local/bin + $HOME/.local/bin
|
||||
install_hermes_symlinks "$hermes_venv"
|
||||
venv="$hermes_venv"
|
||||
else
|
||||
printf '%s[dry]%s python3 -m venv %s && %s/bin/python -m pip install hermes-agent && ln -sf %s/bin/hermes ~/.local/bin/hermes\n' \
|
||||
@@ -882,11 +971,9 @@ migrate_to_venv() {
|
||||
"$hermes_venv/bin/python" -m pip install --quiet hermes-agent \
|
||||
|| die "hermes-agent Installation im User-Space-venv fehlgeschlagen"
|
||||
|
||||
# c) Symlink umhängen: ~/.local/bin/hermes → User-Space-venv
|
||||
log "Hänge Symlink um: ~/.local/bin/hermes → $hermes_venv/bin/hermes"
|
||||
mkdir -p "$HOME/.local/bin"
|
||||
ln -sf "$hermes_venv/bin/hermes" "$HOME/.local/bin/hermes"
|
||||
export PATH="$HOME/.local/bin:$PATH"
|
||||
# c) Symlink umhängen: Dual-Symlink (F98 B21) → User-Space-venv
|
||||
log "Hänge Symlink um: hermes → $hermes_venv/bin/hermes"
|
||||
install_hermes_symlinks "$hermes_venv"
|
||||
|
||||
# d) pipx-venv unmounten
|
||||
log "Unmounte pipx-venv (pipx uninstall hermes-agent)..."
|
||||
@@ -1423,7 +1510,7 @@ write_env_file() {
|
||||
echo "# ── Archivar (lokal) ──"
|
||||
echo "# P8: LLM/Embeddings laufen lokal via Ollama, NICHT über die Cloud."
|
||||
echo "ARCHIVAR_ENABLE_LLM=true"
|
||||
echo "ARCHIVAR_LLM_BASE_URL=${ARCHIVAR_LLM_BASE_URL}"
|
||||
echo "ARCHIVAR_LLM_BASE_URL=${ARCHIVAR_BASE_URL:-$ARCHIVAR_LLM_BASE_URL}"
|
||||
echo "ARCHIVAR_EMBEDDING_BASE_URL=${ARCHIVAR_EMBEDDING_BASE_URL}"
|
||||
echo ""
|
||||
echo "# ── Rocket.Chat Identität (P4: bot-spezifisch) ──"
|
||||
@@ -1565,22 +1652,68 @@ MD
|
||||
# sudo systemctl (system-service, root-Installationen).
|
||||
# ──────────────────────────────────────────────────────────────────────────
|
||||
|
||||
# ──────────────────────────────────────────────────────────────────────────
|
||||
# F98 B20 — gateway_systemctl_v2(): Cross-User-fähiger systemctl-Wrapper.
|
||||
#
|
||||
# Root-Cause (Live-verifiziert 01.09., Rainer): In einer root-Shell ohne
|
||||
# DBUS-Session (sudo -i) schlägt `systemctl --user daemon-reload` still fehl:
|
||||
# "Failed to connect to user scope bus via local transport:
|
||||
# $DBUS_SESSION_BUS_ADDRESS and $XDG_RUNTIME_DIR not defined
|
||||
# (consider using --machine=<user>@.host --user ...)"
|
||||
# systemd empfiehlt SELBST die Lösung: --machine=<user>@.host --user.
|
||||
#
|
||||
# Diese Funktion leitet den Ziel-User ab und nutzt im sudo-Kontext den
|
||||
# Machine-Transport, damit enable/start/daemon-reload auch aus einer
|
||||
# root-Shell heraus den User-Service des echten Users erreichen (B19-Folge).
|
||||
#
|
||||
# Aufruf: gateway_systemctl_v2 <action> [args...]
|
||||
# Exit-Code wird durchgereicht (KEIN `|| true`), stderr+stdout durchgelassen.
|
||||
# ──────────────────────────────────────────────────────────────────────────
|
||||
gateway_systemctl_v2() {
|
||||
local action="$1"; shift
|
||||
local user_target
|
||||
|
||||
# Schritt 1: Ziel-User ableiten.
|
||||
if [ "$(id -u)" = "0" ]; then
|
||||
# Root-Kontext: echten User aus SUDO_USER ableiten, sonst ersten
|
||||
# regulären User (uid>=1000) aus /etc/passwd.
|
||||
if [ -n "${SUDO_USER:-}" ]; then
|
||||
user_target="$SUDO_USER"
|
||||
else
|
||||
user_target="$(awk -F: '$3 >= 1000 && $3 < 65534 { print $1; exit }' /etc/passwd 2>/dev/null || true)"
|
||||
fi
|
||||
if [ -z "$user_target" ]; then
|
||||
err "gateway_systemctl_v2: kein Ziel-User ableitbar (SUDO_USER leer, kein uid>=1000-User in /etc/passwd)"
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
user_target="$USER"
|
||||
fi
|
||||
|
||||
# Schritt 2: Aufruf — Machine-Transport nur im Cross-User-Fall.
|
||||
if [ "$user_target" = "$USER" ]; then
|
||||
systemctl --user "$action" "$@"
|
||||
else
|
||||
systemctl --machine="${user_target}@.host" --user "$action" "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
# restart_gateway() — erkennt automatisch ob Gateway als user- oder system-service läuft
|
||||
restart_gateway() {
|
||||
if systemctl --user is-active hermes-gateway &>/dev/null; then
|
||||
systemctl --user restart hermes-gateway
|
||||
if gateway_systemctl_v2 is-active hermes-gateway &>/dev/null; then
|
||||
gateway_systemctl_v2 restart hermes-gateway
|
||||
elif sudo systemctl is-active hermes-gateway &>/dev/null; then
|
||||
sudo systemctl restart hermes-gateway
|
||||
else
|
||||
# Weder user noch system — versuche user (Default)
|
||||
systemctl --user restart hermes-gateway 2>/dev/null || true
|
||||
gateway_systemctl_v2 restart hermes-gateway 2>/dev/null || true
|
||||
fi
|
||||
}
|
||||
|
||||
# gateway_journalctl() — journalctl-Aufruf für user- ODER system-service
|
||||
gateway_journalctl() {
|
||||
local args="$*"
|
||||
if systemctl --user is-active hermes-gateway &>/dev/null 2>&1; then
|
||||
if gateway_systemctl_v2 is-active hermes-gateway &>/dev/null 2>&1; then
|
||||
journalctl --user -u hermes-gateway $args
|
||||
elif systemctl is-active hermes-gateway &>/dev/null 2>&1; then
|
||||
journalctl -u hermes-gateway $args
|
||||
@@ -1592,8 +1725,8 @@ gateway_journalctl() {
|
||||
|
||||
# gateway_is_enabled() — prüft enable-Status für user- ODER system-service
|
||||
gateway_is_enabled() {
|
||||
if systemctl --user is-enabled hermes-gateway &>/dev/null 2>&1; then
|
||||
systemctl --user is-enabled hermes-gateway 2>/dev/null
|
||||
if gateway_systemctl_v2 is-enabled hermes-gateway &>/dev/null 2>&1; then
|
||||
gateway_systemctl_v2 is-enabled hermes-gateway 2>/dev/null
|
||||
elif systemctl is-enabled hermes-gateway &>/dev/null 2>&1; then
|
||||
systemctl is-enabled hermes-gateway 2>/dev/null
|
||||
else
|
||||
@@ -1603,31 +1736,31 @@ gateway_is_enabled() {
|
||||
|
||||
# gateway_is_active() — prüft active-Status für user- ODER system-service
|
||||
gateway_is_active() {
|
||||
systemctl --user is-active hermes-gateway &>/dev/null 2>&1 \
|
||||
gateway_systemctl_v2 is-active hermes-gateway &>/dev/null 2>&1 \
|
||||
|| systemctl is-active hermes-gateway &>/dev/null 2>&1
|
||||
}
|
||||
|
||||
# gateway_systemctl() — generischer systemctl-Aufruf, auto-detektiert user vs. system
|
||||
gateway_systemctl() {
|
||||
local cmd="$1"; shift
|
||||
if systemctl --user is-active hermes-gateway &>/dev/null 2>&1; then
|
||||
systemctl --user "$cmd" hermes-gateway "$@"
|
||||
if gateway_systemctl_v2 is-active hermes-gateway &>/dev/null 2>&1; then
|
||||
gateway_systemctl_v2 "$cmd" hermes-gateway "$@"
|
||||
elif systemctl is-active hermes-gateway &>/dev/null 2>&1; then
|
||||
sudo systemctl "$cmd" hermes-gateway "$@"
|
||||
else
|
||||
# Weder user noch system — versuche user (Default)
|
||||
systemctl --user "$cmd" hermes-gateway "$@" 2>/dev/null || true
|
||||
gateway_systemctl_v2 "$cmd" hermes-gateway "$@" 2>/dev/null || true
|
||||
fi
|
||||
}
|
||||
|
||||
# gateway_daemon_reload() — daemon-reload für user- ODER system-service
|
||||
gateway_daemon_reload() {
|
||||
if systemctl --user is-active hermes-gateway &>/dev/null 2>&1; then
|
||||
systemctl --user daemon-reload
|
||||
if gateway_systemctl_v2 is-active hermes-gateway &>/dev/null 2>&1; then
|
||||
gateway_systemctl_v2 daemon-reload
|
||||
elif systemctl is-active hermes-gateway &>/dev/null 2>&1; then
|
||||
sudo systemctl daemon-reload
|
||||
else
|
||||
systemctl --user daemon-reload 2>/dev/null || true
|
||||
gateway_systemctl_v2 daemon-reload 2>/dev/null || true
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -1635,15 +1768,15 @@ install_gateway_service() {
|
||||
banner "8. Gateway Service"
|
||||
|
||||
if ! $DRY_RUN; then
|
||||
# loginctl enable-linger — KRITISCH: user service ohne aktive Session.
|
||||
# F98 P-182: timeout 10s + Warn-und-continue. Auf jungfräulichem Debian 13
|
||||
# kann systemd-logind noch nicht ready sein → loginctl blockt endlos.
|
||||
# Root-Installation (id -u = 0) braucht kein Linger (Root-Prozesse
|
||||
# überleben Logout ohne Linger).
|
||||
# ── [1/5] loginctl enable-linger ──
|
||||
# KRITISCH: user service ohne aktive Session. F98 P-182: timeout 10s +
|
||||
# Warn-und-continue. Auf jungfräulichem Debian 13 kann systemd-logind
|
||||
# noch nicht ready sein → loginctl blockt endlos. Root-Installation
|
||||
# (id -u = 0) braucht kein Linger (Root-Prozesse überleben Logout).
|
||||
log "[1/5] Aktiviere loginctl enable-linger..."
|
||||
if [ "$(id -u)" = "0" ]; then
|
||||
log "Root-Installation — Linger übersprungen (Root-Prozesse überleben Logout ohne Linger)"
|
||||
elif ! loginctl show-user "$USER" 2>/dev/null | grep -q 'Linger=yes'; then
|
||||
log "Aktiviere loginctl enable-linger (timeout 10s)..."
|
||||
if ! timeout 10 sudo loginctl enable-linger "$USER" 2>/dev/null; then
|
||||
if ! timeout 10 loginctl enable-linger "$USER" 2>/dev/null; then
|
||||
warn "Linger konnte nicht aktiviert werden (timeout/Fehler) — Gateway crasht evtl. nach Logout"
|
||||
@@ -1651,17 +1784,27 @@ install_gateway_service() {
|
||||
fi
|
||||
fi
|
||||
|
||||
# Gateway über Hermes selbst installieren lassen
|
||||
# ── [2/5] "hermes gateway install" ──
|
||||
# F98 B12: stderr+stdout durchlassen (kein 2>/dev/null), Exit-Code prüfen
|
||||
# statt `|| true`. Ein stiller Fehler hier (B20-Folge) würde sonst die
|
||||
# Unit nicht anlegen → kein enable → kein Autostart (B19).
|
||||
log "[2/5] Rufe \"hermes gateway install\" auf..."
|
||||
cd "$PIPX_VENV" 2>/dev/null || true
|
||||
"$VENV_PY" -m hermes_cli.main gateway install 2>/dev/null || true
|
||||
if ! "$VENV_PY" -m hermes_cli.main gateway install; then
|
||||
warn "[2/5] \"hermes gateway install\" fehlgeschlagen (rc=$?) — Unit wird ggf. in [3/5] nachgezogen"
|
||||
fi
|
||||
|
||||
# ExecStart auf "gateway run" stellen (lädt Platform-Plugins)
|
||||
# ── [3/5] ExecStart auf "gateway run" patchen ──
|
||||
log "[3/5] ExecStart auf \"gateway run\" patchen..."
|
||||
local unit="$HOME/.config/systemd/user/hermes-gateway.service"
|
||||
if [ -f "$unit" ]; then
|
||||
sed -i "s|^ExecStart=.*|ExecStart=$VENV_PY -m hermes_cli.main gateway run|" "$unit"
|
||||
else
|
||||
warn "[3/5] Unit-Datei fehlt ($unit) — \"hermes gateway install\" hat sie nicht angelegt"
|
||||
fi
|
||||
|
||||
# EnvironmentFile drop-in: .env + rocketchat.env laden
|
||||
# ── [4/5] EnvironmentFile drop-in schreiben ──
|
||||
log "[4/5] Schreibe EnvironmentFile drop-in (env.conf)..."
|
||||
local dropin_dir="$HOME/.config/systemd/user/hermes-gateway.service.d"
|
||||
local dropin="$dropin_dir/env.conf"
|
||||
mkdir -p "$dropin_dir"
|
||||
@@ -1706,7 +1849,11 @@ EOF
|
||||
log "Ollama systemd drop-in übersprungen (Provider=$PROVIDER, kein lokales Ollama)"
|
||||
fi
|
||||
|
||||
gateway_daemon_reload
|
||||
# ── [5/5] gateway_daemon_reload via gateway_systemctl_v2 (B20) ──
|
||||
log "[5/5] systemd daemon-reload (Cross-User-fähig)..."
|
||||
if ! gateway_daemon_reload; then
|
||||
warn "[5/5] systemd-Unit konnte nicht aktiviert werden (daemon-reload fehlgeschlagen) — siehe B20/B18"
|
||||
fi
|
||||
|
||||
# State-Cleanup (Discovery-Bug + Auto-Resume-Loop)
|
||||
rm -f "$HOME/.hermes/gateway_state.json" \
|
||||
@@ -1947,6 +2094,7 @@ check_components() {
|
||||
REPAIR_INDEX_STALE=false
|
||||
REPAIR_ENV_MISSING=false
|
||||
REPAIR_SYMLINK_MISSING=false
|
||||
REPAIR_UNIT_MISSING=false
|
||||
|
||||
# ── Stufe 1: venv finden ──
|
||||
if ! PIPX_VENV="$(find_pipx_venv 2>/dev/null)" || [ -z "$PIPX_VENV" ]; then
|
||||
@@ -2117,6 +2265,19 @@ except Exception:
|
||||
REPAIR_SYMLINK_MISSING=true
|
||||
REPAIR_NEEDED=true
|
||||
fi
|
||||
|
||||
# ── Stufe 8: systemd-Unit (F98 B18) ──
|
||||
# Wenn `hermes gateway install` still scheitert (B20-Folge), existiert die
|
||||
# Unit nicht → kein enable → kein Autostart (B19). --repair erkennt das
|
||||
# jetzt und stellt die Unit in repair_components() Stufe 8 nach.
|
||||
local unit_file="$HOME/.config/systemd/user/hermes-gateway.service"
|
||||
if [ -f "$unit_file" ]; then
|
||||
ok "Stufe 8: systemd-Unit vorhanden ($unit_file)"
|
||||
else
|
||||
warn "Stufe 8: systemd-Unit fehlt ($unit_file)"
|
||||
REPAIR_UNIT_MISSING=true
|
||||
REPAIR_NEEDED=true
|
||||
fi
|
||||
}
|
||||
|
||||
# ──────────────────────────────────────────────────────────────────────────
|
||||
@@ -2135,7 +2296,7 @@ repair_env_file() {
|
||||
# KEY=VALUE-Paare (nur nicht-secret Keys mit Defaults).
|
||||
local -a pairs=(
|
||||
"ARCHIVAR_ENABLE_LLM=true"
|
||||
"ARCHIVAR_LLM_BASE_URL=${ARCHIVAR_LLM_BASE_URL}"
|
||||
"ARCHIVAR_LLM_BASE_URL=${ARCHIVAR_BASE_URL:-$ARCHIVAR_LLM_BASE_URL}"
|
||||
"ARCHIVAR_EMBEDDING_BASE_URL=${ARCHIVAR_EMBEDDING_BASE_URL}"
|
||||
"ROCKETCHAT_BASE_URL=${ROCKETCHAT_BASE_URL}"
|
||||
"ROCKETCHAT_USER=${ROCKETCHAT_USER}"
|
||||
@@ -2281,6 +2442,14 @@ repair_components() {
|
||||
# Fortschritts-Anzeige: Anzahl Räume aus room-map.json lesen
|
||||
local _room_count
|
||||
_room_count="$("$VENV_PY" -c "import json;print(len(json.load(open('$HOME/.hermes/hermes-agent/data/room-map.json')).get('rooms',[])))" 2>/dev/null || echo "?")"
|
||||
# F98 B17: 0 Räume → FAISS-Index überspringen (kein Index nötig).
|
||||
# rebuild_index.py crasht sonst mit RoomIndexError bei leerer
|
||||
# room-map. Edge-Case _room_count="?" (Python-Crash) wird
|
||||
# konservativ ebenfalls als graceful-skip behandelt, damit
|
||||
# --repair nicht mit kryptischem Traceback abbricht.
|
||||
if [ "$_room_count" = "0" ] || [ "$_room_count" = "?" ]; then
|
||||
ok "Stufe 5: 0 Räume in room-map.json — FAISS-Index übersprungen (kein Index nötig)"
|
||||
else
|
||||
log "Stufe 5: Rebuild FAISS-Index (${_room_count} Räume)..."
|
||||
# rebuild_index.py erwartet cwd = Repo-Root (sys.path.insert(0, "plugin"))
|
||||
# Hartes Timeout (max 300s): Embedding-Calls können bei kaltem Ollama lange dauern.
|
||||
@@ -2289,6 +2458,7 @@ repair_components() {
|
||||
else
|
||||
warn "Stufe 5: TIMEOUT/Fehler beim FAISS-Rebuild — überspringe, nächste Stufe"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
printf '%s[dry]%s (cd %s && %s %s) (max 300s)\n' "$C_YELLOW" "$C_RESET" "$script_dir" "$VENV_PY" "$rebuild_script"
|
||||
fi
|
||||
@@ -2327,6 +2497,17 @@ repair_components() {
|
||||
repaired=true
|
||||
fi
|
||||
|
||||
# Stufe 8: systemd-Unit + Autostart (F98 B18)
|
||||
# Wenn `hermes gateway install` still scheiterte (B20-Folge), fehlt die
|
||||
# Unit → kein enable → kein Autostart (B19). install_gateway_service() ist
|
||||
# idempotent (sed-ExecStart = no-op wenn korrekt, Drop-in wird überschrieben,
|
||||
# enable idempotent) und nutzt jetzt gateway_systemctl_v2 (B20-Fix).
|
||||
if $REPAIR_UNIT_MISSING; then
|
||||
banner "Reparatur Stufe 8: systemd-Unit + Autostart"
|
||||
install_gateway_service
|
||||
repaired=true
|
||||
fi
|
||||
|
||||
if $repaired; then
|
||||
return 0
|
||||
else
|
||||
@@ -2413,7 +2594,9 @@ compute_cascade() {
|
||||
# Provider + Multiroom konsistent auflösen (Wizard und Hauptfluss münden
|
||||
# hier in dieselben Variablen — Niagara-Punkt 1, Konzept §3.1).
|
||||
PROVIDER="${PROVIDER:-none}"
|
||||
RC_MULTIROOM="${RC_MULTIROOM:-true}"
|
||||
# F98 B16: Multiroom-Wahrheit aus EINER Quelle (effective_multiroom), nicht
|
||||
# aus einem Default-Init, der die .env-Wahl des Wizards überschreibt.
|
||||
RC_MULTIROOM="$(effective_multiroom)"
|
||||
|
||||
# FAISS: nur bei Multiroom (Single-Room braucht kein FAISS — Konzept §3.3 Regel 3).
|
||||
if [ "$RC_MULTIROOM" = "true" ]; then
|
||||
@@ -2448,7 +2631,15 @@ compute_cascade() {
|
||||
;;
|
||||
esac
|
||||
|
||||
log "Cascade: PROVIDER=$PROVIDER MULTIROOM=$RC_MULTIROOM → Ollama-Install=$OLLAMA_INSTALL_REQUIRED, Modelle=${MODEL_PULL_REQUIRED[*]:-"(keine)"}, FAISS=$FAISS_REQUIRED"
|
||||
# B15: ARCHIVAR_BASE_URL hängt von OLLAMA_INSTALL_REQUIRED ab, das erst im
|
||||
# case-Block gesetzt wird — hier final auflösen.
|
||||
if $OLLAMA_INSTALL_REQUIRED; then
|
||||
ARCHIVAR_BASE_URL="http://localhost:11434"
|
||||
else
|
||||
ARCHIVAR_BASE_URL="${PROVIDER_BASE_URL:-http://localhost:11434}"
|
||||
fi
|
||||
|
||||
log "Cascade: PROVIDER=$PROVIDER MULTIROOM=$RC_MULTIROOM → Ollama-Install=$OLLAMA_INSTALL_REQUIRED, Modelle=${MODEL_PULL_REQUIRED[*]:-"(keine)"}, FAISS=$FAISS_REQUIRED, Archivar-Base=$ARCHIVAR_BASE_URL"
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -2525,12 +2716,24 @@ T[de_lang_q]="Bitte Sprache wählen / Please select language: 1) Deutsch 2) En
|
||||
T[en_lang_q]="Please select language: 1) Deutsch 2) English"
|
||||
T[de_lang_ok]="Sprache: Deutsch"
|
||||
T[en_lang_ok]="Language: English"
|
||||
T[de_multiroom_q]="Wird ein Multiroom-Agent benötigt? Y) Ja — Bot routet mehrere Themenräume (Archivar aktiv) N) Nein — Single-Room-Modus (nur 1 Raum, Archivar deaktiviert)"
|
||||
T[en_multiroom_q]="Do you need a multiroom agent? Y) Yes — bot routes multiple topic rooms (Archivar active) N) No — single-room mode (1 room only, Archivar disabled)"
|
||||
T[de_multiroom_q]="Wird ein Multiroom-Agent benötigt?
|
||||
Ein Multiroom-Agent routet eingehende Nachrichten automatisch in den
|
||||
passenden Themenraum (Archivar aktiv). H) Hilfe J) Ja N) Nein"
|
||||
T[en_multiroom_q]="Do you need a multiroom agent?
|
||||
A multiroom agent routes incoming messages automatically to the matching
|
||||
topic room (Archivar active). H) Help Y) Yes N) No"
|
||||
T[de_multiroom_help]="Multiroom: Bot kennt alle Themenräume und entscheidet automatisch, wohin jede Nachricht gehört. Single-Room: Bot arbeitet nur in einem Raum (z.B. DM), keine Routing-Logik nötig."
|
||||
T[en_multiroom_help]="Multiroom: the bot knows all topic rooms and decides automatically where each message belongs. Single-room: the bot works in one room only (e.g. DM), no routing logic needed."
|
||||
T[de_multiroom_ok]="Multiroom: Ja"
|
||||
T[en_multiroom_ok]="Multiroom: Yes"
|
||||
T[de_multiroom_no]="Multiroom: Nein (Single-Room-Modus)"
|
||||
T[en_multiroom_no]="Multiroom: No (single-room mode)"
|
||||
T[de_profile_q]="Welches Profil? P) Produktion (24/7, Auto-Update) T) Test/Dev (manuell) H) Hilfe"
|
||||
T[en_profile_q]="Which profile? P) Production (24/7, auto-update) T) Test/Dev (manual) H) Help"
|
||||
T[de_profile_help]="Produktion: Bot läuft durchgehend, Updates automatisch. Test/Dev: Bot nur bei Bedarf starten, Updates manuell via --update-only."
|
||||
T[en_profile_help]="Production: bot runs continuously, updates automatic. Test/Dev: start the bot only when needed, update manually via --update-only."
|
||||
T[de_ask_suffix]=" [J/N/H]: "
|
||||
T[en_ask_suffix]=" [Y/N/H]: "
|
||||
T[de_rc_url_q]="Rocket.Chat-Server-URL?"
|
||||
T[en_rc_url_q]="Rocket.Chat server URL?"
|
||||
T[de_rc_user_q]="Bot-Username?"
|
||||
@@ -2593,6 +2796,48 @@ ask() {
|
||||
return 0
|
||||
}
|
||||
|
||||
# ── F98 B9 — ask_with_help(): Ja/Nein-Frage mit [H]-Hilfstext. ──
|
||||
# ask_with_help <var_name> "<question>" "<default>" "<help_text>"
|
||||
# Setzt <var_name> auf "true" oder "false".
|
||||
# - H oder ?: zeigt help_text, dann Frage erneut
|
||||
# - J/j/Y/y/1: true
|
||||
# - N/n/0: false
|
||||
# - Default (Enter): <default>
|
||||
# Suffix ist sprachabhängig (DE: [J/N/H], EN: [Y/N/H]).
|
||||
# ──────────────────────────────────────────────────────────────────────────
|
||||
ask_with_help() {
|
||||
local varname="$1" question="$2" default="$3" help_text="$4"
|
||||
local suffix="${T[${LANG_CHOICE}_ask_suffix]:-${T[de_ask_suffix]}}"
|
||||
local val="$default"
|
||||
|
||||
if $GUIDED_DEFAULTS; then
|
||||
printf '%s[guided-defaults]%s %s = %s\n' "$C_YELLOW" "$C_RESET" "$varname" "$val"
|
||||
eval "$varname=\"$val\""
|
||||
return 0
|
||||
fi
|
||||
|
||||
while true; do
|
||||
printf '%s[?]%s %s%s' "$C_BLUE" "$C_RESET" "$question" "$suffix"
|
||||
local input
|
||||
read -r input
|
||||
case "$input" in
|
||||
H|h|'?')
|
||||
printf '%s[i]%s %s\n' "$C_BLUE" "$C_RESET" "$help_text"
|
||||
continue
|
||||
;;
|
||||
J|j|Y|y|1) val="true"; break ;;
|
||||
N|n|0) val="false"; break ;;
|
||||
'')
|
||||
[ -n "$default" ] && val="$default"
|
||||
break
|
||||
;;
|
||||
*) continue ;;
|
||||
esac
|
||||
done
|
||||
eval "$varname=\"$val\""
|
||||
return 0
|
||||
}
|
||||
|
||||
# ── Wizard-Hauptfunktion. Führt Phasen 0-11 aus, setzt env-Variablen. ──
|
||||
run_guided_wizard() {
|
||||
banner "Hermes Rocket.Chat Plugin — Geführte Installation (F98)"
|
||||
@@ -2663,7 +2908,20 @@ run_guided_wizard() {
|
||||
if phase_done 2; then
|
||||
ok "[Phase 2 übersprungen (bereits abgeschlossen)]"
|
||||
else
|
||||
ask PROFILE "Welches Profil? 1) Produktion (24/7) 2) Test/Dev" "1" false
|
||||
# F98 B8: Profil-Frage selbsterklärend machen (P/T + [H]-Hilfe).
|
||||
local _profile_done=false
|
||||
while ! $_profile_done; do
|
||||
ask PROFILE "${T[${LANG_CHOICE}_profile_q]}" "1" false
|
||||
case "$PROFILE" in
|
||||
H|h|'?')
|
||||
printf '%s[i]%s %s\n' "$C_BLUE" "$C_RESET" "${T[${LANG_CHOICE}_profile_help]}"
|
||||
continue
|
||||
;;
|
||||
P|p|1) PROFILE="1"; _profile_done=true ;;
|
||||
T|t|2) PROFILE="2"; _profile_done=true ;;
|
||||
*) _profile_done=true ;;
|
||||
esac
|
||||
done
|
||||
if [ "$PROFILE" = "2" ]; then
|
||||
LOG_LEVEL="DEBUG"; ROCKETCHAT_PING_SEC="3"; ROCKETCHAT_IDLE_SEC="300"
|
||||
else
|
||||
@@ -2677,11 +2935,13 @@ run_guided_wizard() {
|
||||
if phase_done 3; then
|
||||
ok "[Phase 3 übersprungen (bereits abgeschlossen)]"
|
||||
else
|
||||
ask MULTIROOM_ANS "Wird ein Multiroom-Agent benötigt? Y) Ja N) Nein" "N" false
|
||||
case "$MULTIROOM_ANS" in
|
||||
Y|y|J|j|1) RC_MULTIROOM="true"; ok "[${T[${LANG_CHOICE}_multiroom_ok]}]" ;;
|
||||
*) RC_MULTIROOM="false"; ok "[${T[${LANG_CHOICE}_multiroom_no]}]" ;;
|
||||
esac
|
||||
# F98 B10/B11: Multiroom-Frage mit Erklärung + [H]-Hilfe + J/N-Konsistenz.
|
||||
ask_with_help MULTIROOM_ANS "${T[${LANG_CHOICE}_multiroom_q]}" "false" "${T[${LANG_CHOICE}_multiroom_help]}"
|
||||
if [ "$MULTIROOM_ANS" = "true" ]; then
|
||||
RC_MULTIROOM="true"; ok "[${T[${LANG_CHOICE}_multiroom_ok]}]"
|
||||
else
|
||||
RC_MULTIROOM="false"; ok "[${T[${LANG_CHOICE}_multiroom_no]}]"
|
||||
fi
|
||||
mark_phase 3 "multiroom"
|
||||
fi
|
||||
|
||||
|
||||
@@ -70,13 +70,14 @@ def _run_cascade(provider: str, multiroom: str) -> tuple[str, str, int]:
|
||||
"""Führt compute_cascade() mit gegebenem Provider/Multiroom aus und gibt
|
||||
(stdout, stderr, rc) zurück."""
|
||||
snippet = (
|
||||
_extract_functions("compute_cascade")
|
||||
_extract_functions("effective_multiroom", "compute_cascade")
|
||||
+ f"PROVIDER='{provider}'\n"
|
||||
+ f"RC_MULTIROOM='{multiroom}'\n"
|
||||
+ "compute_cascade\n"
|
||||
+ "echo \"OLLAMA_INSTALL_REQUIRED=$OLLAMA_INSTALL_REQUIRED\"\n"
|
||||
+ "echo \"FAISS_REQUIRED=$FAISS_REQUIRED\"\n"
|
||||
+ "echo \"MODEL_PULL_REQUIRED=${MODEL_PULL_REQUIRED[*]}\"\n"
|
||||
+ "echo \"ARCHIVAR_BASE_URL=$ARCHIVAR_BASE_URL\"\n"
|
||||
)
|
||||
env = {"PATH": "/usr/bin:/bin:/usr/local/bin", "HOME": "/tmp/f98-cascade-home"}
|
||||
result = subprocess.run(
|
||||
@@ -106,6 +107,8 @@ class TestComputeCascadeMatrix:
|
||||
assert d["FAISS_REQUIRED"] == "true"
|
||||
assert "qwen2.5:7b" in d["MODEL_PULL_REQUIRED"]
|
||||
assert "nomic-embed-text" in d["MODEL_PULL_REQUIRED"]
|
||||
# B15: lokales Ollama → Archivar zeigt auf localhost:11434
|
||||
assert d["ARCHIVAR_BASE_URL"] == "http://localhost:11434"
|
||||
|
||||
def test_ollama_single(self):
|
||||
out, err, rc = _run_cascade("ollama", "false")
|
||||
@@ -189,6 +192,46 @@ class TestCascadeIntegration:
|
||||
content = _read_install_sh()
|
||||
assert "compute_cascade()" in content
|
||||
|
||||
def test_effective_multiroom_function_exists(self):
|
||||
content = _read_install_sh()
|
||||
assert "effective_multiroom()" in content
|
||||
|
||||
def test_archivar_base_url_remote_provider(self):
|
||||
"""B15: Remote-Provider (custom/DGX) → ARCHIVAR_BASE_URL = Provider-URL."""
|
||||
snippet = (
|
||||
_extract_functions("effective_multiroom", "compute_cascade")
|
||||
+ "PROVIDER='custom'\n"
|
||||
+ "PROVIDER_BASE_URL='http://192.168.180.46:7999/v1'\n"
|
||||
+ "RC_MULTIROOM='true'\n"
|
||||
+ "compute_cascade\n"
|
||||
+ "echo \"ARCHIVAR_BASE_URL=$ARCHIVAR_BASE_URL\"\n"
|
||||
)
|
||||
env = {"PATH": "/usr/bin:/bin:/usr/local/bin", "HOME": "/tmp/f98-cascade-home"}
|
||||
result = subprocess.run(
|
||||
["bash", "-c", snippet],
|
||||
capture_output=True, text=True, env=env, timeout=30,
|
||||
)
|
||||
assert result.returncode == 0, f"compute_cascade crashte:\n{result.stdout}\n{result.stderr}"
|
||||
assert "ARCHIVAR_BASE_URL=http://192.168.180.46:7999/v1" in result.stdout
|
||||
|
||||
def test_archivar_base_url_cloud_provider_fallback(self):
|
||||
"""B15: Cloud-Provider ohne PROVIDER_BASE_URL → Fallback localhost."""
|
||||
snippet = (
|
||||
_extract_functions("effective_multiroom", "compute_cascade")
|
||||
+ "PROVIDER='openrouter'\n"
|
||||
+ "PROVIDER_BASE_URL=''\n"
|
||||
+ "RC_MULTIROOM='true'\n"
|
||||
+ "compute_cascade\n"
|
||||
+ "echo \"ARCHIVAR_BASE_URL=$ARCHIVAR_BASE_URL\"\n"
|
||||
)
|
||||
env = {"PATH": "/usr/bin:/bin:/usr/local/bin", "HOME": "/tmp/f98-cascade-home"}
|
||||
result = subprocess.run(
|
||||
["bash", "-c", snippet],
|
||||
capture_output=True, text=True, env=env, timeout=30,
|
||||
)
|
||||
assert result.returncode == 0
|
||||
assert "ARCHIVAR_BASE_URL=http://localhost:11434" in result.stdout
|
||||
|
||||
def test_ollama_install_conditional(self):
|
||||
"""install_system_deps: Ollama-Block in `if $OLLAMA_INSTALL_REQUIRED`."""
|
||||
content = _read_install_sh()
|
||||
|
||||
@@ -0,0 +1,293 @@
|
||||
"""
|
||||
F98-I2: B16 State-Konsistenz (effective_multiroom) + B20 systemd-Machine-Fix Tests.
|
||||
|
||||
Testet die Iteration-2-Fixes aus Rainers Architektur-Review:
|
||||
1. B16: effective_multiroom() liest Multiroom-Wahrheit aus EINER Quelle
|
||||
(env MULTIROOM_AGENT → .env → RC_MULTIROOM → Default true).
|
||||
2. B20: gateway_systemctl_v2() nutzt im sudo-Kontext --machine=<user>@.host.
|
||||
3. B18: check_components() setzt REPAIR_UNIT_MISSING bei fehlender Unit.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
INSTALL_SH = Path(__file__).resolve().parents[1] / "install.sh"
|
||||
|
||||
|
||||
def _read_install_sh() -> str:
|
||||
return INSTALL_SH.read_text()
|
||||
|
||||
|
||||
def _extract_functions(*names: str) -> str:
|
||||
"""Extrahiert Funktions-Definitionen (plus log-Helfer) aus install.sh."""
|
||||
content = INSTALL_SH.read_text()
|
||||
lines = content.splitlines()
|
||||
|
||||
def _find_func(name: str) -> tuple[int, int] | None:
|
||||
start = None
|
||||
for i, line in enumerate(lines):
|
||||
if line.startswith(f"{name}()"):
|
||||
start = i
|
||||
break
|
||||
if start is None:
|
||||
return None
|
||||
end = start
|
||||
for j in range(start + 1, len(lines)):
|
||||
if lines[j].strip() == "}":
|
||||
end = j
|
||||
break
|
||||
return start, end
|
||||
|
||||
header_parts = []
|
||||
for helper in ("mask_secrets", "log", "warn", "err", "ok", "banner", "die"):
|
||||
r = _find_func(helper)
|
||||
if r:
|
||||
header_parts.append("\n".join(lines[r[0]:r[1] + 1]))
|
||||
header = "C_RESET=''; C_BLUE=''; C_GREEN=''; C_YELLOW=''; C_RED=''; C_BOLD=''\n\n" + "\n\n".join(header_parts)
|
||||
|
||||
funcs = []
|
||||
for name in names:
|
||||
r = _find_func(name)
|
||||
if r:
|
||||
funcs.append("\n".join(lines[r[0]:r[1] + 1]))
|
||||
return header + "\n\n" + "\n\n".join(funcs) + "\n"
|
||||
|
||||
|
||||
def _run_bash(snippet: str, extra_env: dict | None = None) -> tuple[str, str, int]:
|
||||
env = {
|
||||
"PATH": "/usr/bin:/bin:/usr/local/bin",
|
||||
"HOME": "/tmp/f98-i2-home",
|
||||
}
|
||||
if extra_env:
|
||||
env.update(extra_env)
|
||||
result = subprocess.run(
|
||||
["bash", "-c", snippet],
|
||||
capture_output=True, text=True, env=env, timeout=30,
|
||||
)
|
||||
return result.stdout, result.stderr, result.returncode
|
||||
|
||||
|
||||
class TestEffectiveMultiroom:
|
||||
"""B16: effective_multiroom() — eine Wahrheitsquelle für Multiroom."""
|
||||
|
||||
def test_env_multiroom_agent_wins(self):
|
||||
snippet = (
|
||||
_extract_functions("effective_multiroom")
|
||||
+ "MULTIROOM_AGENT='false'\n"
|
||||
+ "RC_MULTIROOM='true'\n"
|
||||
+ "echo \"RESULT=$(effective_multiroom)\"\n"
|
||||
)
|
||||
out, err, rc = _run_bash(snippet)
|
||||
assert rc == 0, f"effective_multiroom crashte:\n{out}\n{err}"
|
||||
assert "RESULT=false" in out, f"env MULTIROOM_AGENT=false sollte gewinnen:\n{out}"
|
||||
|
||||
def test_dotenv_multiroom_agent_wins_over_rc(self):
|
||||
"""MULTIROOM_AGENT=false in .env gewinnt über RC_MULTIROOM=true."""
|
||||
import tempfile, os
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
hermes_dir = os.path.join(d, ".hermes")
|
||||
os.makedirs(hermes_dir)
|
||||
envfile = os.path.join(hermes_dir, ".env")
|
||||
with open(envfile, "w") as f:
|
||||
f.write("MULTIROOM_AGENT=false\n")
|
||||
snippet = (
|
||||
_extract_functions("effective_multiroom")
|
||||
+ f"HOME='{d}'\n"
|
||||
+ "RC_MULTIROOM='true'\n"
|
||||
+ "echo \"RESULT=$(effective_multiroom)\"\n"
|
||||
)
|
||||
out, err, rc = _run_bash(snippet)
|
||||
assert rc == 0
|
||||
assert "RESULT=false" in out, f".env MULTIROOM_AGENT=false sollte gewinnen:\n{out}\n{err}"
|
||||
|
||||
def test_rc_multiroom_used_when_no_env(self):
|
||||
snippet = (
|
||||
_extract_functions("effective_multiroom")
|
||||
+ "RC_MULTIROOM='false'\n"
|
||||
+ "echo \"RESULT=$(effective_multiroom)\"\n"
|
||||
)
|
||||
out, err, rc = _run_bash(snippet)
|
||||
assert rc == 0
|
||||
assert "RESULT=false" in out, f"RC_MULTIROOM=false sollte gewinnen:\n{out}"
|
||||
|
||||
def test_default_true_when_nothing_set(self):
|
||||
snippet = (
|
||||
_extract_functions("effective_multiroom")
|
||||
+ "echo \"RESULT=$(effective_multiroom)\"\n"
|
||||
)
|
||||
out, err, rc = _run_bash(snippet)
|
||||
assert rc == 0
|
||||
assert "RESULT=true" in out, f"Default sollte true sein:\n{out}"
|
||||
|
||||
|
||||
class TestGatewaySystemctlV2:
|
||||
"""B20: gateway_systemctl_v2() — Cross-User-fähiger systemctl-Wrapper."""
|
||||
|
||||
def test_function_exists(self):
|
||||
content = _read_install_sh()
|
||||
assert "gateway_systemctl_v2()" in content
|
||||
|
||||
def test_uses_machine_transport(self):
|
||||
"""Der Machine-Transport --machine=<user>@.host muss im Code stehen."""
|
||||
content = _read_install_sh()
|
||||
assert "--machine=" in content
|
||||
assert "@.host" in content
|
||||
|
||||
def test_derives_sudo_user(self):
|
||||
"""SUDO_USER-Ableitung muss vorhanden sein."""
|
||||
content = _read_install_sh()
|
||||
assert "SUDO_USER" in content
|
||||
|
||||
def test_non_root_uses_plain_user(self):
|
||||
"""Nicht-root: systemctl --user (kein Machine-Transport)."""
|
||||
# Simuliere nicht-root: id -u liefert 1000, USER=bernd.
|
||||
import tempfile, os
|
||||
fake_id = "#!/bin/bash\nif [ \"$1\" = \"-u\" ]; then echo 1000; exit 0; fi\nexit 0\n"
|
||||
fake_systemctl = "#!/bin/bash\necho \"ARGS=$*\"\n"
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
id_path = os.path.join(d, "id")
|
||||
sc_path = os.path.join(d, "systemctl")
|
||||
with open(id_path, "w") as f:
|
||||
f.write(fake_id)
|
||||
with open(sc_path, "w") as f:
|
||||
f.write(fake_systemctl)
|
||||
os.chmod(id_path, 0o755)
|
||||
os.chmod(sc_path, 0o755)
|
||||
snippet = (
|
||||
_extract_functions("gateway_systemctl_v2")
|
||||
+ "USER='bernd'\n"
|
||||
+ "gateway_systemctl_v2 is-active hermes-gateway\n"
|
||||
)
|
||||
out, err, rc = _run_bash(snippet, extra_env={"PATH": f"{d}:/usr/bin:/bin"})
|
||||
# Nicht-root → systemctl --user is-active hermes-gateway
|
||||
assert "--user" in out, f"Nicht-root sollte --user nutzen:\n{out}\n{err}"
|
||||
assert "--machine=" not in out, f"Nicht-root darf keinen Machine-Transport nutzen:\n{out}"
|
||||
|
||||
def test_root_uses_machine_transport(self):
|
||||
"""Root + SUDO_USER → --machine=<user>@.host --user."""
|
||||
import tempfile, os
|
||||
fake_id = "#!/bin/bash\nif [ \"$1\" = \"-u\" ]; then echo 0; exit 0; fi\nexit 0\n"
|
||||
fake_systemctl = "#!/bin/bash\necho \"ARGS=$*\"\n"
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
id_path = os.path.join(d, "id")
|
||||
sc_path = os.path.join(d, "systemctl")
|
||||
with open(id_path, "w") as f:
|
||||
f.write(fake_id)
|
||||
with open(sc_path, "w") as f:
|
||||
f.write(fake_systemctl)
|
||||
os.chmod(id_path, 0o755)
|
||||
os.chmod(sc_path, 0o755)
|
||||
snippet = (
|
||||
_extract_functions("gateway_systemctl_v2")
|
||||
+ "USER='root'\n"
|
||||
+ "SUDO_USER='bernd'\n"
|
||||
+ "gateway_systemctl_v2 is-active hermes-gateway\n"
|
||||
)
|
||||
out, err, rc = _run_bash(snippet, extra_env={"PATH": f"{d}:/usr/bin:/bin"})
|
||||
assert "--machine=bernd@.host" in out, f"Root sollte Machine-Transport nutzen:\n{out}\n{err}"
|
||||
assert "--user" in out, f"Root sollte --user behalten:\n{out}"
|
||||
|
||||
|
||||
class TestRepairUnitMissing:
|
||||
"""B18: check_components() setzt REPAIR_UNIT_MISSING bei fehlender Unit."""
|
||||
|
||||
def test_repair_unit_missing_flag_declared(self):
|
||||
content = _read_install_sh()
|
||||
assert "REPAIR_UNIT_MISSING" in content
|
||||
|
||||
def test_check_components_checks_unit_file(self):
|
||||
content = _read_install_sh()
|
||||
assert "hermes-gateway.service" in content
|
||||
assert "Stufe 8" in content
|
||||
|
||||
def test_repair_components_has_stage_8(self):
|
||||
content = _read_install_sh()
|
||||
assert "Reparatur Stufe 8" in content
|
||||
|
||||
|
||||
class TestAskWithHelp:
|
||||
"""B9/B10/B11: ask_with_help() — [H]-Hilfe + J/N-Konsistenz."""
|
||||
|
||||
def test_ask_with_help_function_exists(self):
|
||||
content = _read_install_sh()
|
||||
assert "ask_with_help()" in content
|
||||
|
||||
def test_ask_with_help_yes(self):
|
||||
snippet = (
|
||||
_extract_functions("ask_with_help")
|
||||
+ "GUIDED_DEFAULTS=false\n"
|
||||
+ "LANG_CHOICE='de'\n"
|
||||
+ "declare -A T\n"
|
||||
+ "T[de_ask_suffix]=' [J/N/H]: '\n"
|
||||
+ "ask_with_help MY_VAR 'Frage?' 'false' 'Hilfetext' <<< 'J'\n"
|
||||
+ "echo \"MY_VAR=$MY_VAR\"\n"
|
||||
)
|
||||
out, err, rc = _run_bash(snippet)
|
||||
assert rc == 0, f"ask_with_help crashte:\n{out}\n{err}"
|
||||
assert "MY_VAR=true" in out, f"J sollte true setzen:\n{out}"
|
||||
|
||||
def test_ask_with_help_no(self):
|
||||
snippet = (
|
||||
_extract_functions("ask_with_help")
|
||||
+ "GUIDED_DEFAULTS=false\n"
|
||||
+ "LANG_CHOICE='de'\n"
|
||||
+ "declare -A T\n"
|
||||
+ "T[de_ask_suffix]=' [J/N/H]: '\n"
|
||||
+ "ask_with_help MY_VAR 'Frage?' 'true' 'Hilfetext' <<< 'N'\n"
|
||||
+ "echo \"MY_VAR=$MY_VAR\"\n"
|
||||
)
|
||||
out, err, rc = _run_bash(snippet)
|
||||
assert rc == 0
|
||||
assert "MY_VAR=false" in out, f"N sollte false setzen:\n{out}"
|
||||
|
||||
def test_ask_with_help_shows_help_then_accepts(self):
|
||||
"""H zeigt Hilfe, dann J wird akzeptiert."""
|
||||
snippet = (
|
||||
_extract_functions("ask_with_help")
|
||||
+ "GUIDED_DEFAULTS=false\n"
|
||||
+ "LANG_CHOICE='de'\n"
|
||||
+ "declare -A T\n"
|
||||
+ "T[de_ask_suffix]=' [J/N/H]: '\n"
|
||||
+ "ask_with_help MY_VAR 'Frage?' 'false' 'HILFETEXT-MARKER' <<< $'H\\nJ'\n"
|
||||
+ "echo \"MY_VAR=$MY_VAR\"\n"
|
||||
)
|
||||
out, err, rc = _run_bash(snippet)
|
||||
assert rc == 0
|
||||
assert "HILFETEXT-MARKER" in out, f"H sollte Hilfe zeigen:\n{out}\n{err}"
|
||||
assert "MY_VAR=true" in out, f"J nach H sollte true setzen:\n{out}"
|
||||
|
||||
def test_ask_with_help_default_on_empty(self):
|
||||
snippet = (
|
||||
_extract_functions("ask_with_help")
|
||||
+ "GUIDED_DEFAULTS=false\n"
|
||||
+ "LANG_CHOICE='de'\n"
|
||||
+ "declare -A T\n"
|
||||
+ "T[de_ask_suffix]=' [J/N/H]: '\n"
|
||||
+ "ask_with_help MY_VAR 'Frage?' 'true' 'Hilfetext' <<< ''\n"
|
||||
+ "echo \"MY_VAR=$MY_VAR\"\n"
|
||||
)
|
||||
out, err, rc = _run_bash(snippet)
|
||||
assert rc == 0
|
||||
assert "MY_VAR=true" in out, f"Default sollte bei leerer Eingabe greifen:\n{out}"
|
||||
|
||||
def test_language_pack_has_help_keys(self):
|
||||
content = _read_install_sh()
|
||||
assert "T[de_multiroom_help]" in content
|
||||
assert "T[en_multiroom_help]" in content
|
||||
assert "T[de_profile_help]" in content
|
||||
assert "T[en_profile_help]" in content
|
||||
assert "T[de_ask_suffix]" in content
|
||||
assert "T[en_ask_suffix]" in content
|
||||
|
||||
def test_de_uses_jn_not_yn(self):
|
||||
"""B11: DE-Dialoge nutzen J)/N(), nicht Y)/N()."""
|
||||
content = _read_install_sh()
|
||||
# Der DE-Multiroom-Text darf kein Y) mehr enthalten.
|
||||
assert "J) Ja" in content
|
||||
# EN behält Y/N (korrekt).
|
||||
assert "Y) Yes" in content
|
||||
Reference in New Issue
Block a user