mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-06-16 09:45:24 -04:00
refactor(tests): add shared CLI test helpers
Adds shared test helpers for CLI script loading and scoped core.database stubs, then converts a low-conflict pilot set of CLI tests. Part of #2523.
This commit is contained in:
committed by
GitHub
parent
cf5c5118d8
commit
dd1fa7e1c4
@@ -4,27 +4,10 @@
|
||||
`if redact_env and env_obj:` then called `env_obj.items()` -> AttributeError.
|
||||
Guard with isinstance(dict).
|
||||
"""
|
||||
import importlib.machinery
|
||||
import importlib.util
|
||||
import sys
|
||||
import types
|
||||
from types import SimpleNamespace
|
||||
from pathlib import Path
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
def _load(monkeypatch):
|
||||
db = types.ModuleType("core.database")
|
||||
db.SessionLocal = MagicMock()
|
||||
db.McpServer = MagicMock()
|
||||
monkeypatch.setitem(sys.modules, "core.database", db)
|
||||
loader = importlib.machinery.SourceFileLoader("odysseus_mcp_cli", str(ROOT / "scripts" / "odysseus-mcp"))
|
||||
spec = importlib.util.spec_from_loader(loader.name, loader)
|
||||
m = importlib.util.module_from_spec(spec)
|
||||
loader.exec_module(m)
|
||||
return m
|
||||
from tests.helpers.cli_loader import load_script
|
||||
from tests.helpers.db_stubs import make_core_db_stub
|
||||
|
||||
|
||||
def _srv(env):
|
||||
@@ -33,12 +16,14 @@ def _srv(env):
|
||||
|
||||
|
||||
def test_serialize_handles_list_env(monkeypatch):
|
||||
cli = _load(monkeypatch)
|
||||
make_core_db_stub(monkeypatch, models=["McpServer"])
|
||||
cli = load_script("odysseus-mcp")
|
||||
out = cli._serialize(_srv("[1, 2]")) # JSON array, not object
|
||||
assert out["id"] == "s1"
|
||||
|
||||
|
||||
def test_serialize_redacts_dict_env(monkeypatch):
|
||||
cli = _load(monkeypatch)
|
||||
make_core_db_stub(monkeypatch, models=["McpServer"])
|
||||
cli = load_script("odysseus-mcp")
|
||||
out = cli._serialize(_srv('{"API_KEY": "secret"}'))
|
||||
assert out["env"] == {"API_KEY": "***"}
|
||||
|
||||
Reference in New Issue
Block a user