Files
Hermes_rocket.chat_Plugin/tests/test_f98_wizard.py
T
Bernd (Hermes) 12314cffd9 feat(F98): Guided Setup Wizard + Provider-Freiheit (12 Phasen, Flow-Spec V1)
Provider-Freiheit (Andreas-Direktive 31.08. + .45-Live-Test):
- detect_provider() P1-P6: lokales Ollama/DGX Spark ohne Key, openrouter/
  ollama-cloud/custom mit Key, P6 = Empfehlungs-Block statt Abbruch
- Root-Cause A: hardcoded provider=ollama-cloud (Z.1018) entfernt
- Root-Cause D: Key-Zwang-Hardabort entschärft — Cloud-Key NUR bei
  Cloud-Provider, lokale Inference braucht keinen Key
- Root-Cause I: verify_installation Provider-Vergleich statt String-Gleichheit
- Root-Cause C: auxiliary.* folgt erkanntem Provider

Guided Setup Wizard (additive Schicht, kein separater Installer):
- --guided/--defaults/--resume Flags
- 12 Phasen: Sprache, System-Analyse, Profil, Multiroom, RC-Verbindung
  (LIVE-Tests + Fehlerzweige), Secrets (maskiert), DM-Homechannel,
  Themenräume, Auto-Install, Backup (P-164), Resume, Proof-Run, Abschluss
- Sprach-Pack DE/EN (declare -A T), Selbsterklärend-Regel (5 Punkte)
- Secret-Maskierung (mask_secrets, read -s, --defaults maskiert)
- setup_requirements.txt als Single Source of Truth

Tests: 35 neue A1c-Tests (test_f98_wizard.py), alle grün.
Live verifiziert auf .45: Dialog erscheint statt OLLAMA-Key-Abort,
DGX Spark (P2) wird erkannt.
2026-08-31 17:42:43 +02:00

294 lines
14 KiB
Python

