test(agent): update enqueue-after-close contract to the #94736 self-heal

The old contract (write after close() raises AttributeError and drops
the token delta) is superseded: the persistence boundary now reopens
the connection, so the delta lands. Assert the new, stronger contract.
This commit is contained in:
teknium1
2026-08-31 08:49:59 -07:00
committed by Teknium
parent 9db48053e8
commit d3a45a9ce4
+10 -6
View File
@@ -277,18 +277,22 @@ class TestReaderFlush:
assert _totals(db, "s-cc")["input_tokens"] == 4
def test_enqueue_after_close_raises_at_call_site(self, tmp_path):
"""After close() the synchronous fallback surfaces the failure to the
caller (whose try/except logs it) — the pre-queue contract — instead
of silently dropping the delta."""
def test_enqueue_after_close_lands_via_reopen(self, tmp_path):
"""After close() the synchronous fallback used to surface an opaque
AttributeError to the caller and drop the delta. Since the #94736
self-heal, a write that reaches the store after a teardown close()
reopens the connection and LANDS instead — strictly better than the
old raise-and-lose contract: no delta is dropped, and the recovery
is loud (WARNING at the persistence boundary)."""
db = SessionDB(db_path=tmp_path / "closed.db")
db.create_session("s-closed", "test")
db.queue_token_counts("s-closed", input_tokens=1, api_call_count=1)
db.close()
with pytest.raises(Exception):
db.queue_token_counts("s-closed", input_tokens=2, api_call_count=1)
db.queue_token_counts("s-closed", input_tokens=2, api_call_count=1)
assert not db._token_queue # not parked on a dead queue either
assert _totals(db, "s-closed")["input_tokens"] == 1 + 2
db.close()
# =========================================================================