Skip to content

Commit afab2db

Browse files
authored
Update test_tui_commands.py
1 parent 37b20a6 commit afab2db

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

‎tests/tui/test_tui_commands.py‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,8 @@ def test_run_sessions_lists_metadata(self):
357357
self.assertIn("my session_250101120000.md", out)
358358
self.assertIn("gpt-4", out)
359359
self.assertIn("/tmp/p", out)
360+
# the console may wrap the line, so allow whitespace/newline
361+
self.assertRegex(out, r"1\s+messages")
360362

361363
def test_run_sessions_skips_unreadable_files(self):
362364
tui, buf = make_tui()
@@ -609,6 +611,42 @@ def test_restore_drops_system_and_tool_blocks(self):
609611
roles = [m.role for m in tui.session.last_messages]
610612
self.assertEqual(roles, ["user", "assistant"])
611613

614+
def test_restore_switches_input_history_to_saved_project(self):
615+
"""/restore of a session saved under another project points the
616+
prompt session's Up/Down recall at that project's history file
617+
(session + default buffer), not the startup project's."""
618+
from python_agent_harness.tui.input import _history_path
619+
620+
tui, buf = make_tui()
621+
startup_project = str(tui._controller.project_dir)
622+
saved_project = "/some/other/project"
623+
with tempfile.TemporaryDirectory() as d:
624+
path = os.path.join(d, "session.md")
625+
with open(path, "w", encoding="utf-8") as f:
626+
f.write(
627+
"**user**: hi\n\n;; Local Variables:\n"
628+
f";; python-agent-harness--project-dir: {saved_project!r}\n"
629+
";; End:\n"
630+
)
631+
tui._run_restore(path)
632+
expected = _history_path(saved_project)
633+
self.assertEqual(tui.prompt_session.history.filename, expected)
634+
self.assertEqual(tui.prompt_session.default_buffer.history.filename, expected)
635+
self.assertNotEqual(expected, _history_path(startup_project))
636+
637+
def test_restore_without_project_metadata_keeps_input_history(self):
638+
"""A session file without project metadata (old format) leaves
639+
the prompt session's input history untouched."""
640+
tui, buf = make_tui()
641+
before = tui.prompt_session.history.filename
642+
with tempfile.TemporaryDirectory() as d:
643+
path = os.path.join(d, "session.md")
644+
with open(path, "w", encoding="utf-8") as f:
645+
f.write("**user**: hi\n\n;; Local Variables:\n;; End:\n")
646+
tui._run_restore(path)
647+
self.assertEqual(tui.prompt_session.history.filename, before)
648+
self.assertEqual(tui.prompt_session.default_buffer.history.filename, before)
649+
612650
def test_find_session_by_title(self):
613651
"""Title lookup: exact basename, .md-less, substring and
614652
derived-title matches; unmatched queries return None."""

0 commit comments

Comments
 (0)