Skip to content

The agent that grows with you

test: session mutation endpoints admit through the authority; poller fake acknowledges

Teknium09e84eacbeae
diff --git a/tests/test_session_detail_malformed_db.py b/tests/test_session_detail_malformed_db.py
index 6663bb0d3d3..88589b7a759 100644
--- a/tests/test_session_detail_malformed_db.py
+++ b/tests/test_session_detail_malformed_db.py
@@ -91,20 +91,52 @@ async def test_messages_endpoint_reports_corruption(malformed_db):
assert excinfo.value.status_code == 503
+class _CorruptAuthorityDB:
+ """Authority store whose first write fails the way a corrupt file really fails."""
+
+ db_path = "/nonexistent/state.db"
+
+ def _validate_import_payload(self, sessions): # pragma: no cover - import only
+ return sessions, []
+
+
+def _mutation_request(monkeypatch):
+ """Delete/rename never open a SessionDB in the handler: they admit through the session
+ authority, so corruption surfaces from the authority write, not from a handler-opened store."""
+ import sqlite3
+ from types import SimpleNamespace
+
+ import gateway.session_mutations as _mutations
+
+ authority = SimpleNamespace(db=_CorruptAuthorityDB(), profile_id="p", epoch=1)
+ principal = object()
+ monkeypatch.setattr(_web_server_sessions, "_session_mutation_context", lambda request, profile: (authority, principal))
+
+ async def _mutate(*_args, **_kwargs):
+ raise sqlite3.DatabaseError("database disk image is malformed")
+
+ monkeypatch.setattr(_mutations, "mutate_session", _mutate)
+ return SimpleNamespace()
+
+
@pytest.mark.asyncio
-async def test_delete_does_not_claim_success_on_a_corrupt_store(malformed_db):
+async def test_delete_does_not_claim_success_on_a_corrupt_store(monkeypatch):
+ request = _mutation_request(monkeypatch)
with pytest.raises(HTTPException) as excinfo:
- await sessions_router.delete_session_endpoint("20260830_180820_744f05")
+ await sessions_router.delete_session_endpoint(
+ "20260830_180820_744f05", request, request_id="r1", expected_revision=1
+ )
assert excinfo.value.status_code == 503
@pytest.mark.asyncio
-async def test_rename_endpoint_reports_corruption(malformed_db):
+async def test_rename_endpoint_reports_corruption(monkeypatch):
from hermes_cli.web_models import SessionRename
+ request = _mutation_request(monkeypatch)
with pytest.raises(HTTPException) as excinfo:
await sessions_router.rename_session_endpoint(
- "20260830_180820_744f05", SessionRename(title="neu")
+ "20260830_180820_744f05", SessionRename(title="neu", request_id="r1", expected_revision=1), request
)
assert excinfo.value.status_code == 503
diff --git a/tests/test_tui_gateway_server.py b/tests/test_tui_gateway_server.py
index 6a7473de40f..84f6e4705a7 100644
--- a/tests/test_tui_gateway_server.py
+++ b/tests/test_tui_gateway_server.py
@@ -7096,6 +7096,7 @@ def test_notification_poller_live_loop_requeues_foreign_completion_for_owner(
def _deliver(_rid, sid, session, text):
delivered["a" if sid == "sid-a-live-handoff" else "b"].append(text)
session["running"] = False
+ return True # the execution gate accepted the turn; None would re-queue for redelivery
monkeypatch.setattr(server, "_run_prompt_submit", _deliver)
server._sessions.update(
diff --git a/tests/test_web_server_sessiondb_eventloop.py b/tests/test_web_server_sessiondb_eventloop.py
index 7666bbcf09c..fda767e55d8 100644
--- a/tests/test_web_server_sessiondb_eventloop.py
+++ b/tests/test_web_server_sessiondb_eventloop.py
@@ -18,7 +18,7 @@ TARGET_HANDLERS = {
"delete_empty_sessions_endpoint",
"get_session_latest_descendant",
"get_session_messages",
- "delete_session_endpoint",
+ # delete_session_endpoint admits through the session authority and opens no SessionDB.
"export_session_endpoint",
"prune_sessions_endpoint",
"get_usage_analytics",