core/cli: fix /help command usage line and help Tab completion

Use a standalone Click context so /help compact shows Usage: /compact,
not nested under help. Complete /help <cmd> from the slash registry.
This commit is contained in:
2026-07-15 13:09:24 +08:00
parent 972bcd78ee
commit 5e016c012b
4 changed files with 50 additions and 13 deletions
+26
View File
@@ -116,3 +116,29 @@ def test_completer_provider_args(tmp_path: object, monkeypatch: object) -> None:
first = completer("r", 0)
assert first == "remote"
def test_completer_help_commands(tmp_path: object, monkeypatch: object) -> None:
import readline
from pathlib import Path
import pytest
assert isinstance(tmp_path, Path)
assert isinstance(monkeypatch, pytest.MonkeyPatch)
state = _minimal_state(tmp_path)
completer = build_completer(state)
monkeypatch.setattr(readline, "get_line_buffer", lambda: "/help ")
monkeypatch.setattr(readline, "get_begidx", lambda: len("/help "))
found: list[str] = []
index = 0
while True:
item = completer("c", index)
if item is None:
break
found.append(item)
index += 1
assert "compact" in found
assert "clear" in found
+8
View File
@@ -96,6 +96,14 @@ async def test_help_and_clear(state: ReplState) -> None:
assert state.agent.messages == []
async def test_help_command_usage_line(state: ReplState, capsys: pytest.CaptureFixture[str]) -> None:
assert await handle_slash(state, "/help compact") is True
out = capsys.readouterr().out
assert "Usage: /compact" in out
assert "help [COMMAND] compact" not in out
assert "Soft-compact" in out
async def test_quit(state: ReplState) -> None:
assert await handle_slash(state, "/quit") is False