fix(honcho): describe what _seen_gateway_accounts can list
The docstring said grouping session rows by (source, user_id) enumerates every account the gateway handled. record_gateway_session_peer overwrites a row's user_id, so a shared thread keeps only its last author. The docstring now says that, and a test pins it.
This commit is contained in:
@@ -1060,8 +1060,8 @@ def _state_db_path() -> Path:
|
||||
def _seen_gateway_accounts(db_path: Path) -> list[dict]:
|
||||
"""Gateway accounts recorded in state.db, most recent first; bot authors are skipped.
|
||||
|
||||
The gateway stamps each session row with its routing peer, so grouping rows by
|
||||
(source, user_id) enumerates every account it has handled.
|
||||
A session row keeps only its last routing peer, so a shared thread contributes
|
||||
its most recent author and not every participant.
|
||||
"""
|
||||
if not db_path.exists():
|
||||
return []
|
||||
|
||||
@@ -51,6 +51,15 @@ class TestSeenGatewayAccounts:
|
||||
{"platform": "telegram", "user_id": "111", "user_id_alt": "", "label": "eri", "sessions": 2, "profiles": []},
|
||||
]
|
||||
|
||||
def test_shared_session_lists_only_its_last_author(self, tmp_path):
|
||||
"""record_gateway_session_peer overwrites the row's user_id, so earlier authors are gone."""
|
||||
from hermes_state import SessionDB
|
||||
|
||||
db = SessionDB(tmp_path / "state.db")
|
||||
for uid in ("alice", "bob"):
|
||||
db.record_gateway_session_peer("shared", source="telegram", user_id=uid, session_key="telegram:group:1")
|
||||
assert [a["user_id"] for a in _seen_gateway_accounts(tmp_path / "state.db")] == ["bob"]
|
||||
|
||||
def test_missing_db_or_table_returns_empty(self, tmp_path):
|
||||
assert _seen_gateway_accounts(tmp_path / "absent.db") == []
|
||||
sqlite3.connect(tmp_path / "empty.db").close()
|
||||
|
||||
Reference in New Issue
Block a user