refactor(gateway): drop the test-only delivery-ledger _prune() wrapper

After 39e914ea33 the prune runs inside `record_obligation`'s transaction
via `_prune_unlocked`; `_prune()` had a single caller left, the test
`TestPrune::test_old_delivered_rows_pruned`. It also opened its own
transaction WITHOUT `_DB_LOCK` while every other writer in the module
takes `_DB_LOCK, _transaction()`, so the `_unlocked` contract ("caller
holds the lock") was violated by its only wrapper.

Delete it and have the test do what a writer does:
`with dl._DB_LOCK, dl._transaction() as conn: dl._prune_unlocked(conn, now)`.

`grep -rn '_prune(' --include=*.py gateway tests/gateway`: no
production caller (gateway/run.py's hit is `_housekeeping_checkpoint_prune`).

PROOF: tests/gateway/test_delivery_ledger.py (TestPrune included) +
test_delivery_ledger_single_connection.py: 40 passed.
This commit is contained in:
kshitijk4poor
2026-09-22 14:45:09 +05:30
committed by kshitij
parent b255c8fb15
commit 4607e5017c
2 changed files with 3 additions and 10 deletions

View File

@@ -523,15 +523,6 @@ def _prune_unlocked(conn, now: float) -> None:
LIMIT ?)""", (total - _MAX_ROWS,))
def _prune(now: Optional[float] = None) -> None:
now = now if now is not None else time.time()
try:
with _transaction() as conn:
_prune_unlocked(conn, now)
except Exception:
logger.debug("delivery ledger prune failed", exc_info=True)
def ledger_enabled(config: Optional[Dict[str, Any]] = None) -> bool:
"""Read the ``gateway.delivery_ledger`` config gate (default on)."""
try:

View File

@@ -376,7 +376,9 @@ class TestPrune:
"UPDATE delivery_obligations SET updated_at=? WHERE obligation_id=?",
(time.time() - dl._RETENTION_SECONDS - 60, "ob-1"),
)
dl._prune()
# Prune has no wrapper of its own: it runs inside a writer's transaction, lock held.
with dl._DB_LOCK, dl._transaction() as conn:
dl._prune_unlocked(conn, time.time())
assert _row("ob-1") is None