hermes-agent/tests/hermes_state/test_hermes_state_ux_messages.py
teknium1 76cfc7b257 test: restore state.db / SessionDB regression guards dropped by #120071
Restored (each proven red against a sabotaged production path, green on main):

- tests/agent/test_overflow_overhead_aware_tokens.py::
  test_overflow_recovery_compresses_with_tool_overhead_counted[413,
  context_overflow, prompt_too_long, long_context_tier_429]
  Rewritten from the four estimator-to-compressor tests: the real estimator
  runs with a ~10k-token tool schema and the compressor must receive an
  approx_tokens that counts it (LCM issue 441). No helper-name pinning.
- tests/hermes_cli/test_web_server_sessiondb_eventloop.py::
  test_bulk_delete_sessiondb_work_runs_off_event_loop,
  test_session_read_handlers_run_sessiondb_work_off_event_loop[search,stats,detail]
  Real route handlers; every SessionDB open/call lands off the event-loop
  thread (#60747). AST/source tests stay deleted.
- tests/hermes_state/test_hermes_state.py::TestCompressionChainProjection::
  test_list_batches_tip_row_fetch_into_one_query
  list_sessions_rich resolves a page of compression tips in one batched
  query, not one per root (N+1 guard).
- tests/hermes_state/test_tail_rewind_semantics.py::TestCompressTagsCarriedTail::
  test_compress_marks_carried_forward_tail_dicts
  Repaired from a skip-on-exception body that asserted nothing: compress()
  tags exactly the verbatim carried tail so archive_and_compact gets an
  accurate tail_count (#86366).
- tests/hermes_state/test_wal_checkpoint_strategy.py::
  test_failed_checkpoint_never_raises_and_is_not_silent,
  test_failed_checkpoint_at_close_still_releases_the_handle
  Periodic PASSIVE checkpoint failure neither raises into the write path nor
  passes silently; a failing checkpoint at close() still releases the
  handle (#45383 strategy). Log-wording asserts dropped.
- tests/hermes_state/test_hermes_state_ux_messages.py::
  test_db_unavailable_details_line_carries_raw_cause_only_below_the_lead,
  test_db_unavailable_network_drive_cause_does_not_offer_doctor_fix
  CLI details=True keeps the raw SQLite cause on its own Details line only;
  a locking-protocol (network FS) cause never offers `doctor --fix`.
- tests/tools/test_code_execution.py::TestStubSchemaDrift::
  test_generated_module_accepts_all_params
  Replaces the syntax-only test_generated_module_compiles: executes the
  generated hermes_tools module (uds and file transports) and asserts every
  stub accepts all its params as kwargs and forwards each by name and value.
2026-09-23 10:34:54 -07:00

76 lines
2.9 KiB
Python

"""Plain-language contracts for hermes_state user-facing errors (CLI UX message campaign, cluster D)."""
import hermes_state
from hermes_state import format_session_db_unavailable
def test_db_unavailable_is_one_line_for_chat_surfaces_by_default():
hermes_state._set_last_init_error("OperationalError: database is locked")
try:
text = format_session_db_unavailable(prefix="Cannot resume")
finally:
hermes_state._set_last_init_error(None)
assert "\n" not in text
assert "Details:" not in text
assert text.startswith("Cannot resume:")
def test_db_unavailable_commands_are_pinned_to_the_failing_profile(monkeypatch, tmp_path):
"""Both fallbacks that bypass the shared cause table (no cause; network-drive gloss) name the
profile whose store failed, like the table's actions do."""
from hermes_constants import profile_cli_selector
monkeypatch.setenv("HERMES_HOME", str(tmp_path / ".hermes" / "profiles" / "research"))
selector = profile_cli_selector()
assert selector.strip()
hermes_state._set_last_init_error(None)
no_cause = format_session_db_unavailable()
hermes_state._set_last_init_error("OperationalError: locking protocol")
try:
network = format_session_db_unavailable()
finally:
hermes_state._set_last_init_error(None)
for text in (no_cause, network):
assert f"`hermes {selector}doctor`" in text and "`hermes doctor`" not in text
assert "{profile_arg}" not in text
def test_db_unavailable_details_line_carries_raw_cause_only_below_the_lead():
"""CLI banner (details=True): the raw SQLite text is kept for bug reports on
its own ``Details:`` line and never leaks into the plain-language lead; with
no recorded cause there is nothing to detail."""
hermes_state._set_last_init_error("OperationalError: database is locked")
try:
text = format_session_db_unavailable(details=True)
finally:
hermes_state._set_last_init_error(None)
lead, *rest = text.splitlines()
assert "OperationalError" not in lead
assert len(rest) == 1 and rest[0].startswith("Details: ") and "database is locked" in rest[0]
no_cause = format_session_db_unavailable(details=True)
assert "\n" not in no_cause and "Details:" not in no_cause
def test_db_unavailable_network_drive_cause_does_not_offer_doctor_fix():
"""A locking-protocol failure means the DB sits on a network filesystem that
cannot host SQLite's WAL; `hermes doctor --fix` cannot repair a mount, so it
must not be the offered action (only moving the file helps)."""
hermes_state._set_last_init_error("OperationalError: locking protocol")
try:
text = format_session_db_unavailable(details=True)
finally:
hermes_state._set_last_init_error(None)
lead, details = text.splitlines()
assert "doctor --fix" not in lead
assert "locking protocol" not in lead and "locking protocol" in details