fix(cli): make Desktop target selection keyboard navigable [skip ci]

Reuse the existing questionary selector so users can highlight a target with arrow keys and confirm with Enter. Retain numeric shortcuts and the current Python executable label without changing discovery or attachment behavior.

Keep cancellation fail-closed with exit code 130. Exercise real navigation, EOF and Ctrl+C through both CLI launchers so cancelling cannot start a Python backend or attach to Desktop. Document the controls.
This commit is contained in:
Xubin Ren committed 2026-09-08 10:04:15 +08:00
1 parent 9a594f74ff
commit cf74d1c7e5
4 files changed
+116 -14

No files matched your search

@@ -1,6 +1,9 @@
"""The picker covers retained launchers without intercepting explicit commands."""
import pytest
from prompt_toolkit.application import create_app_session
from prompt_toolkit.input import create_pipe_input
from prompt_toolkit.output import DummyOutput
from typer.testing import CliRunner
from nanobot.cli import commands, desktop_target, entry
@@ -26,6 +29,34 @@ def test_retained_launcher_attaches_without_starting_python(monkeypatch, args):
assert seen == [args]
@pytest.mark.parametrize("args", [[], ["webui"]])
@pytest.mark.parametrize("launcher", ["modern", "retained"])
def test_launcher_picker_ctrl_c_does_not_start_python(monkeypatch, args, launcher):
class Target:
def request(self, operation):
assert operation == "status", "cancelled picker must not request attachment"
return desktop_target.DesktopReply("ready", frozenset({"webui", "tui"}))
monkeypatch.setattr(desktop_target, "_interactive_shell", lambda: True)
monkeypatch.setattr(desktop_target, "discover_desktop_target", Target)
monkeypatch.setattr(entry, "_run_agent", lambda *_a, **_kw: pytest.fail("agent started"))
monkeypatch.setattr(
"nanobot.cli.webui._resolve_webui_config_path",
lambda *_a, **_kw: pytest.fail("Python WebUI started"),
)
monkeypatch.setattr(entry.sys, "argv", ["nanobot", *args])
with create_pipe_input() as pipe_input:
with create_app_session(input=pipe_input, output=DummyOutput()):
pipe_input.send_text("\x03")
if launcher == "retained":
result = CliRunner().invoke(commands.app, args)
assert result.exit_code == 130, result.output
else:
with pytest.raises(SystemExit) as exc:
entry.main()
assert exc.value.code == 130
@pytest.mark.parametrize("args", [["agent", "--help"], ["--help"], ["--version"],
["webui", "--no-open"], ["webui", "--port", "8765"]])
def test_retained_launcher_explicit_commands_never_discover(monkeypatch, args):