From 7fd2f574132fcf8aea71ca485ca489c367fedffe Mon Sep 17 00:00:00 2001 From: Yuan Li Date: Sun, 27 Sep 2026 18:15:01 +0800 Subject: [PATCH] fix(cli): include -p in TUI exit summary resume hints (#125078, salvage #125079) hermes_cli/main_tui_launch.py::_print_tui_exit_summary printed `hermes --tui --resume ID` / `hermes --tui -c "TITLE"` without the `-p ` suffix that the classic CLI sibling (cli_session_mixin.py::_print_exit_summary) already appends, so a hint copied from a named profile's TUI resolved against the default profile and failed with "No session found". Trimmed from #125079: no try/except fallback (get_active_profile_name does not raise), tests folded into the existing tests/hermes_cli/test_exit_summary_resume_hint.py. red-on-base: tests/hermes_cli/test_exit_summary_resume_hint.py::TestTuiExitSummaryResumeHint:: test_tui_hints_include_profile_flag_for_named_profile fails on origin/main with `assert 'hermes --tui --resume 20260524_000001_abc123 -p dev' in '...hermes --tui --resume 20260524_000001_abc123\n hermes --tui -c "My TUI Session"...'`; green-on-head: 7 passed. --- hermes_cli/main_tui_launch.py | 8 +++-- .../test_exit_summary_resume_hint.py | 33 +++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/hermes_cli/main_tui_launch.py b/hermes_cli/main_tui_launch.py index bec2eefb6e..9771d39af5 100644 --- a/hermes_cli/main_tui_launch.py +++ b/hermes_cli/main_tui_launch.py @@ -59,9 +59,13 @@ def _print_tui_exit_summary(session_id: Optional[str], active_session_file: Opti if db is not None: db.close() - print(f"\nResume this session with:\n hermes --tui --resume {target}") + # Sessions live under the profile's HERMES_HOME — mirror cli_session_mixin::_print_exit_summary. + from hermes_cli.profiles import get_active_profile_name + active_profile = get_active_profile_name() + profile_flag = "" if active_profile in ("default", "custom") else f" -p {active_profile}" + print(f"\nResume this session with:\n hermes --tui --resume {target}{profile_flag}") if title: - print(f' hermes --tui -c "{title}"') + print(f' hermes --tui -c "{title}"{profile_flag}') print(f"\nSession: {target}") if title: print(f"Title: {title}") diff --git a/tests/hermes_cli/test_exit_summary_resume_hint.py b/tests/hermes_cli/test_exit_summary_resume_hint.py index 997d39bf89..2d945cba53 100644 --- a/tests/hermes_cli/test_exit_summary_resume_hint.py +++ b/tests/hermes_cli/test_exit_summary_resume_hint.py @@ -4,6 +4,9 @@ from datetime import datetime from unittest.mock import MagicMock, patch from cli import HermesCLI +from hermes_cli.main_tui_launch import _print_tui_exit_summary + +import hermes_cli.main # noqa: F401 — _print_tui_exit_summary imports it lazily; load it at collection time def _make_cli(session_id="20260524_000001_abc123"): @@ -81,3 +84,33 @@ class TestExitSummaryResumeHint: # Resume hint still printed without -p. assert "hermes --resume 20260524_000001_abc123" in out assert " -p " not in out + + +def _tui_session_db(*_args, **_kwargs): + db = MagicMock() + db.get_session.return_value = {"message_count": 3} + db.get_session_title.return_value = "My TUI Session" + return db + + +class TestTuiExitSummaryResumeHint: + """``_print_tui_exit_summary`` (hermes_cli/main_tui_launch.py) is a separate entry + point from the classic CLI summary above and must carry the same ``-p`` flag (#125078).""" + + def test_tui_hints_include_profile_flag_for_named_profile(self, capsys): + with patch("hermes_state.SessionDB", _tui_session_db), patch( + "hermes_cli.profiles.get_active_profile_name", return_value="dev" + ): + _print_tui_exit_summary("20260524_000001_abc123") + out = capsys.readouterr().out + assert "hermes --tui --resume 20260524_000001_abc123 -p dev" in out + assert 'hermes --tui -c "My TUI Session" -p dev' in out + + def test_tui_hints_no_profile_flag_on_default(self, capsys): + with patch("hermes_state.SessionDB", _tui_session_db), patch( + "hermes_cli.profiles.get_active_profile_name", return_value="default" + ): + _print_tui_exit_summary("20260524_000001_abc123") + out = capsys.readouterr().out + assert "hermes --tui --resume 20260524_000001_abc123" in out + assert " -p " not in out