Merge pull request 'feat: named server sets — save/apply the Active/Disabled split (#52)' (#56) from feat/52-server-sets into main
CI / Lint (ruff) (push) Successful in 7s
CI / Tests (py3.10 / ubuntu-latest) (push) Successful in 10s
CI / Tests (py3.12 / windows-latest) (push) Successful in 20s
CI / Tests (py3.13 / ubuntu-latest) (push) Successful in 9s
CI / Tests (py3.12 / ubuntu-latest) (push) Successful in 9s
CI / Lint (ruff) (push) Successful in 7s
CI / Tests (py3.10 / ubuntu-latest) (push) Successful in 10s
CI / Tests (py3.12 / windows-latest) (push) Successful in 20s
CI / Tests (py3.13 / ubuntu-latest) (push) Successful in 9s
CI / Tests (py3.12 / ubuntu-latest) (push) Successful in 9s
This commit was merged in pull request #56.
This commit is contained in:
@@ -906,6 +906,68 @@ def test_args_secret_warning_empty():
|
||||
assert c.args_secret_warning({"args": []}) is None
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------- #
|
||||
# Named server sets (issue #52)
|
||||
# --------------------------------------------------------------------------- #
|
||||
def _three_servers():
|
||||
return [
|
||||
c.ServerEntry("alpha", {"command": "npx"}, True),
|
||||
c.ServerEntry("beta", {"command": "uvx"}, True),
|
||||
c.ServerEntry("gamma", {"url": "https://x.example/mcp"}, False),
|
||||
]
|
||||
|
||||
|
||||
def test_save_and_list_server_sets_roundtrip():
|
||||
cfg: dict = {}
|
||||
members = c.save_server_set(cfg, "webdev", _three_servers())
|
||||
assert members == ["alpha", "beta"] # only the enabled ones
|
||||
assert c.list_server_sets(cfg) == {"webdev": ["alpha", "beta"]}
|
||||
|
||||
|
||||
def test_apply_server_set_enables_exactly_the_members():
|
||||
servers = _three_servers()
|
||||
missing = c.apply_server_set(servers, ["gamma"])
|
||||
assert missing == []
|
||||
assert [s.enabled for s in servers] == [False, False, True]
|
||||
|
||||
|
||||
def test_apply_server_set_reports_missing_members():
|
||||
servers = _three_servers()
|
||||
missing = c.apply_server_set(servers, ["alpha", "vanished", "gone"])
|
||||
assert missing == ["gone", "vanished"]
|
||||
assert [s.enabled for s in servers] == [True, False, False] # rest still applied
|
||||
|
||||
|
||||
def test_delete_server_set_drops_empty_key():
|
||||
cfg: dict = {}
|
||||
c.save_server_set(cfg, "only", _three_servers())
|
||||
assert c.delete_server_set(cfg, "only") is True
|
||||
assert c.SETS_KEY not in cfg # no empty bcc key left behind
|
||||
assert c.delete_server_set(cfg, "only") is False
|
||||
|
||||
|
||||
def test_server_sets_survive_write_and_reload(tmp_path):
|
||||
cfgpath = tmp_path / "cfg.json"
|
||||
cfg = {"mcpServers": {"alpha": {"command": "npx"}}}
|
||||
c.save_server_set(cfg, "webdev", [c.ServerEntry("alpha", {"command": "npx"}, True)])
|
||||
c.write_config(cfgpath, cfg)
|
||||
reloaded = c.load_config(cfgpath)
|
||||
assert c.list_server_sets(reloaded) == {"webdev": ["alpha"]}
|
||||
|
||||
|
||||
def test_apply_servers_preserves_sets_key():
|
||||
cfg: dict = {"mcpServers": {}}
|
||||
c.save_server_set(cfg, "s", [c.ServerEntry("alpha", {"command": "npx"}, True)])
|
||||
c.apply_servers(cfg, _three_servers())
|
||||
assert c.SETS_KEY in cfg # the server writer never touches sets
|
||||
|
||||
|
||||
def test_list_server_sets_skips_malformed_entries():
|
||||
cfg = {c.SETS_KEY: {"good": ["a"], "bad-not-list": "a", "bad-items": ["a", 3]}}
|
||||
assert c.list_server_sets(cfg) == {"good": ["a"]}
|
||||
assert c.list_server_sets({c.SETS_KEY: "junk"}) == {}
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------- #
|
||||
# resolve_name_collision (paste/import duplicate-name handling — issue #8)
|
||||
# --------------------------------------------------------------------------- #
|
||||
|
||||
Reference in New Issue
Block a user