Skip to content

The agent that grows with you

test(cli): the classic commands PTY test asserts main's output

Teknium0ae6cf4e3e5b
diff --git a/tests/hermes_cli/test_gateway_chat_commands_live.py b/tests/hermes_cli/test_gateway_chat_commands_live.py
index 5467c26e87b..e1d494cbf02 100644
--- a/tests/hermes_cli/test_gateway_chat_commands_live.py
+++ b/tests/hermes_cli/test_gateway_chat_commands_live.py
@@ -1,4 +1,11 @@
-"""Classic `hermes --cli chat` session commands on the shared gateway, driven in a real PTY."""
+"""Classic `hermes --cli chat` session commands on the shared gateway, driven in a real PTY.
+
+The classic CLI is main's HermesCLI again (gateway-backed agent and session store), so each
+expectation is main's own output for the same keystrokes (lanes/pushready/probe_cmds.py, main =
+git archive 3b63f7b0a4c). Keys go in as the A/B harness types them: the text, then Enter apart
+(main's prompt_toolkit drops an Enter that arrives in the same burst as the text).
+"""
+import contextlib
import json
from http.server import ThreadingHTTPServer
import os
@@ -14,12 +21,13 @@ import uuid
import pytest
+from hermes_cli.observability.shared_metrics_consent import OFFER_VERSION
from tests.gateway.fixtures.local_recovery_probe import Model
from tests.gateway.test_normal_runtime_boot import control
-def test_classic_view_title_undo_retry_new_usage_tools_and_reads(tmp_path):
+def classic_session(tmp_path):
root = Path(__file__).resolve().parents[2]
home, user, cwd = tmp_path / "state", tmp_path / "user", tmp_path / "caller"
home.mkdir(mode=0o700)
@@ -33,7 +41,10 @@ def test_classic_view_title_undo_retry_new_usage_tools_and_reads(tmp_path):
(home / "config.yaml").write_text(json.dumps({
"gateway": {"multiplex_profiles": False},
"model": {"provider": "custom", "default": "view-model", "base_url": url},
- "auxiliary": {"title_generation": {"enabled": False}}}))
+ "auxiliary": {"title_generation": {"enabled": False}},
+ # Answered at the current offer version, as tests/fakes/fake_llm_provider.write_hermes_home
+ # does: main's interactive chat asks it first on a home that never answered.
+ "telemetry": {"shared_metrics": {"enabled": False, "send": False, "offer_version": OFFER_VERSION}}}))
env = {k: os.environ[k] for k in ("PATH", "LANG", "TZ") if k in os.environ}
env.update(HOME=str(user), USERPROFILE=str(user), HERMES_HOME=str(home), PYTHONPATH=str(root),
PYTHONUNBUFFERED="1", OPENAI_API_KEY="loopback-only", OPENAI_BASE_URL=url)
@@ -49,7 +60,13 @@ def test_classic_view_title_undo_retry_new_usage_tools_and_reads(tmp_path):
def send(line, expect, timeout=45):
# The pane is fixed-height (blank rows pad it), so a new answer is one more occurrence.
seen = screen().count(expect)
- tmux("send-keys", "-t", "chat", "-l", line)
+ if line:
+ tmux("send-keys", "-t", "chat", "-l", line)
+ echo = time.monotonic() + 10
+ while line not in screen():
+ assert time.monotonic() < echo, (line, screen())
+ time.sleep(.1)
+ time.sleep(1) # health: allow HX013 -- main drops an Enter sent in the same burst as the text (probe_pty.py); the gap is the input timing
tmux("send-keys", "-t", "chat", "Enter")
deadline = time.monotonic() + timeout
while time.monotonic() < deadline:
@@ -63,6 +80,11 @@ def test_classic_view_title_undo_retry_new_usage_tools_and_reads(tmp_path):
with sqlite3.connect(f"file:{home / 'state.db'}?mode=ro", uri=True) as conn:
return conn.execute(sql, args).fetchall()
+ def session_id():
+ """Main's bare `/title` prints the full id (the banner shows main's 8-character label)."""
+ shown = send("/title", "Session ID: ")
+ return [line.split("Session ID: ", 1)[1].strip() for line in shown.splitlines() if "Session ID: " in line][-1]
+
with (home / "gw.log").open("w") as log:
daemon = subprocess.Popen([sys.executable, "-m", "gateway.run"], cwd=root, env=env,
stdin=subprocess.DEVNULL, stdout=log, stderr=subprocess.STDOUT)
@@ -77,32 +99,12 @@ def test_classic_view_title_undo_retry_new_usage_tools_and_reads(tmp_path):
command = shlex.join([sys.executable, "-m", "hermes_cli.main", "--cli", "chat"])
tmux("new-session", "-d", "-s", "chat", "-x", "200", "-y", "50", "-c", str(cwd),
command + '; printf "\\nCLI_RC=%s\\n" "$?"; sleep 120')
- send("", "Welcome to Hermes", 60)
- sid = next(line.split("Session: ", 1)[1].strip() for line in screen().splitlines() if "Session: " in line)
- send("first question", "RECOVERY_ACK_first question")
- send("second question", "RECOVERY_ACK_second question")
- send("/title View Title", "Session title set: View Title")
- assert db("SELECT title FROM sessions WHERE id=?", sid) == [("View Title",)]
- send("/title", "**View Title**")
- send("/usage", "Last turn:")
- send("/tools", "not available on the shared gateway yet")
- send("/retry", "RECOVERY_ACK_second question")
- active = [r[0] for r in db("SELECT content FROM messages WHERE session_id=? AND active=1 AND role='user'", sid)]
- assert active == ["first question", "second question"], active
- send("/undo", "Undid 1 turn")
- # The removed message is back in the composer: Enter alone resubmits it.
- send("", "RECOVERY_ACK_second question")
- send("/memory", "No pending memory writes")
- send("/insights", "**Sessions:** 1")
- send("/fast", "/fast is not available on the shared gateway yet")
- send("/new Second Thread", "Session title set: Second Thread")
- second = [line.split("Session: ", 1)[1].strip() for line in screen().splitlines() if "Session: " in line][-1]
- assert second != sid
- assert db("SELECT title FROM sessions WHERE id=?", second) == [("Second Thread",)]
- send("third question", "RECOVERY_ACK_third question")
- assert db("SELECT COUNT(*) FROM messages WHERE session_id=? AND role='user'", second) == [(1,)]
+ deadline = time.monotonic() + 60
+ while "Welcome to Hermes Agent" not in screen():
+ assert time.monotonic() < deadline, (screen(), (home / "gw.log").read_text())
+ time.sleep(.1)
+ yield send, screen, db, session_id
send("/quit", "CLI_RC=0")
- assert "Unsupported gateway CLI command" not in screen()
finally:
tmux("kill-server")
if daemon.poll() is None:
@@ -114,3 +116,40 @@ def test_classic_view_title_undo_retry_new_usage_tools_and_reads(tmp_path):
daemon.wait(timeout=5)
peer.shutdown()
peer.server_close()
+
+
+def test_classic_view_title_and_usage_match_main(tmp_path):
+ with classic_session(tmp_path) as (send, screen, db, session_id):
+ send("first question", "RECOVERY_ACK_first question")
+ send("second question", "RECOVERY_ACK_second question")
+ send("/title View Title", "Session title set: View Title")
+ sid = session_id()
+ assert "Title: View Title" in screen()
+ assert db("SELECT title FROM sessions WHERE id=?", sid) == [("View Title",)]
+ send("/usage", "Session Token Usage")
+ active = [r[0] for r in db("SELECT content FROM messages WHERE session_id=? AND active=1 AND role='user'", sid)]
+ assert active == ["first question", "second question"], active
+
+
[email protected](strict=True, reason="not on the gateway session yet: GatewaySessionStore.rewind_user_turn "
+ "refuses (/retry, /undo) and /new <title>'s rename is not_found. Main's behaviour is "
+ "asserted so the gap stays visible.")
+def test_classic_view_retry_undo_new_match_main(tmp_path):
+ with classic_session(tmp_path) as (send, screen, db, session_id):
+ send("first question", "RECOVERY_ACK_first question")
+ send("second question", "RECOVERY_ACK_second question")
+ sid = session_id()
+ send("/retry", "RECOVERY_ACK_second question")
+ assert 'Retrying: "second question"' in screen()
+ # Main confirms a destructive command; Enter takes "Approve Once".
+ send("/undo", "destroys conversation state")
+ send("", "Undid 1 turn")
+ # The removed message is back in the composer: Enter alone resubmits it.
+ send("", "RECOVERY_ACK_second question")
+ send("/new Second Thread", "destroys conversation state")
+ send("", "New session started")
+ second = session_id()
+ assert second != sid
+ assert db("SELECT title FROM sessions WHERE id=?", second) == [("Second Thread",)]