diff --git a/cli.py b/cli.py index 93a6680fcc..ee210f7905 100644 --- a/cli.py +++ b/cli.py @@ -11638,8 +11638,12 @@ class HermesCLI(CLIAgentSetupMixin, CLICommandsMixin, CLIBillingMixin): from hermes_state import SessionDB new_title = SessionDB.sanitize_title(raw_title) except ValueError as e: + # sanitize_title rejected the input (e.g. too long). + # Print that one reason and stop — don't fall + # through to the "empty after cleanup" branch and + # print a second, contradictory error (SC-05). _cprint(f" {e}") - new_title = None + return True if not new_title: _cprint(" Title is empty after cleanup. Please use printable characters.") elif self._session_db.get_session(self.session_id): @@ -11729,9 +11733,14 @@ class HermesCLI(CLIAgentSetupMixin, CLICommandsMixin, CLIBillingMixin): _undo_n = int(_undo_parts[1]) except ValueError: print(f"(._.) Invalid count {_undo_parts[1]!r} — use /undo or /undo N.") - return + return True # bad arg — command handled, keep the REPL alive if _undo_n < 1: _undo_n = 1 + # Nothing to undo → say so immediately; don't pop a destructive + # confirmation dialog for a guaranteed no-op (SC-06). + if not self.conversation_history: + print("(._.) No messages to undo.") + return True _undo_desc = ( "This removes the last user/assistant exchange from history." if _undo_n == 1 diff --git a/hermes_cli/cli_commands_mixin.py b/hermes_cli/cli_commands_mixin.py index f3dcd7399f..93b221fc59 100644 --- a/hermes_cli/cli_commands_mixin.py +++ b/hermes_cli/cli_commands_mixin.py @@ -1048,7 +1048,7 @@ class CLICommandsMixin: session_meta = self._session_db.get_session(target_id) if not session_meta: _cprint(f" Session not found: {target}") - _cprint(" Use /history or `hermes sessions list` to see available sessions.") + _cprint(" Use /sessions or `hermes sessions list` to see available sessions.") return # If the target is the empty head of a compression chain, redirect to diff --git a/hermes_cli/commands.py b/hermes_cli/commands.py index ee8eda30a4..56624a1691 100644 --- a/hermes_cli/commands.py +++ b/hermes_cli/commands.py @@ -263,7 +263,7 @@ COMMAND_REGISTRY: list[CommandDef] = [ CommandDef("diff", "Show git changes in the working directory", "Info", args_hint="[staged|all|session] [--stat] [path...]", subcommands=("staged", "all", "session")), - CommandDef("verbose", "Cycle tool progress display: off -> new -> all -> verbose -> log", + CommandDef("verbose", "Cycle tool progress display: off -> new -> all -> verbose", "Configuration", cli_only=True, gateway_config_gate="display.tool_progress_command", busy_policy="dispatch"), diff --git a/tests/cli/test_slash_undo_title_robustness.py b/tests/cli/test_slash_undo_title_robustness.py new file mode 100644 index 0000000000..1a7d218153 --- /dev/null +++ b/tests/cli/test_slash_undo_title_robustness.py @@ -0,0 +1,55 @@ +"""Regression tests for slash-command dispatch robustness (round-3 QA). + +Covers: +- SC-01: `/undo ` must NOT quit the CLI (process_command returns + True to keep the REPL alive), and must not raise. +- SC-06: `/undo` on an empty session reports "nothing to undo" without popping + a destructive-confirmation dialog. +- SC-05: `/title ` prints exactly one error, not the contradictory + "too long" + "empty after cleanup" pair. +""" + +from unittest.mock import patch + +from tests.cli.test_cli_init import _make_cli + + +def test_undo_non_numeric_count_keeps_repl_alive(): + """`/undo abc` returned a bare None → REPL treated it as exit (SC-01).""" + cli = _make_cli() + cli.conversation_history = [ + {"role": "user", "content": "hi"}, + {"role": "assistant", "content": "hello"}, + ] + # Must not raise, and must return True (truthy → REPL continues). + result = cli.process_command("/undo abc") + assert result is True + + +def test_undo_empty_session_no_confirmation_dialog(): + """`/undo` with no history must short-circuit before the destructive prompt (SC-06).""" + cli = _make_cli() + cli.conversation_history = [] + + called = {"confirm": False} + + def _spy_confirm(*a, **k): + called["confirm"] = True + return "approved" + + with patch.object(cli, "_confirm_destructive_slash", _spy_confirm): + result = cli.process_command("/undo") + + assert result is True + assert called["confirm"] is False # no confirmation for a guaranteed no-op + + +def test_title_too_long_prints_single_error(capsys): + """`/title <500 chars>` must print one error, not two contradictory ones (SC-05).""" + cli = _make_cli() + result = cli.process_command("/title " + "A" * 500) + out = capsys.readouterr().out + assert result is True + # The length error should fire; the contradictory "empty after cleanup" + # message must NOT also appear. + assert "empty after cleanup" not in out.lower()