"""
F98: Guided Setup Wizard — install.sh Tests (TDD).
Testet die F98-Wizard-Schicht (additiv zu install.sh):
1. Provider-Freiheit: KEIN hardcoded provider=ollama-cloud (Root-Cause A)
2. Provider-Detection P1-P6 (detect_provider)
3. Layout-Detection (detect_install_layout)
4. Key-Zwang entschärft (Root-Cause D): KEIN `die "Abbruch: erforderliche Secrets fehlen"`
bei lokaler Inference
5. Wizard-Flags (--guided/--defaults/--resume) geparst
6. Sprach-Pack (DE/EN) vorhanden
7. Secret-Maskierung (mask_secrets)
8. setup_requirements.txt als Single Source of Truth
9. Selbsterklärend-Regel: Ausweich-Optionen (SKIP), kein Abbruch ohne Cloud-Key
"""
from __future__ import annotations
import re
import subprocess
from pathlib import Path
import pytest
INSTALL_SH = Path(__file__).resolve().parents[1] / "install.sh"
SETUP_REQ = Path(__file__).resolve().parents[1] / "setup_requirements.txt"
def _read_install_sh() -> str:
return INSTALL_SH.read_text()
# ═══════════════════════════════════════════════════════════════════════════
# Test 1: Syntax
# ═══════════════════════════════════════════════════════════════════════════
class TestInstallShSyntax:
def test_bash_syntax_ok(self):
if not INSTALL_SH.exists():
pytest.skip("install.sh nicht gefunden")
result = subprocess.run(
["bash", "-n", str(INSTALL_SH)],
capture_output=True, text=True,
)
assert result.returncode == 0, f"bash -n failed:\n{result.stderr}"
# ═══════════════════════════════════════════════════════════════════════════
# Test 2: Provider-Freiheit (Root-Cause A) — kein hardcoded ollama-cloud
# ═══════════════════════════════════════════════════════════════════════════
class TestProviderFreedom:
def test_no_hardcoded_provider_ollama_cloud(self):
"""write_config_yaml darf KEIN `local provider="ollama-cloud"` mehr haben."""
content = _read_install_sh()
assert 'local provider="ollama-cloud"' not in content, (
"hardcoded provider=ollama-cloud noch vorhanden (Root-Cause A)"
)
def test_detect_provider_function_exists(self):
content = _read_install_sh()
assert "detect_provider()" in content, "detect_provider() fehlt"
def test_detect_provider_has_p1_p6(self):
"""Detection-Reihenfolge P1-P6 muss vorhanden sein."""
content = _read_install_sh()
for marker in ["P1", "P2", "P3", "P4", "P6"]:
assert marker in content, f"Detection-Marker {marker} fehlt"
def test_detect_provider_local_ollama_no_key(self):
"""P1 (lokales Ollama) → provider=ollama, KEIN Key."""
content = _read_install_sh()
# P1-Block muss PROVIDER=ollama + PROVIDER_NEEDS_KEY=false setzen
assert "PROVIDER=\"ollama\"" in content
assert "PROVIDER_NEEDS_KEY=false" in content
def test_verify_installation_provider_compare_not_string_equality(self):
"""verify_installation nutzt Provider-Vergleich, nicht String-Gleichheit (Root-Cause I)."""
content = _read_install_sh()
# Der alte hardcoded Check `grep -q "^ provider: ollama-cloud"` darf nicht mehr da sein
assert 'grep -q "^ provider: ollama-cloud"' not in content, (
"verify_installation prüft noch hardcoded ollama-cloud (Root-Cause I)"
)
# Neuer Provider-Vergleich (case mit gültigen Providern)
assert "ollama|custom|openrouter|ollama-cloud" in content
# ═══════════════════════════════════════════════════════════════════════════
# Test 3: Key-Zwang entschärft (Root-Cause D)
# ═══════════════════════════════════════════════════════════════════════════
class TestNoKeyCoercion:
def test_no_die_abort_secrets_missing(self):
"""KEIN `die "Abbruch: erforderliche Secrets fehlen"` mehr (Root-Cause D)."""
content = _read_install_sh()
# Der alte Hardabort (exakt diese die-Zeile) darf nicht mehr existieren.
# Der neue die-Aufruf enthält den Zusatz "(oder nutze --guided)".
assert 'die "Abbruch: erforderliche Secrets fehlen"\n' not in content, (
"Key-Zwang-Hardabort noch vorhanden (Root-Cause D)"
)
# Der neue die-Aufruf verweist auf --guided (Ausweich statt Abbruch).
assert 'die "Abbruch: erforderliche Secrets fehlen (oder nutze --guided)"' in content
def test_cloud_key_only_for_cloud_provider(self):
"""Cloud-Key NUR bei Cloud-Provider (ollama-cloud/openrouter)."""
content = _read_install_sh()
assert 'PROVIDER" = "ollama-cloud"' in content or 'PROVIDER" = "ollama-cloud"' in content
assert "OPENROUTER_API_KEY fehlt" in content
def test_guided_skips_password_userid_check(self):
"""Im Guided-Modus werden Password/User-ID im Dialog abgefragt, nicht erzwungen."""
content = _read_install_sh()
assert "if ! $GUIDED; then" in content
# ═══════════════════════════════════════════════════════════════════════════
# Test 4: Wizard-Flags
# ═══════════════════════════════════════════════════════════════════════════
class TestWizardFlags:
def test_guided_flag_parsed(self):
content = _read_install_sh()
assert "--guided) GUIDED=true" in content
def test_defaults_flag_parsed(self):
content = _read_install_sh()
assert "--defaults) GUIDED_DEFAULTS=true" in content
def test_resume_flag_parsed(self):
content = _read_install_sh()
assert "--resume) RESUME=true" in content
def test_guided_flag_declared(self):
content = _read_install_sh()
assert "GUIDED=false" in content
assert "GUIDED_DEFAULTS=false" in content
assert "RESUME=false" in content
def test_run_guided_wizard_function_exists(self):
content = _read_install_sh()
assert "run_guided_wizard()" in content
def test_wizard_dispatched_in_main_flow(self):
content = _read_install_sh()
assert "if $GUIDED; then" in content
assert "run_guided_wizard" in content
# ═══════════════════════════════════════════════════════════════════════════
# Test 5: Sprach-Pack (DE/EN)
# ═══════════════════════════════════════════════════════════════════════════
class TestLanguagePack:
def test_language_pack_declared(self):
content = _read_install_sh()
assert "declare -A T" in content
def test_de_en_strings_present(self):
content = _read_install_sh()
assert "T[de_lang_q]" in content
assert "T[en_lang_q]" in content
assert "T[de_multiroom_q]" in content
assert "T[en_multiroom_q]" in content
def test_language_selection_phase0(self):
content = _read_install_sh()
assert "LANG_CHOICE" in content
# ═══════════════════════════════════════════════════════════════════════════
# Test 6: Secret-Maskierung
# ═══════════════════════════════════════════════════════════════════════════
class TestSecretMasking:
def test_mask_secrets_function_exists(self):
content = _read_install_sh()
assert "mask_secrets()" in content
def test_mask_secrets_filters_keys(self):
content = _read_install_sh()
assert "OPENROUTER_API_KEY" in content
assert "OLLAMA_CLOUD_API_KEY" in content
assert "ROCKETCHAT_PASSWORD" in content
assert "***masked***" in content
def test_password_read_silent(self):
"""Kennwort-Eingabe nutzt read -s (unsichtbar)."""
content = _read_install_sh()
assert "read -rs" in content or "read -s" in content
# ═══════════════════════════════════════════════════════════════════════════
# Test 7: setup_requirements.txt (Single Source of Truth)
# ═══════════════════════════════════════════════════════════════════════════
class TestSetupRequirements:
def test_setup_requirements_exists(self):
assert SETUP_REQ.exists(), "setup_requirements.txt fehlt"
def test_setup_requirements_format(self):
"""Format: modulname|pip_name|min_version|severity."""
for line in SETUP_REQ.read_text().splitlines():
line = line.strip()
if not line or line.startswith("#"):
continue
parts = line.split("|")
assert len(parts) == 4, f"Zeile hat nicht 4 Felder: {line}"
assert parts[3] in ("HARD", "SOFT"), f"severity ungültig: {line}"
def test_wizard_reads_setup_requirements(self):
content = _read_install_sh()
assert "setup_requirements.txt" in content
# ═══════════════════════════════════════════════════════════════════════════
# Test 8: Selbsterklärend-Regel (Ausweich-Optionen, kein Abbruch)
# ═══════════════════════════════════════════════════════════════════════════
class TestSelfExplainingRule:
def test_skip_option_present(self):
"""Ausweich-Option 'SKIP' (Später konfigurieren) vorhanden."""
content = _read_install_sh()
assert "SKIP" in content
def test_allow_skip_parameter(self):
content = _read_install_sh()
assert "allow_skip" in content
def test_p6_recommendation_block_no_abort(self):
"""P6 (nichts erkannt) → Empfehlungs-Block, KEIN Abbruch."""
content = _read_install_sh()
assert "Empfohlene Reihenfolge" in content
def test_missing_requirements_collected(self):
"""Defizite werden gesammelt (MISSING_REQUIREMENTS), nicht einzeln abgebrochen."""
content = _read_install_sh()
assert "MISSING_REQUIREMENTS" in content
def test_backup_dir_p164(self):
"""Backup vor schreibender Phase (P-164)."""
content = _read_install_sh()
assert "hermes-install-backup" in content
# ═══════════════════════════════════════════════════════════════════════════
# Test 9: Layout-Detection (V1.3-korrigiert §7.7)
# ═══════════════════════════════════════════════════════════════════════════
class TestLayoutDetection:
def test_detect_install_layout_exists(self):
content = _read_install_sh()
assert "detect_install_layout()" in content
def test_layout_values(self):
content = _read_install_sh()
assert "root_fhs" in content
assert "pipx" in content
assert "user_space" in content
# ═══════════════════════════════════════════════════════════════════════════
# Test 10: Proof-Run + Abschluss (Phase 10/11)
# ═══════════════════════════════════════════════════════════════════════════
class TestProofAndSummary:
def test_proof_run_function_exists(self):
content = _read_install_sh()
assert "run_proof_and_summary()" in content
def test_proof_checks_gateway_and_health(self):
content = _read_install_sh()
assert "gateway_is_active" in content
assert "/health" in content
def test_nachhol_liste(self):
content = _read_install_sh()
assert "Nachhol-Liste" in content
def test_resume_repair_hints(self):
content = _read_install_sh()
assert "--guided --resume" in content
assert "--repair" in content