fix(remote): send a service option under its served name

This commit is contained in:
imSp4rky
2026-11-24 16:47:45 -07:00
parent 8d5234130a
commit 5ab60b8879
4 changed files with 43 additions and 3 deletions
@@ -1,4 +1,4 @@
"""make_remote_command resolves names against the remote server's list and reports the failures."""
"""make_remote_command resolves names against the remote server's list, reports the failures and keeps served option names."""
from __future__ import annotations
@@ -10,7 +10,17 @@ import pytest
from unshackle.core.services import Services
SERVED = [
{"tag": "EXAMPLE", "url": "https://example.com", "help": "Example service.", "cli_params": [], "aliases": []},
{
"tag": "EXAMPLE",
"url": "https://example.com",
"help": "Example service.",
"cli_params": [
{"kind": "option", "name": "zone_code", "opts": ["--zone"], "is_flag": False, "default": None},
{"kind": "option", "name": "flavour_name", "opts": ["--flavour"], "is_flag": False, "choices": ["a", "b"]},
{"kind": "option", "name": "loud_mode", "opts": ["--loud"], "is_flag": True, "default": False},
],
"aliases": [],
},
{
"tag": "DEMO",
"url": "https://example.com",
@@ -55,3 +65,10 @@ def test_fetch_failure_keeps_stub_instead_of_raising() -> None:
cmd = _make("EXAMPLE")
assert cmd.name == "EXAMPLE"
assert cmd.help is None
def test_options_keep_the_served_name() -> None:
with patch.object(Services, "fetch_remote_services", return_value=SERVED):
cmd = _make("EXAMPLE")
ctx = cmd.make_context("EXAMPLE", ["--zone", "eu", "--flavour", "b", "--loud", "an-id"])
assert ctx.params == {"title": "an-id", "zone_code": "eu", "flavour_name": "b", "loud_mode": True}
+18
View File
@@ -146,6 +146,24 @@ def test_service_params_are_the_only_service_options_when_present() -> None:
build({"service_params": {"count": "x"}})
def test_service_params_keyed_by_flag_reach_an_option_with_another_name() -> None:
import click
from unshackle.core.api.handlers import SESSION_TRANSPORT_KEYS, instantiate_service
@click.command()
@click.argument("title")
@click.option("--zone", "zone_code", default=None)
@click.option("--lang", "svc_lang", default=None)
def cli(title: str, **kwargs: object) -> dict:
return kwargs
module = type("Svc", (), {"cli": cli})
data = {"service_params": {"zone": "eu", "svc_lang": "de", "lang": "fr"}}
built = instantiate_service(click.Context(click.Command("dl")), module, "t", data, SESSION_TRANSPORT_KEYS)
assert built == {"zone_code": "eu", "svc_lang": "de"}
def test_drain_server_logs_survives_client_systemexit() -> None:
"""RemoteClient raises SystemExit on transport errors; the drain must swallow it."""
from unshackle.core.remote_service import RemoteService