75 lines
2.0 KiB
Python
75 lines
2.0 KiB
Python
from __future__ import annotations
|
|
|
|
import json
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from pyMCPBroker.config import load_config
|
|
|
|
|
|
def test_env_substitution(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
|
monkeypatch.setenv("BROKER_CMD", "python fake.py")
|
|
path = tmp_path / "config.json"
|
|
path.write_text(
|
|
json.dumps(
|
|
{
|
|
"tree": [
|
|
{
|
|
"path": "/repo",
|
|
"type": "node",
|
|
"source": {"backend": "stdio", "command": "${BROKER_CMD}"},
|
|
}
|
|
]
|
|
}
|
|
),
|
|
encoding="utf-8",
|
|
)
|
|
cfg = load_config(path)
|
|
assert cfg.tree[0].source is not None
|
|
assert cfg.tree[0].source.command == "python fake.py"
|
|
|
|
|
|
def test_env_missing_raises(tmp_path: Path) -> None:
|
|
path = tmp_path / "config.json"
|
|
path.write_text(
|
|
json.dumps(
|
|
{
|
|
"tree": [
|
|
{
|
|
"path": "/repo",
|
|
"type": "node",
|
|
"source": {"backend": "stdio", "command": "${MISSING_VAR}"},
|
|
}
|
|
]
|
|
}
|
|
),
|
|
encoding="utf-8",
|
|
)
|
|
with pytest.raises(ValueError):
|
|
load_config(path)
|
|
|
|
|
|
def test_invalid_path_alias_raises(tmp_path: Path) -> None:
|
|
path = tmp_path / "config.json"
|
|
path.write_text(
|
|
json.dumps(
|
|
{
|
|
"tree": [
|
|
{
|
|
"path": "/repo",
|
|
"type": "node",
|
|
"source": {
|
|
"backend": "stdio",
|
|
"command": "echo test",
|
|
"path_aliases": {"get_file_contents": "bad/name"},
|
|
},
|
|
}
|
|
]
|
|
}
|
|
),
|
|
encoding="utf-8",
|
|
)
|
|
with pytest.raises(Exception):
|
|
load_config(path)
|