Files
hermes-agent/tests/tools/test_session_search_readonly.py
Teknium e1a10b0bc2 ci: bring the branch's own code under main's strict ruff config
Main made the strict ruff config the default (`ruff check .`, blocking), and
the branch's code carried 278 findings under it (main itself is clean). Fixed:

- PLW1510 (86): `check=False` on each subprocess.run, preserving behaviour,
  as main's own sweep (0006a5e229) did.
- ASYNC220 (9, test fixtures only): `noqa` with the reason, main's convention
  for a Popen that returns at once and whose handle the test drives.
- ruff's safe autofixes plus the narrow unsafe ones (UP006/UP037/RUF100/RUF013/
  PLR0402/RUF059 underscore renames/UP031/UP041/UP017/FURB167/PIE807/RUF007/
  RUF015/RUF022/FURB162), and by hand: four %-formats to f-strings, three
  unused unpacked names, one fixture loop over `.items()`.

No behaviour change. `ruff check .` passes; scripts/check passes; the 412 test
files mirroring every edited file pass (3 tests/pm files that fail only under
that batch's uv lookup pass solo, before and after this commit).
2026-10-10 17:59:08 -07:00

69 lines
2.7 KiB
Python

"""Search never becomes another session-database initializer."""
import json
from pathlib import Path
import sqlite3
def test_search_does_not_create_current_storage_for_empty_or_foreign_reads(tmp_path, monkeypatch):
from hermes_constants import reset_hermes_home_override, set_hermes_home_override
from hermes_state import SessionDB
import tools.session_search_tool
from tools.registry import registry
monkeypatch.setattr(Path, "home", lambda: tmp_path)
home = tmp_path / ".hermes"
home.mkdir()
monkeypatch.setenv("HERMES_HOME", str(home))
token = set_hermes_home_override(home)
handler = registry.get_entry("session_search").handler
try:
empty = json.loads(handler({}))
assert not (home / "state.db").exists(), "a reader created the canonical database"
assert empty["success"] is False
other = home / "profiles" / "reader-target"
other.mkdir(parents=True)
db = SessionDB(other / "state.db")
try:
db.create_session("foreign-read", source="cli")
db.append_message("foreign-read", role="user", content="owned target marker")
finally:
db.close()
for args in [
{"session_id": "foreign-read", "profile": "reader-target"},
{"session_id": "reader-target/foreign-read"},
]:
result = json.loads(handler(args))
assert result["success"] is True, result
assert result["messages"][0]["content"] == "owned target marker"
assert not (home / "state.db").exists()
finally:
reset_hermes_home_override(token)
def test_search_reads_live_storage_without_a_write_commit(tmp_path, monkeypatch):
from hermes_constants import reset_hermes_home_override, set_hermes_home_override
from hermes_state import SessionDB
import tools.session_search_tool
from tools.registry import registry
home = tmp_path / "profile"
home.mkdir()
monkeypatch.setenv("HERMES_HOME", str(home))
token = set_hermes_home_override(home)
owner = SessionDB(home / "state.db")
observer = sqlite3.connect(home / "state.db")
try:
owner.create_session("live-read", source="cli")
owner.append_message("live-read", role="user", content="live reader marker")
before = observer.execute("PRAGMA data_version").fetchone()[0]
result = json.loads(registry.get_entry("session_search").handler({"session_id": "live-read"}))
assert result["success"] is True, result
assert result["messages"][0]["content"] == "live reader marker"
assert observer.execute("PRAGMA data_version").fetchone()[0] == before
finally:
observer.close()
owner.close()
reset_hermes_home_override(token)