Files
hermes-agent/tests/hermes_cli/test_cli_goal_kick_prompt.py
T
teknium1 d10bb2ab6f test: make tests/ mirror the source tree; drop issue numbers from filenames
`scripts/run_tests.sh tests/<dir>/` is how a change gets its regression
coverage run, so a test filed under the wrong directory is a test nobody
runs when that code changes. Two kinds of drift had accumulated.

Parallel directories for one source package, folded into the mirror:
  tests/acp        -> tests/acp_adapter   (its __init__/conftest move with it)
  tests/cli        -> tests/hermes_cli    (prompt_toolkit fixture merged into
                                           hermes_cli/conftest.py)
  tests/run_agent  -> tests/agent         (backoff fixture becomes
                                           agent/conftest.py)
  tests/relay      -> tests/gateway/relay
  tests/state      -> tests/hermes_state

246 loose files at tests/ root, routed by the package they import/patch:
hermes_cli, hermes_state, agent, gateway, tools, plugins, tui_gateway, cron.
Installer and desktop-update script tests go to tests/scripts/{install,
desktop_update}/. 43 tests of root-level modules (batch_runner, utils,
hermes_constants, packaging) stay at the root.

Filenames drop their issue numbers (95 files: test_89315_x.py -> test_x.py);
the number stays in the module docstring where it has context.

Collisions: test_cli_skin_integration.py existed in both tests/ and tests/cli
with different subsets — merged into one (10 tests, all kept);
run_agent/test_pre_compress_memory_context.py -> agent/..._handoff.py;
tests/test_account_usage.py -> agent/test_account_usage_fetch.py;
tests/test_web_server.py -> hermes_cli/test_web_server_ws_ping.py.
Deleted: test_minisweagent_path.py (empty since PR #2804),
test_model_picker_scroll.py (tested a private copy of the logic, imported
nothing), test_process_loop_event_loop_warning.py (asserted asyncio behaviour,
imported nothing from Hermes).

Repo-root path arithmetic (Path(__file__).parents[N], dirname chains) is
bumped for the 202 files that changed depth and verified by evaluating every
such expression against the new location. classify_changes' desktop-updater
lane prefix, tests-os.yml's ignore glob and every in-tree path comment follow
the moves. tests/test_tests_tree_layout.py keeps the tree from drifting back.
2026-09-13 09:18:02 -07:00

70 lines
3.4 KiB
Python

"""`/goal <text>` kicks the loop with a short pointer when the user's last message already carries the goal.
In one run `/goal <2,000-char handoff note>` was issued 16 minutes after the same note had been pasted as
a user message; the kickoff re-sent it and the agent spent 11 API calls / 6 min deciding it was a replay.
"""
import queue
from hermes_cli.cli_commands_mixin import CLICommandsMixin
from hermes_cli.goals import GOAL_ALREADY_SEEN_KICK
def _cli(history):
cli = CLICommandsMixin.__new__(CLICommandsMixin)
cli.conversation_history = history
cli._pending_input = queue.Queue()
from hermes_cli.goals import GoalManager
cli._get_goal_manager = lambda: GoalManager("kick-test")
return cli
def _kick(cli, text):
cli._handle_goal_command("/goal " + text)
return cli._pending_input.get_nowait()
HANDOFF = "HANDOFF: resume round 3 integration.\n" + "\n".join(f" - step {i}: merge r3-{i} and run its targeted suite, then the full suite" for i in range(8))
def test_goal_that_the_user_just_pasted_kicks_with_a_pointer_not_the_text():
cli = _cli([{"role": "user", "content": HANDOFF + "\n\nGo."},
{"role": "assistant", "content": "ok"}])
assert _kick(cli, HANDOFF) == GOAL_ALREADY_SEEN_KICK
# block-style content is handled too
cli = _cli([{"role": "user", "content": [{"type": "text", "text": HANDOFF}]}])
assert _kick(cli, HANDOFF) == GOAL_ALREADY_SEEN_KICK
def test_a_new_goal_or_a_goal_from_an_older_turn_is_kicked_verbatim():
assert _kick(_cli([]), "Ship the release") == "Ship the release"
cli = _cli([{"role": "user", "content": "Something unrelated"}])
assert _kick(cli, HANDOFF) == " ".join(HANDOFF.split())
# only the LAST user message counts: the agent has moved on since an older paste
cli = _cli([{"role": "user", "content": HANDOFF}, {"role": "assistant", "content": "done"},
{"role": "user", "content": "now something else"}])
assert _kick(cli, HANDOFF) == " ".join(HANDOFF.split())
def test_a_short_goal_that_selects_one_option_from_the_last_message_is_kicked_verbatim():
"""Independent-review witness: after a message offering API or UI work, `/goal ship the API` and
`/goal ship the UI` produced identical kickoffs. A goal that is a fragment of the last message
carries the selection; only a near-whole re-paste is replaced by the pointer."""
offer = "I can either ship the API or ship the UI next; which do you want? " * 8
cli = _cli([{"role": "user", "content": offer}])
assert _kick(cli, "ship the API") == "ship the API"
assert _kick(cli, "ship the UI") == "ship the UI"
# a long goal that is only a minority of a much longer message is also kept verbatim
long_goal = "x" * 500
cli = _cli([{"role": "user", "content": long_goal + " " + "y" * 2000}])
assert _kick(cli, long_goal) == long_goal
def test_gateway_and_tui_surfaces_use_the_same_rule(tmp_path, monkeypatch):
"""Independent review: other surfaces still duplicated the full goal. One shared function now."""
from hermes_cli import goals
long_goal = "HANDOFF " + "step; " * 120
assert goals.goal_kick_prompt(long_goal, long_goal) == goals.GOAL_ALREADY_SEEN_KICK
assert goals.goal_kick_prompt("ship the API", "ship the API or ship the UI? " * 8) == "ship the API"
# DB-backed lookup fails safe to "" (goal kicked verbatim) when no session/db
assert goals.last_user_message_from_db(None) == ""