release: neutralized public connector catalog (R1-R5 transform + A3 neutralization)
This commit is contained in:
+72
-72
@@ -1,15 +1,15 @@
|
||||
"""F454 PMDB Connector Plugin — Tests (Phase 1 + Phase 2).
|
||||
"""F-XXX PMDB Connector Plugin — Tests (Phase 1 + Phase 2).
|
||||
|
||||
@implements: [F454]
|
||||
@implements: [F-XXX]
|
||||
|
||||
Zwei Test-Ebenen:
|
||||
1. Unit-Tests (kein Netzwerk): client.py Error-Mapping, config.py
|
||||
Token-Aufloesung, __init__.py Tool-Registrierung (Mock-ctx).
|
||||
2. Integration-Tests (gegen Live-PMDB auf .49, via Env PMDB_TEST_TOKEN
|
||||
2. Integration-Tests (gegen Live-PMDB auf der zentralen PMDB, via Env PMDB_TEST_TOKEN
|
||||
aktiviert): echte HTTP-Calls gegen /mcp/api/*.
|
||||
|
||||
Die Unit-Tests laufen ueberall (stdlib-only). Die Integration-Tests sind
|
||||
standardmaessig SKIPPED (kein Token) und werden auf .49 mit einem echten
|
||||
standardmaessig SKIPPED (kein Token) und werden auf der zentralen PMDB mit einem echten
|
||||
Test-Token aktiviert.
|
||||
|
||||
Test-Daten-Hygiene (P-191): Integration-Tests legen eigene Credentials/Tasks
|
||||
@@ -34,14 +34,14 @@ import plugin.pmdb_connector as pmdb_plugin # noqa: E402
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# F590: Isolation der kanonischen Token-Quelle mcp_tokens.json
|
||||
# F-XXX: Isolation der kanonischen Token-Quelle mcp_tokens.json
|
||||
# ---------------------------------------------------------------------------
|
||||
@pytest.fixture(autouse=True)
|
||||
def _isolate_mcp_tokens(monkeypatch, tmp_path):
|
||||
"""Isoliert mcp_tokens.json von der echten Produktions-Datei.
|
||||
|
||||
F590: ``resolve_token()`` liest jetzt ZUERST mcp_tokens.json. Tests, die
|
||||
den config.yaml-Fallback (F526) testen, muessen die kanonische Quelle
|
||||
F-XXX: ``resolve_token()`` liest jetzt ZUERST mcp_tokens.json. Tests, die
|
||||
den config.yaml-Fallback (F-XXX) testen, muessen die kanonische Quelle
|
||||
isolieren — sonst liefert die echte ``~/.hermes/mcp_tokens.json`` den
|
||||
echten Produktions-Token und die Assertions brechen (Token-Drift in den
|
||||
Tests). Der Pfad zeigt auf eine nicht-existente Temp-Datei -> leerer
|
||||
@@ -185,31 +185,31 @@ def test_client_submit_task_sends_payload(monkeypatch):
|
||||
# Unit: config.py Token-Aufloesung
|
||||
# ---------------------------------------------------------------------------
|
||||
def test_resolve_token_profile_specific():
|
||||
cfg = {"auth_keys": {"miguel": "mcp_miguel_x", "default": "mcp_bernd_y"}}
|
||||
assert pmdb_config.resolve_token("miguel", cfg) == "mcp_miguel_x"
|
||||
cfg = {"auth_keys": {"team": "mcp_<agent>_x", "default": "mcp_<agent>_y"}}
|
||||
assert pmdb_config.resolve_token("team", cfg) == "mcp_<agent>_x"
|
||||
|
||||
|
||||
def test_resolve_token_falls_back_to_default():
|
||||
cfg = {"auth_keys": {"default": "mcp_bernd_y"}}
|
||||
assert pmdb_config.resolve_token("rainer", cfg) == "mcp_bernd_y"
|
||||
cfg = {"auth_keys": {"default": "mcp_<agent>_y"}}
|
||||
assert pmdb_config.resolve_token("team", cfg) == "mcp_<agent>_y"
|
||||
|
||||
|
||||
def test_resolve_token_missing_returns_none(monkeypatch):
|
||||
# F526: Fallback-Kette liest Basis-/Profile-Config vom Filesystem.
|
||||
# F-XXX: Fallback-Kette liest Basis-/Profile-Config vom Filesystem.
|
||||
# Für den deterministischen None-Fall die Filesystem-Lookups mocken.
|
||||
monkeypatch.setattr(pmdb_config, "_base_config_path", lambda: None)
|
||||
monkeypatch.setattr(pmdb_config, "_profile_auth_keys", lambda p: {})
|
||||
assert pmdb_config.resolve_token("rainer", {}) is None
|
||||
assert pmdb_config.resolve_token("rainer", {"auth_keys": {}}) is None
|
||||
assert pmdb_config.resolve_token("team", {}) is None
|
||||
assert pmdb_config.resolve_token("team", {"auth_keys": {}}) is None
|
||||
|
||||
|
||||
def test_token_prefix_masks_secret():
|
||||
assert pmdb_config.token_prefix("mcp_miguel_geheim123") == "mcp_miguel_***"
|
||||
assert "geheim123" not in pmdb_config.token_prefix("mcp_miguel_geheim123")
|
||||
assert pmdb_config.token_prefix("mcp_<agent>_geheim123") == "mcp_<agent>_***"
|
||||
assert "geheim123" not in pmdb_config.token_prefix("mcp_<agent>_geheim123")
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# F590: Token-Sync aus mcp_tokens.json (kanonische Quelle)
|
||||
# F-XXX: Token-Sync aus mcp_tokens.json (kanonische Quelle)
|
||||
# ---------------------------------------------------------------------------
|
||||
def _write_mcp_tokens(tmp_path, agenten):
|
||||
path = tmp_path / "mcp_tokens.json"
|
||||
@@ -226,7 +226,7 @@ def test_mcp_tokens_path_default(monkeypatch):
|
||||
|
||||
def test_mcp_tokens_path_hermes_home_is_profile(monkeypatch, tmp_path):
|
||||
"""HERMES_HOME=Profil-Verzeichnis -> Basis-Parent/mcp_tokens.json."""
|
||||
prof = tmp_path / "profiles" / "miguel"
|
||||
prof = tmp_path / "profiles" / "team"
|
||||
prof.mkdir(parents=True)
|
||||
monkeypatch.delenv("HERMES_MCP_TOKENS", raising=False)
|
||||
monkeypatch.setenv("HERMES_HOME", str(prof))
|
||||
@@ -246,62 +246,62 @@ def test_load_mcp_tokens_missing_returns_empty(monkeypatch, tmp_path):
|
||||
|
||||
|
||||
def test_load_mcp_tokens_reads_agenten(monkeypatch, tmp_path):
|
||||
path = _write_mcp_tokens(tmp_path, {"miguel": {"token": "mcp_miguel_x"}})
|
||||
path = _write_mcp_tokens(tmp_path, {"team": {"token": "mcp_<agent>_x"}})
|
||||
monkeypatch.setenv("HERMES_MCP_TOKENS", path)
|
||||
assert pmdb_config.load_mcp_tokens() == {"miguel": {"token": "mcp_miguel_x"}}
|
||||
assert pmdb_config.load_mcp_tokens() == {"team": {"token": "mcp_<agent>_x"}}
|
||||
|
||||
|
||||
def test_resolve_token_from_mcp_tokens_exact(monkeypatch, tmp_path):
|
||||
path = _write_mcp_tokens(tmp_path, {"miguel": {"token": "mcp_miguel_x"}})
|
||||
path = _write_mcp_tokens(tmp_path, {"team": {"token": "mcp_<agent>_x"}})
|
||||
monkeypatch.setenv("HERMES_MCP_TOKENS", path)
|
||||
assert pmdb_config.resolve_token_from_mcp_tokens("miguel") == "mcp_miguel_x"
|
||||
assert pmdb_config.resolve_token_from_mcp_tokens("team") == "mcp_<agent>_x"
|
||||
|
||||
|
||||
def test_resolve_token_from_mcp_tokens_case_insensitive(monkeypatch, tmp_path):
|
||||
"""P-194: Profil 'Miguel' (gross) matcht agenten['miguel'] (klein)."""
|
||||
path = _write_mcp_tokens(tmp_path, {"miguel": {"token": "mcp_miguel_x"}})
|
||||
"""P-194: Profil 'team' (gross) matcht agenten['team'] (klein)."""
|
||||
path = _write_mcp_tokens(tmp_path, {"team": {"token": "mcp_<agent>_x"}})
|
||||
monkeypatch.setenv("HERMES_MCP_TOKENS", path)
|
||||
assert pmdb_config.resolve_token_from_mcp_tokens("Miguel") == "mcp_miguel_x"
|
||||
assert pmdb_config.resolve_token_from_mcp_tokens("team") == "mcp_<agent>_x"
|
||||
|
||||
|
||||
def test_resolve_token_from_mcp_tokens_missing_returns_none(monkeypatch, tmp_path):
|
||||
path = _write_mcp_tokens(tmp_path, {"miguel": {"token": "mcp_miguel_x"}})
|
||||
path = _write_mcp_tokens(tmp_path, {"team": {"token": "mcp_<agent>_x"}})
|
||||
monkeypatch.setenv("HERMES_MCP_TOKENS", path)
|
||||
assert pmdb_config.resolve_token_from_mcp_tokens("rainer") is None
|
||||
assert pmdb_config.resolve_token_from_mcp_tokens("team") is None
|
||||
|
||||
|
||||
def test_resolve_token_prefers_mcp_tokens_over_config(monkeypatch, tmp_path):
|
||||
"""F590: mcp_tokens.json gewinnt gegen config.yaml auth_keys."""
|
||||
path = _write_mcp_tokens(tmp_path, {"miguel": {"token": "mcp_miguel_KANONISCH"}})
|
||||
"""F-XXX: mcp_tokens.json gewinnt gegen config.yaml auth_keys."""
|
||||
path = _write_mcp_tokens(tmp_path, {"team": {"token": "mcp_<agent>_KANONISCH"}})
|
||||
monkeypatch.setenv("HERMES_MCP_TOKENS", path)
|
||||
cfg = {"auth_keys": {"miguel": "mcp_miguel_stale"}}
|
||||
assert pmdb_config.resolve_token("miguel", cfg) == "mcp_miguel_KANONISCH"
|
||||
cfg = {"auth_keys": {"team": "mcp_<agent>_stale"}}
|
||||
assert pmdb_config.resolve_token("team", cfg) == "mcp_<agent>_KANONISCH"
|
||||
|
||||
|
||||
def test_resolve_token_falls_back_to_config_when_mcp_tokens_missing(
|
||||
monkeypatch, tmp_path):
|
||||
"""Ohne mcp_tokens.json-Eintrag greift der config.yaml-Fallback (F526)."""
|
||||
"""Ohne mcp_tokens.json-Eintrag greift der config.yaml-Fallback (F-XXX)."""
|
||||
monkeypatch.setenv("HERMES_MCP_TOKENS", str(tmp_path / "fehlt.json"))
|
||||
cfg = {"auth_keys": {"miguel": "mcp_miguel_x"}}
|
||||
assert pmdb_config.resolve_token("miguel", cfg) == "mcp_miguel_x"
|
||||
cfg = {"auth_keys": {"team": "mcp_<agent>_x"}}
|
||||
assert pmdb_config.resolve_token("team", cfg) == "mcp_<agent>_x"
|
||||
|
||||
|
||||
def test_probierte_pfade_includes_mcp_tokens(monkeypatch, tmp_path):
|
||||
"""F590: mcp_tokens.json steht an ERSTER Stelle in probierte_pfade."""
|
||||
"""F-XXX: mcp_tokens.json steht an ERSTER Stelle in probierte_pfade."""
|
||||
monkeypatch.setenv("HERMES_MCP_TOKENS", str(tmp_path / "mcp_tokens.json"))
|
||||
pfade = pmdb_config.probierte_pfade("miguel", {})
|
||||
pfade = pmdb_config.probierte_pfade("team", {})
|
||||
assert any(p.endswith("mcp_tokens.json") for p in pfade)
|
||||
assert pfade[0].endswith("mcp_tokens.json")
|
||||
|
||||
|
||||
def test_manager_profiles_default():
|
||||
assert "bernd" in pmdb_config.manager_profiles({})
|
||||
assert "andreas" in pmdb_config.manager_profiles({})
|
||||
assert "team" in pmdb_config.manager_profiles({})
|
||||
assert "team" in pmdb_config.manager_profiles({})
|
||||
|
||||
|
||||
def test_manager_profiles_custom():
|
||||
cfg = {"manager_profiles": ["bernd"]}
|
||||
assert pmdb_config.manager_profiles(cfg) == ["bernd"]
|
||||
cfg = {"manager_profiles": ["team"]}
|
||||
assert pmdb_config.manager_profiles(cfg) == ["team"]
|
||||
|
||||
|
||||
def test_base_url_default():
|
||||
@@ -314,14 +314,14 @@ def test_base_url_default():
|
||||
def test_profile_config_path_hermes_home_is_profile(monkeypatch, tmp_path):
|
||||
"""HERMES_HOME zeigt auf ein Profil-Verzeichnis -> Config liegt DIREKT dort.
|
||||
|
||||
P0-4: HERMES_HOME=$HOME/.hermes/profiles/miguel. Die Config liegt
|
||||
unter HERMES_HOME/config.yaml. Es darf NICHT erneut `profiles/miguel`
|
||||
P0-4: HERMES_HOME=$HOME/.hermes/profiles/team. Die Config liegt
|
||||
unter HERMES_HOME/config.yaml. Es darf NICHT erneut `profiles/team`
|
||||
angehaengt werden (sonst Dopplung -> token_missing).
|
||||
"""
|
||||
prof = tmp_path / "profiles" / "miguel"
|
||||
prof = tmp_path / "profiles" / "team"
|
||||
prof.mkdir(parents=True)
|
||||
monkeypatch.setenv("HERMES_HOME", str(prof))
|
||||
path = pmdb_config._profile_config_path("miguel")
|
||||
path = pmdb_config._profile_config_path("team")
|
||||
assert path == prof / "config.yaml"
|
||||
|
||||
|
||||
@@ -330,8 +330,8 @@ def test_profile_config_path_hermes_home_is_base(monkeypatch, tmp_path):
|
||||
base = tmp_path / ".hermes"
|
||||
base.mkdir(parents=True)
|
||||
monkeypatch.setenv("HERMES_HOME", str(base))
|
||||
path = pmdb_config._profile_config_path("miguel")
|
||||
assert path == base / "profiles" / "miguel" / "config.yaml"
|
||||
path = pmdb_config._profile_config_path("team")
|
||||
assert path == base / "profiles" / "team" / "config.yaml"
|
||||
|
||||
|
||||
def test_profile_config_path_default_profile(monkeypatch, tmp_path):
|
||||
@@ -346,15 +346,15 @@ def test_profile_config_path_default_profile(monkeypatch, tmp_path):
|
||||
def test_load_pmdb_config_from_profile_hermes_home(monkeypatch, tmp_path):
|
||||
"""End-to-End: HERMES_HOME=Profil-Verzeichnis -> load_pmdb_config findet
|
||||
die pmdb_connector-Sektion in HERMES_HOME/config.yaml (P0-4-Fix)."""
|
||||
prof = tmp_path / "profiles" / "miguel"
|
||||
prof = tmp_path / "profiles" / "team"
|
||||
prof.mkdir(parents=True)
|
||||
(prof / "config.yaml").write_text(
|
||||
"pmdb_connector:\n auth_keys:\n miguel: mcp_miguel_x\n",
|
||||
"pmdb_connector:\n auth_keys:\n team: mcp_<agent>_x\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
monkeypatch.setenv("HERMES_HOME", str(prof))
|
||||
cfg = pmdb_config.load_pmdb_config("miguel")
|
||||
assert cfg.get("auth_keys", {}).get("miguel") == "mcp_miguel_x"
|
||||
cfg = pmdb_config.load_pmdb_config("team")
|
||||
assert cfg.get("auth_keys", {}).get("team") == "mcp_<agent>_x"
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -371,9 +371,9 @@ class _MockCtx:
|
||||
|
||||
def test_register_all_tools(monkeypatch):
|
||||
monkeypatch.setattr(pmdb_config, "get_active_profile_name",
|
||||
lambda: "miguel")
|
||||
lambda: "team")
|
||||
monkeypatch.setattr(pmdb_config, "load_pmdb_config",
|
||||
lambda p: {"auth_keys": {"miguel": "mcp_miguel_x"}})
|
||||
lambda p: {"auth_keys": {"team": "mcp_<agent>_x"}})
|
||||
ctx = _MockCtx()
|
||||
pmdb_plugin.register(ctx)
|
||||
assert len(ctx.registered) == len(pmdb_plugin._TOOLS)
|
||||
@@ -384,9 +384,9 @@ def test_register_all_tools(monkeypatch):
|
||||
|
||||
def test_register_missing_token_deactivates(monkeypatch):
|
||||
monkeypatch.setattr(pmdb_config, "get_active_profile_name",
|
||||
lambda: "miguel")
|
||||
lambda: "team")
|
||||
monkeypatch.setattr(pmdb_config, "load_pmdb_config", lambda p: {})
|
||||
# F526: Filesystem-Fallback isolieren, damit kein realer Token geladen wird.
|
||||
# F-XXX: Filesystem-Fallback isolieren, damit kein realer Token geladen wird.
|
||||
monkeypatch.setattr(pmdb_config, "_base_config_path", lambda: None)
|
||||
monkeypatch.setattr(pmdb_config, "_profile_auth_keys", lambda p: {})
|
||||
ctx = _MockCtx()
|
||||
@@ -400,10 +400,10 @@ def test_register_missing_token_deactivates(monkeypatch):
|
||||
|
||||
def test_manager_only_guard_blocks_non_manager(monkeypatch):
|
||||
monkeypatch.setattr(pmdb_config, "get_active_profile_name",
|
||||
lambda: "miguel")
|
||||
lambda: "team")
|
||||
monkeypatch.setattr(pmdb_config, "load_pmdb_config",
|
||||
lambda p: {"auth_keys": {"miguel": "mcp_miguel_x"},
|
||||
"manager_profiles": ["bernd"]})
|
||||
lambda p: {"auth_keys": {"team": "mcp_<agent>_x"},
|
||||
"manager_profiles": ["team"]})
|
||||
ctx = _MockCtx()
|
||||
pmdb_plugin.register(ctx)
|
||||
r = json.loads(ctx.registered["pmdb_set_bit"]["handler"]({"feature_id": 1, "bit_nr": 6}))
|
||||
@@ -413,10 +413,10 @@ def test_manager_only_guard_blocks_non_manager(monkeypatch):
|
||||
|
||||
def test_manager_only_guard_blocks_get_submitted_tasks(monkeypatch):
|
||||
monkeypatch.setattr(pmdb_config, "get_active_profile_name",
|
||||
lambda: "miguel")
|
||||
lambda: "team")
|
||||
monkeypatch.setattr(pmdb_config, "load_pmdb_config",
|
||||
lambda p: {"auth_keys": {"miguel": "mcp_miguel_x"},
|
||||
"manager_profiles": ["bernd"]})
|
||||
lambda p: {"auth_keys": {"team": "mcp_<agent>_x"},
|
||||
"manager_profiles": ["team"]})
|
||||
ctx = _MockCtx()
|
||||
pmdb_plugin.register(ctx)
|
||||
r = json.loads(ctx.registered["pmdb_get_submitted_tasks"]["handler"]({}))
|
||||
@@ -425,13 +425,13 @@ def test_manager_only_guard_blocks_get_submitted_tasks(monkeypatch):
|
||||
|
||||
def test_manager_guard_case_insensitive(monkeypatch):
|
||||
# P-194: Profil-Name case-inkonsistent -> Vergleich muss case-insensitive sein.
|
||||
# Profil "Bernd" (gross) vs. manager_profiles ["bernd"] (klein) -> darf NICHT
|
||||
# Profil "team" (gross) vs. manager_profiles ["team"] (klein) -> darf NICHT
|
||||
# forbidden liefern (Guard muss case-insensitive matchen).
|
||||
monkeypatch.setattr(pmdb_config, "get_active_profile_name",
|
||||
lambda: "Bernd")
|
||||
lambda: "team")
|
||||
monkeypatch.setattr(pmdb_config, "load_pmdb_config",
|
||||
lambda p: {"auth_keys": {"Bernd": "mcp_bernd_x"},
|
||||
"manager_profiles": ["bernd"]})
|
||||
lambda p: {"auth_keys": {"team": "mcp_<agent>_x"},
|
||||
"manager_profiles": ["team"]})
|
||||
ctx = _MockCtx()
|
||||
pmdb_plugin.register(ctx)
|
||||
# Manager-Guard passiert (case-insensitive) -> Handler ruft client (Netzwerk).
|
||||
@@ -440,10 +440,10 @@ def test_manager_guard_case_insensitive(monkeypatch):
|
||||
|
||||
def test_manager_only_allows_manager(monkeypatch):
|
||||
monkeypatch.setattr(pmdb_config, "get_active_profile_name",
|
||||
lambda: "bernd")
|
||||
lambda: "team")
|
||||
monkeypatch.setattr(pmdb_config, "load_pmdb_config",
|
||||
lambda p: {"auth_keys": {"bernd": "mcp_bernd_x"},
|
||||
"manager_profiles": ["bernd"]})
|
||||
lambda p: {"auth_keys": {"team": "mcp_<agent>_x"},
|
||||
"manager_profiles": ["team"]})
|
||||
ctx = _MockCtx()
|
||||
pmdb_plugin.register(ctx)
|
||||
# Manager-Guard passiert -> Handler ruft client.set_bit (Netzwerk).
|
||||
@@ -453,7 +453,7 @@ def test_manager_only_allows_manager(monkeypatch):
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# F-719: Task-Anlagen (client.py — get_anlagen/download/upload)
|
||||
# F-XXX: Task-Anlagen (client.py — get_anlagen/download/upload)
|
||||
# ---------------------------------------------------------------------------
|
||||
class _FakeBinaryResponse:
|
||||
"""Response mit Binär-Body + Headers (fuer download_anlage)."""
|
||||
@@ -498,7 +498,7 @@ def test_client_get_anlagen_uses_internal_base(monkeypatch):
|
||||
|
||||
def test_client_download_anlage_returns_bytes(monkeypatch):
|
||||
payload = b"\x89PNG\r\n\x1a\nBINAERDATEN"
|
||||
disp = "attachment; filename*=UTF-8''bild.png"
|
||||
disp = "attachment; filename*=UTF-XXX''bild.png"
|
||||
|
||||
class _Resp:
|
||||
def __init__(self):
|
||||
@@ -545,7 +545,7 @@ def test_client_download_anlage_http_error_maps(monkeypatch):
|
||||
|
||||
def test_parse_content_disposition():
|
||||
assert pmdb_client._parse_content_disposition(
|
||||
"attachment; filename*=UTF-8''bericht.pdf") == "bericht.pdf"
|
||||
"attachment; filename*=UTF-XXX''bericht.pdf") == "bericht.pdf"
|
||||
assert pmdb_client._parse_content_disposition(
|
||||
'attachment; filename="alt.txt"') == "alt.txt"
|
||||
assert pmdb_client._parse_content_disposition("") == ""
|
||||
@@ -619,7 +619,7 @@ def test_live_get_tasks_authenticated():
|
||||
@requires_live
|
||||
def test_live_get_mask_404_or_ok():
|
||||
c = pmdb_client.PMDBClient(base_url=PMDB_TEST_BASE, token=PMDB_TEST_TOKEN)
|
||||
r = c.get_mask("F454")
|
||||
r = c.get_mask("F-XXX")
|
||||
assert "success" in r
|
||||
if r["success"]:
|
||||
assert "bit_kette" in r["data"]
|
||||
@@ -628,7 +628,7 @@ def test_live_get_mask_404_or_ok():
|
||||
@requires_live
|
||||
def test_live_search():
|
||||
c = pmdb_client.PMDBClient(base_url=PMDB_TEST_BASE, token=PMDB_TEST_TOKEN)
|
||||
r = c.search(feature="F454")
|
||||
r = c.search(feature="F-XXX")
|
||||
assert "success" in r
|
||||
if r["success"]:
|
||||
assert "setcard" in r["data"]
|
||||
|
||||
Reference in New Issue
Block a user