mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-09-04 02:01:48 +03:00
feat(cli): make nanobot launch the terminal agent
This commit is contained in:
+47
-1
@@ -1,4 +1,50 @@
|
||||
from nanobot.cli.entry import _native_tui_candidate
|
||||
from nanobot.cli import entry
|
||||
from nanobot.cli.entry import _agent_invocation_args, _native_tui_candidate
|
||||
|
||||
|
||||
def test_root_command_routes_to_agent_without_copying_agent_options() -> None:
|
||||
assert _agent_invocation_args([]) == []
|
||||
assert _agent_invocation_args(["agent", "--theme", "dark"]) == ["--theme", "dark"]
|
||||
assert _agent_invocation_args(["--workspace", "./project"]) == [
|
||||
"--workspace",
|
||||
"./project",
|
||||
]
|
||||
assert _agent_invocation_args(["-mhello"]) == ["-mhello"]
|
||||
|
||||
|
||||
def test_root_metadata_and_subcommands_keep_the_root_cli() -> None:
|
||||
for args in (
|
||||
["--help"],
|
||||
["--version"],
|
||||
["--install-completion"],
|
||||
["gateway"],
|
||||
["webui"],
|
||||
):
|
||||
assert _agent_invocation_args(args) is None
|
||||
|
||||
|
||||
def test_root_alias_dispatches_the_shared_agent_command(monkeypatch) -> None:
|
||||
calls: dict[str, object] = {}
|
||||
monkeypatch.setattr(entry.sys, "argv", ["nanobot", "-m", "hello"])
|
||||
monkeypatch.setattr(
|
||||
entry,
|
||||
"set_cli_process_identity",
|
||||
lambda args: calls.__setitem__("identity", args),
|
||||
)
|
||||
monkeypatch.setattr(entry, "_configure_windows_console", lambda: None)
|
||||
monkeypatch.setattr(
|
||||
entry,
|
||||
"_run_agent",
|
||||
lambda args, *, prog_name: calls.update(args=args, prog_name=prog_name),
|
||||
)
|
||||
|
||||
entry.main()
|
||||
|
||||
assert calls == {
|
||||
"identity": ["agent", "-m", "hello"],
|
||||
"args": ["-m", "hello"],
|
||||
"prog_name": "nanobot",
|
||||
}
|
||||
|
||||
|
||||
def test_native_agent_invocations_use_the_lightweight_entrypoint() -> None:
|
||||
|
||||
@@ -58,6 +58,24 @@ def test_legacy_console_entrypoint_still_sets_subcommand_identity(
|
||||
assert commands == [["webui"]]
|
||||
|
||||
|
||||
def test_legacy_console_entrypoint_routes_bare_command_to_agent(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
identities: list[list[str]] = []
|
||||
launches: list[tuple[list[str], str]] = []
|
||||
monkeypatch.setattr("nanobot.cli.commands.set_cli_process_identity", identities.append)
|
||||
monkeypatch.setattr(
|
||||
"nanobot.cli.entry._run_agent",
|
||||
lambda args, *, prog_name: launches.append((args, prog_name)),
|
||||
)
|
||||
|
||||
result = CliRunner().invoke(app, [])
|
||||
|
||||
assert result.exit_code == 0
|
||||
assert identities == [["agent"]]
|
||||
assert launches == [([], "nanobot")]
|
||||
|
||||
|
||||
def test_named_executable_creates_stable_role_symlink(
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
|
||||
Reference in New Issue
Block a user