Unify public UX around pyro CLI and Pyro facade
This commit is contained in:
parent
d16aadd03f
commit
23a2dfb330
19 changed files with 936 additions and 407 deletions
|
|
@ -11,56 +11,55 @@ import pyro_mcp.demo as demo_module
|
|||
def test_run_demo_happy_path(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
calls: list[tuple[str, dict[str, Any]]] = []
|
||||
|
||||
class StubManager:
|
||||
class StubPyro:
|
||||
def __init__(self) -> None:
|
||||
pass
|
||||
|
||||
def create_vm(
|
||||
def run_in_vm(
|
||||
self,
|
||||
*,
|
||||
profile: str,
|
||||
command: str,
|
||||
vcpu_count: int,
|
||||
mem_mib: int,
|
||||
timeout_seconds: int,
|
||||
ttl_seconds: int,
|
||||
) -> dict[str, str]:
|
||||
network: bool,
|
||||
) -> dict[str, Any]:
|
||||
calls.append(
|
||||
(
|
||||
"create_vm",
|
||||
"run_in_vm",
|
||||
{
|
||||
"profile": profile,
|
||||
"command": command,
|
||||
"vcpu_count": vcpu_count,
|
||||
"mem_mib": mem_mib,
|
||||
"timeout_seconds": timeout_seconds,
|
||||
"ttl_seconds": ttl_seconds,
|
||||
"network": network,
|
||||
},
|
||||
)
|
||||
)
|
||||
return {"vm_id": "vm-1"}
|
||||
return {"vm_id": "vm-1", "stdout": "git version 2.x", "exit_code": 0}
|
||||
|
||||
def start_vm(self, vm_id: str) -> dict[str, str]:
|
||||
calls.append(("start_vm", {"vm_id": vm_id}))
|
||||
return {"vm_id": vm_id}
|
||||
|
||||
def status_vm(self, vm_id: str) -> dict[str, Any]:
|
||||
calls.append(("status_vm", {"vm_id": vm_id}))
|
||||
return {"vm_id": vm_id, "network_enabled": False, "execution_mode": "host_compat"}
|
||||
|
||||
def exec_vm(self, vm_id: str, *, command: str, timeout_seconds: int) -> dict[str, Any]:
|
||||
calls.append(
|
||||
(
|
||||
"exec_vm",
|
||||
{"vm_id": vm_id, "command": command, "timeout_seconds": timeout_seconds},
|
||||
)
|
||||
)
|
||||
return {"vm_id": vm_id, "stdout": "git version 2.x", "exit_code": 0}
|
||||
|
||||
monkeypatch.setattr(demo_module, "VmManager", StubManager)
|
||||
monkeypatch.setattr(demo_module, "Pyro", StubPyro)
|
||||
result = demo_module.run_demo()
|
||||
|
||||
assert result["exit_code"] == 0
|
||||
assert calls[0][0] == "create_vm"
|
||||
assert calls[1] == ("start_vm", {"vm_id": "vm-1"})
|
||||
assert calls[2] == ("status_vm", {"vm_id": "vm-1"})
|
||||
assert calls[3][0] == "exec_vm"
|
||||
assert calls == [
|
||||
(
|
||||
"run_in_vm",
|
||||
{
|
||||
"profile": "debian-git",
|
||||
"command": "git --version",
|
||||
"vcpu_count": 1,
|
||||
"mem_mib": 512,
|
||||
"timeout_seconds": 30,
|
||||
"ttl_seconds": 600,
|
||||
"network": False,
|
||||
},
|
||||
)
|
||||
]
|
||||
|
||||
|
||||
def test_demo_command_prefers_network_probe_for_guest_vsock() -> None:
|
||||
|
|
@ -79,3 +78,20 @@ def test_main_prints_json(
|
|||
demo_module.main()
|
||||
rendered = json.loads(capsys.readouterr().out)
|
||||
assert rendered["exit_code"] == 0
|
||||
|
||||
|
||||
def test_run_demo_network_uses_probe(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
captured: dict[str, Any] = {}
|
||||
|
||||
class StubPyro:
|
||||
def __init__(self) -> None:
|
||||
pass
|
||||
|
||||
def run_in_vm(self, **kwargs: Any) -> dict[str, Any]:
|
||||
captured.update(kwargs)
|
||||
return {"exit_code": 0}
|
||||
|
||||
monkeypatch.setattr(demo_module, "Pyro", StubPyro)
|
||||
demo_module.run_demo(network=True)
|
||||
assert "https://example.com" in str(captured["command"])
|
||||
assert captured["network"] is True
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue