fix(cli): submit slash command on Enter when name prefixes another (#293) (#300)

Typing `/model` and pressing Enter did nothing in the TUI; the picker
only opened via `/model --save` or `/model <name>`. The completion popup
matched both `/model` and `/model-fallback` by prefix, so the
exact-match-hide guard (which required a single match) never fired. With
the popup still visible, the TUI's Enter handler completed the text
instead of submitting the command, so it never executed.

Treat the typed prefix as an exact match whenever it equals any matched
command name, not only when it is the sole match. This hides the popup
on a complete command name so Enter submits it, even when a longer
command shares the prefix.
This commit is contained in:
Ziheng Zhang
2026-06-18 21:07:43 +08:00
committed by GitHub
parent 6894d45be8
commit 6593ac9b5b
2 changed files with 24 additions and 2 deletions
+14
View File
@@ -29,6 +29,20 @@ class TestSlashCommandCompleter:
completions = list(completer.get_completions(_doc("/help"), None))
assert completions == []
def test_exact_command_hides_even_when_prefix_of_another(self):
"""Regression for #293: ``/model`` must hide on exact match so Enter
submits it, even though ``/model-fallback`` shares the prefix. Before
the fix the popup stayed visible (two prefix matches) and the TUI's
Enter handler completed the text instead of executing the command.
"""
completer = SlashCommandCompleter()
# Sanity: both commands share the prefix, so a partial prefix lists both.
partial = {c.text for c in completer.get_completions(_doc("/mode"), None)}
assert {"/model", "/model-fallback"} <= partial
# Exact ``/model`` with no trailing space → hide.
completions = list(completer.get_completions(_doc("/model"), None))
assert completions == []
def test_non_slash_returns_empty(self):
completer = SlashCommandCompleter()
completions = list(completer.get_completions(_doc("hello"), None))