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:
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user