fix(integration): sessions CLI — close db via try/finally, complete test doubles

cmd_sessions used 'with db:' which breaks test doubles lacking the context
manager protocol (13 reds in test_sessions_pin/delete/export). Restore the
explicit try/finally db.close() (same semantics for real SessionDB). Add
get_session/count_prune_matches to the FakeDB doubles in test_sessions_delete
instead of re-adding getattr guards to production code.
This commit is contained in:
Teknium
2026-09-03 02:06:29 -07:00
parent 75934b89c8
commit 0fc204042d
2 changed files with 9 additions and 1 deletions

View File

@@ -950,9 +950,11 @@ def cmd_sessions(args, sessions_parser=None):
except Exception as e:
print(f"Error: Could not open session database: {e}")
return 1
with db:
try:
handler = _DB_HANDLERS.get(action)
if handler is None:
sessions_parser.print_help()
return
return handler(db, args)
finally:
db.close()

View File

@@ -14,6 +14,9 @@ def test_sessions_delete_accepts_unique_id_prefix(monkeypatch, capsys):
captured["resolved_from"] = session_id
return "20260315_092437_c9a6ff"
def get_session(self, session_id):
return {"id": session_id, "pinned": 0}
def delete_session(self, session_id, **kwargs):
captured["deleted"] = session_id
return True
@@ -78,6 +81,9 @@ def _run_prune(monkeypatch, capsys, argv_tail, candidates=None, skipped_open=0):
assert kwargs == seen
return skipped_open
def count_prune_matches(self, **kwargs):
return len(rows)
def prune_sessions(self, **kwargs):
return len(rows)