mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-08-31 00:03:01 +03:00
test(cli): isolate WebUI interrupt polling
This commit is contained in:
@@ -443,6 +443,7 @@ def _attach_to_background_gateway(
|
|||||||
runtime: "GatewayRuntime",
|
runtime: "GatewayRuntime",
|
||||||
*,
|
*,
|
||||||
poll_hook: Callable[[], None] | None = None,
|
poll_hook: Callable[[], None] | None = None,
|
||||||
|
sleep: Callable[[float], None] = time.sleep,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Keep a WebUI launcher attached without taking ownership of the gateway."""
|
"""Keep a WebUI launcher attached without taking ownership of the gateway."""
|
||||||
_print_webui_foreground_lifecycle(attached=True)
|
_print_webui_foreground_lifecycle(attached=True)
|
||||||
@@ -450,7 +451,7 @@ def _attach_to_background_gateway(
|
|||||||
while runtime.status().running:
|
while runtime.status().running:
|
||||||
if poll_hook is not None:
|
if poll_hook is not None:
|
||||||
poll_hook()
|
poll_hook()
|
||||||
time.sleep(0.5)
|
sleep(0.5)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
console.print("\n[yellow]WebUI launcher detached.[/yellow]")
|
console.print("\n[yellow]WebUI launcher detached.[/yellow]")
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -2565,7 +2565,7 @@ def test_webui_foreground_attaches_to_existing_managed_gateway(monkeypatch, tmp_
|
|||||||
assert seen["open_kwargs"] == {"wait": False}
|
assert seen["open_kwargs"] == {"wait": False}
|
||||||
|
|
||||||
|
|
||||||
def test_attach_to_background_gateway_detaches_on_ctrl_c(monkeypatch, capsys) -> None:
|
def test_attach_to_background_gateway_detaches_on_ctrl_c(capsys) -> None:
|
||||||
stopped = False
|
stopped = False
|
||||||
|
|
||||||
class _FakeRuntime:
|
class _FakeRuntime:
|
||||||
@@ -2580,9 +2580,7 @@ def test_attach_to_background_gateway_detaches_on_ctrl_c(monkeypatch, capsys) ->
|
|||||||
def _interrupt(_seconds: float) -> None:
|
def _interrupt(_seconds: float) -> None:
|
||||||
raise KeyboardInterrupt
|
raise KeyboardInterrupt
|
||||||
|
|
||||||
monkeypatch.setattr("nanobot.cli.webui_support.time.sleep", _interrupt)
|
cli_webui_support._attach_to_background_gateway(_FakeRuntime(), sleep=_interrupt)
|
||||||
|
|
||||||
cli_webui_support._attach_to_background_gateway(_FakeRuntime())
|
|
||||||
|
|
||||||
assert stopped is False
|
assert stopped is False
|
||||||
output = capsys.readouterr().out
|
output = capsys.readouterr().out
|
||||||
|
|||||||
Reference in New Issue
Block a user