Files
hermes-agent/tests/hermes_cli/test_sessions_list_truncation.py
T
teknium1 536a07bec2 fix: sessions list prints a footer when --limit cuts the listing
`hermes sessions list` applied --limit inside the SQL query and rendered
whatever came back, so a user with 35 sessions saw 20 rows and a prompt
and had no way to tell the page was cut. The lister now asks for one row
past the cap, drops that probe row, and ends a truncated page with
"… more not shown (use --limit N to see more)". `--limit 0` is LIMIT 0
(no rows), so the copy never suggests it.

The footer goes through one shared helper, `cli_output.print_truncated`,
and the three "... N more" / "… N more" / "… and N more" variants already
in sessions_cmd.py (export dry-run preview, never-active cleanup, prune/
archive preview) now use it too, so every capped listing in the command
reads the same. Migrating checkpoints / curator / skills search / console
listers is follow-up work.

Co-authored-by: KoNit-K <124019182+KoNit-K@users.noreply.github.com>
2026-09-15 18:25:46 -07:00

40 lines
1.2 KiB
Python

"""``hermes sessions list`` tells the user when ``--limit`` cut the listing (#111989).
The cap is applied inside the SQL query, so the lister probes one row past it; the footer
must appear only when that probe row exists.
"""
from argparse import Namespace
import pytest
from hermes_cli import sessions_cmd
@pytest.fixture
def db(tmp_path):
from hermes_state import SessionDB
db = SessionDB(db_path=tmp_path / "state.db")
for i in range(6):
db.create_session(f"sess_{i}", "cli")
db.append_message(f"sess_{i}", "user", f"hello {i}")
yield db
db.close()
def _list(db, limit, capsys):
sessions_cmd._cmd_list(db, Namespace(limit=limit, source=None, workspace=None))
return capsys.readouterr().out
def test_footer_when_more_sessions_than_limit(db, capsys):
out = _list(db, 4, capsys)
ids = [line.split()[-1] for line in out.splitlines() if line.startswith("hello")]
assert len(ids) == 4 # the probe row is never rendered
assert "… more not shown (use --limit 8 to see more)" in out
def test_no_footer_when_listing_fits(db, capsys):
assert "more" not in _list(db, 6, capsys) # exactly the limit
assert "more" not in _list(db, 20, capsys) # fewer than the limit