feat(F556): ROCKETCHAT_SKIP_ADAPTER via kanonischem get_scoped_secret @implements: [F-556]

This commit is contained in:
Bernd (Hermes)
2026-09-26 11:31:27 +02:00
parent b96ac54770
commit 7aba317f04
3 changed files with 68 additions and 54 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
# Projekt-STATUS — Hermes Rocket.Chat Plugin
> **Stand:** 26. September 2026 — F556 IMPLEMENTIERUNG Variante C (Multi-Profil-Adapter-Reduktion, ROCKETCHAT_SKIP_ADAPTER). @implements [F-556]. **F556 (Implementierung, Bit 6):** Plugin-Layer-Lösung gegen Mehrfach-Antworten — Hermes-Multiplex startete für jedes Profil (don/finn/miguel/rainer/viola) einen eigenen RC-Adapter, alle subscribe dieselben Räume. Variante A (Credentials aus Profil-.env) und B (`enabled: false`) scheiterten (Credentials-Vererbung bzw. Multiplex ignoriert den Key für Profil-Adapter). Variante C: `plugin/__init__.py` prüft in `validate_config()` das Flag `ROCKETCHAT_SKIP_ADAPTER` — Auflösung secret_scope → os.environ → config.extra; gesetzt → `validate_config()` False → `create_adapter()` None → Adapter wird nicht instanziiert. Nur das Default-Profil (kein Flag) startet einen Adapter. CLI-Delegation (`hermes chat --profile`) startet keinen Gateway-Adapter → unbeeinträchtigt. KEINE Core-Änderungen. Test `tests/test_f556_skip_adapter.py` (29 Tests), Doku `INSTALL.md` + `templates/.env`.
> **Stand:** 26. September 2026 — F556 IMPLEMENTIERUNG Variante C (Multi-Profil-Adapter-Reduktion, ROCKETCHAT_SKIP_ADAPTER). @implements [F-556]. **F556 (Implementierung, Bit 6):** Plugin-Layer-Lösung gegen Mehrfach-Antworten — Hermes-Multiplex startete für jedes Profil (don/finn/miguel/rainer/viola) einen eigenen RC-Adapter, alle subscribe dieselben Räume. Variante A (Credentials aus Profil-.env) und B (`enabled: false`) scheiterten (Credentials-Vererbung bzw. Multiplex ignoriert den Key für Profil-Adapter). Variante C: `plugin/__init__.py` prüft in `validate_config()` das Flag `ROCKETCHAT_SKIP_ADAPTER` — kanonische scoped-secret-Lesung `gateway.platforms._shared.get_scoped_secret` (fail-closed, kein os.environ-Ausleihen) → gesetzt → `validate_config()` False → `create_adapter()` None → Adapter wird nicht instanziiert. Nur das Default-Profil (kein Flag) startet einen Adapter. CLI-Delegation (`hermes chat --profile`) startet keinen Gateway-Adapter → unbeeinträchtigt. KEINE Core-Änderungen. Test `tests/test_f556_skip_adapter.py` (29 Tests), Doku `INSTALL.md` + `templates/.env`.
> **Letzter fachlicher Commit:** `feat(F553): main_agent Counter-Leak Fix — Lifecycle-Tracker (Variante B) @implements: [F-553]` (`fcf0851`, 23.09.2026)
> **Gitea-Remote:** ✅ Synchron — `fcf0851` + `07be8ba` + `b533320` + `786fa04` + `b175765` + `9b8ad40` + `97d5d88` + `a1af777` + `60103ed` + `c509876` + `dafd72f` + `3dcd024` + `eec8904` + `e02d34e` + `a24dc9d` + `8a00c39` + `f81a510` + `221500e` + `32b560d` + `31ca0f2` + `df8be1c` + `500c28a` + `f165f11` + `4ea711c` + `5027738` + `117b839` + `b8373d3` + `25678c6` + `bb91468` + `a1f4ed0` + `f0f3537` + `ebd057e` + `0d9275d` + `6e8854d` + `b61e19d` + `05531f1` gepusht auf origin/main.
> **Deployment:** ✅ .101 deployed bei `b533320` (Plugin v10.4 — F551+F552). 112 Features GRÜN, 2 verworfen (grau). F553 NOCH NICHT deployed (Bit 7/8 QG ausstehend).
+18 -18
View File
@@ -119,32 +119,32 @@ def _skip_adapter_flag(config) -> bool:
Unter Hermes-Multiplex wird ein Satelliten-Profil (don/finn/miguel/rainer/viola)
innerhalb von ``_profile_runtime_scope()`` gestartet. Dessen eigenes ``.env`` ist
NUR über ``agent.secret_scope.get_secret()`` lesbar — ein pauschales
``os.getenv()`` fällt auf das geerbte Prozess-Env des Default-Profils zurück und
sähe das Satelliten-Flag NICHT (genau der Grund, warum Variante A/B scheiterten).
NUR über die scoped-secret-Lesung lesbar — ein pauschales ``os.getenv()`` fällt
auf das geerbte Prozess-Env des Default-Profils zurück und sähe das Satelliten-Flag
NICHT (genau der Grund, warum Variante A/B scheiterten).
Auflösungs-Reihenfolge (erste gesetzte Quelle gewinnt):
1. ``agent.secret_scope.get_secret('ROCKETCHAT_SKIP_ADAPTER')`` (Satelliten-.env)
2. ``os.environ['ROCKETCHAT_SKIP_ADAPTER']`` (Default/Prozess-Env)
3. ``config.extra['skip_adapter']`` (config.yaml-Steuerung)
Kanonische Lesung: ``gateway.platforms._shared.get_scoped_secret`` — die EINE
scoped-secret-Implementierung des Core (gateway/AGENTS.md § Profile scope). Sie
liefert unter einem Satelliten-Scope den eigenen ``.env``-Wert, beim Default-Profil
(unscoped) dessen ``os.environ``-Wert, und single-profile liest ``os.environ``.
Die Adapter-eigene Nachbau-Form (``try get_secret / except: os.getenv``) ist laut
Core explizit verboten (Fallback-after-miss-Leak) — deshalb hier NICHT verwendet.
``validate_config()`` liefert bei gesetztem Flag False → ``create_adapter()``
liefert None → der Adapter wird NICHT instanziiert. Der CLI-Pfad (hermes chat
--profile) startet keinen Gateway-Adapter und ist damit unberührt.
"""
# 1) Secret-Scope (Multiplex-Satellit): eigenes .env des Profils.
# 1) Kanonische scoped-secret-Lesung (Satelliten-.env bzw. Default-Env).
try:
from agent.secret_scope import get_secret
secret_val = get_secret("ROCKETCHAT_SKIP_ADAPTER", None)
if secret_val is not None and str(secret_val).strip():
return _truthy(secret_val)
from gateway.platforms._shared import get_scoped_secret
val = get_scoped_secret("ROCKETCHAT_SKIP_ADAPTER", None)
except Exception:
pass
# 2) Prozess-/Default-Env.
env_val = os.getenv("ROCKETCHAT_SKIP_ADAPTER")
if env_val is not None and env_val.strip():
return _truthy(env_val)
# 3) config.yaml extra.
# Core nicht importierbar (z.B. Unit-Test-Kontext ohne gateway-Package) →
# Fallback auf os.environ (single-profile-Pfad).
val = os.getenv("ROCKETCHAT_SKIP_ADAPTER")
if val is not None and str(val).strip():
return _truthy(val)
# 2) config.yaml extra (opt-in Steuerung, z.B. platforms.rocketchat.extra.skip_adapter).
extra = getattr(config, "extra", {}) or {}
extra_val = extra.get("skip_adapter")
if extra_val is not None and str(extra_val).strip():
+46 -32
View File
@@ -56,21 +56,26 @@ class _FakeConfig:
self.extra = extra or {}
def _fake_secret_scope(return_value):
"""Installiere ein Fake-``agent.secret_scope``-Modul in sys.modules.
def _fake_scoped_secret(return_value, importable=True):
"""Installiere ein Fake-``gateway.platforms._shared``-Modul in sys.modules.
Das Plugin importiert ``from agent.secret_scope import get_secret`` innerhalb
von ``_skip_adapter_flag``. ``agent`` existiert im Test-venv nicht — wir
injizieren ein Fake-Modul, damit der ECHTE Import-Pfad des Plugins läuft
(und nicht ein gemockter Aufruf, der am fehlenden Modul scheitert).
Das Plugin importiert ``from gateway.platforms._shared import get_scoped_secret``
innerhalb von ``_skip_adapter_flag``. Im Test-venv existiert ``gateway`` nicht.
Wir injizieren ein Fake-Modul, damit der ECHTE Import-Pfad des Plugins läuft.
``importable=False`` lässt das Modul weg → das Plugin fällt auf os.environ zurück
(der single-profile/unit-test-Fallback).
"""
if not importable:
return {}
import types
fake = types.ModuleType("agent.secret_scope")
fake.get_secret = lambda name, default=None: return_value
parent = types.ModuleType("agent")
parent.secret_scope = fake
return {"agent": parent, "agent.secret_scope": fake}
fake = types.ModuleType("gateway.platforms._shared")
fake.get_scoped_secret = lambda name, default=None: return_value
plats = types.ModuleType("gateway.platforms")
plats._shared = fake
gw = types.ModuleType("gateway")
gw.platforms = plats
return {"gateway": gw, "gateway.platforms": plats, "gateway.platforms._shared": fake}
# ═══════════════════════════════════════════════════════════════════════════
@@ -96,56 +101,65 @@ class TestSkipAdapterFlag:
"""Kein Flag in irgendeiner Quelle → kein Skip."""
cfg = _FakeConfig()
os.environ.pop("ROCKETCHAT_SKIP_ADAPTER", None)
with patch.dict(sys.modules, _fake_secret_scope(None)):
with patch.dict(sys.modules, _fake_scoped_secret(None)):
assert _skip_adapter_flag(cfg) is False
def test_secret_scope_true_skips(self):
"""Satellit: Flag im secret_scope (.env) → Skip."""
cfg = _FakeConfig()
os.environ.pop("ROCKETCHAT_SKIP_ADAPTER", None)
with patch.dict(sys.modules, _fake_secret_scope("true")):
with patch.dict(sys.modules, _fake_scoped_secret("true")):
assert _skip_adapter_flag(cfg) is True
def test_secret_scope_false_does_not_skip(self):
"""Satellit: Flag=false im secret_scope → kein Skip (explizit deaktiviert)."""
cfg = _FakeConfig()
os.environ.pop("ROCKETCHAT_SKIP_ADAPTER", None)
with patch.dict(sys.modules, _fake_secret_scope("false")):
with patch.dict(sys.modules, _fake_scoped_secret("false")):
assert _skip_adapter_flag(cfg) is False
def test_secret_scope_missing_falls_through_to_env(self):
"""secret_scope liefert None → Fallthrough auf os.environ."""
cfg = _FakeConfig()
with patch.dict(sys.modules, _fake_secret_scope(None)):
with patch.dict(os.environ, {"ROCKETCHAT_SKIP_ADAPTER": "true"}):
assert _skip_adapter_flag(cfg) is True
def test_scoped_miss_fails_closed_does_not_borrow_env(self):
"""Scoped miss (get_scoped_secret → None) leiht NICHT os.environ aus (fail-closed).
def test_env_true_skips(self):
"""Default/Prozess: Flag im os.environ → Skip."""
Das ist der kanonische Multiplex-Vertrag: ein Satellit ohne eigenes Flag
darf NICHT das Flag eines anderen Profils aus os.environ übernehmen.
Das Plugin liest ausschließlich get_scoped_secret; ein None-Ergebnis
bedeutet „kein Flag“ → kein Skip (Adapter startet).
"""
cfg = _FakeConfig()
with patch.dict(sys.modules, _fake_secret_scope(None)):
with patch.dict(os.environ, {"ROCKETCHAT_SKIP_ADAPTER": "1"}):
with patch.dict(sys.modules, _fake_scoped_secret(None)):
with patch.dict(os.environ, {"ROCKETCHAT_SKIP_ADAPTER": "true"}):
assert _skip_adapter_flag(cfg) is False
def test_scoped_true_skips_default_profile(self):
"""get_scoped_secret liefert '1' (Default-Profil/scoped) → Skip."""
cfg = _FakeConfig()
with patch.dict(sys.modules, _fake_scoped_secret("1")):
assert _skip_adapter_flag(cfg) is True
def test_config_extra_true_skips(self):
"""config.yaml: extra['skip_adapter'] → Skip."""
cfg = _FakeConfig(extra={"skip_adapter": "yes"})
os.environ.pop("ROCKETCHAT_SKIP_ADAPTER", None)
with patch.dict(sys.modules, _fake_secret_scope(None)):
with patch.dict(sys.modules, _fake_scoped_secret(None)):
assert _skip_adapter_flag(cfg) is True
def test_secret_scope_takes_priority_over_env(self):
"""secret_scope=false gewinnt über os.environ=true."""
cfg = _FakeConfig()
with patch.dict(sys.modules, _fake_secret_scope("false")):
with patch.dict(sys.modules, _fake_scoped_secret("false")):
with patch.dict(os.environ, {"ROCKETCHAT_SKIP_ADAPTER": "true"}):
assert _skip_adapter_flag(cfg) is False
def test_secret_scope_import_error_degrades_to_env(self):
"""agent.secret_scope nicht importierbar → graceful Fallthrough auf env."""
def test_scoped_secret_import_error_degrades_to_env(self):
"""gateway.platforms._shared nicht importierbar → Fallback auf os.environ (single-profile/Unit-Test)."""
cfg = _FakeConfig()
# Kein Fake-Modul installiert → der try/except-Import im Plugin schlägt fehl
# und der Code fällt auf os.environ zurück.
# und der Code fällt auf os.environ zurück (single-profile-Pfad).
with patch.dict(sys.modules, {}, clear=False):
sys.modules.pop("gateway", None)
sys.modules.pop("gateway.platforms", None)
sys.modules.pop("gateway.platforms._shared", None)
with patch.dict(os.environ, {"ROCKETCHAT_SKIP_ADAPTER": "true"}):
assert _skip_adapter_flag(cfg) is True
@@ -159,21 +173,21 @@ class TestValidateConfig:
"""Selbst mit gültigen Credentials liefert validate_config False bei Flag."""
cfg = _FakeConfig(extra={"base_url": "https://rc", "user": "b", "password": "p"})
os.environ.pop("ROCKETCHAT_SKIP_ADAPTER", None)
with patch.dict(sys.modules, _fake_secret_scope("true")):
with patch.dict(sys.modules, _fake_scoped_secret("true")):
assert validate_config(cfg) is False
def test_no_flag_with_credentials_is_true(self):
"""Kein Flag + gültige Credentials → True (Adapter darf starten)."""
cfg = _FakeConfig(extra={"base_url": "https://rc", "user": "b", "password": "p"})
os.environ.pop("ROCKETCHAT_SKIP_ADAPTER", None)
with patch.dict(sys.modules, _fake_secret_scope(None)):
with patch.dict(sys.modules, _fake_scoped_secret(None)):
assert validate_config(cfg) is True
def test_no_flag_without_credentials_is_false(self):
"""Kein Flag + fehlende Credentials → False (unverändertes Verhalten)."""
cfg = _FakeConfig()
os.environ.pop("ROCKETCHAT_SKIP_ADAPTER", None)
with patch.dict(sys.modules, _fake_secret_scope(None)):
with patch.dict(sys.modules, _fake_scoped_secret(None)):
os.environ.pop("ROCKETCHAT_BASE_URL", None)
os.environ.pop("ROCKETCHAT_USER", None)
os.environ.pop("ROCKETCHAT_PASSWORD", None)