test: the commit check starts every request clean, and the fence docs claim what it holds

The test's own writes are committed before a request, so a handler's Core DML can no longer hide
in a transaction the test had already opened. The entry-point probe answers on a marked line the
API's logging cannot mix into. A listed commit whose function no longer commits fails the fence.
CLAUDE.md and the backend README now name what an AST cannot see; the route-commit tests no longer
claim their read-back holds the commit.
This commit is contained in:
2026-10-20 01:56:31 +02:00
parent c5f121139b
commit 6ea750a698
6 changed files with 59 additions and 21 deletions
+10 -2
View File
@@ -87,7 +87,8 @@ def test_a_request_that_raises_leaves_nothing_it_did_not_commit(db):
def test_the_commit_check_sees_a_core_dml_write(db, make_user):
"""`db.execute(update(...))` flushes nothing and stages nothing, so the session's own bookkeeping
never sees it: a handler whose only write is Core DML and that forgot its commit passed. The
database's transaction id is what tells. A committed one must still pass."""
database's transaction id is what tells — also when the test itself had a write open before the
request, which the handler's write would otherwise share. A committed one must still pass."""
import pytest
from sqlalchemy import update
from starlette.requests import HTTPConnection
@@ -96,7 +97,9 @@ def test_the_commit_check_sees_a_core_dml_write(db, make_user):
user = make_user()
def drive(commit: bool) -> None:
def drive(commit: bool, *, test_wrote: bool = False) -> None:
if test_wrote: # the test's own write, open and uncommitted, as the request starts
db.execute(update(User).where(User.id == user.id).values(display_name="test"))
conn = HTTPConnection(
{"type": "http", "method": "POST", "path": "/probe", "headers": [], "query_string": b""}
)
@@ -113,3 +116,8 @@ def test_the_commit_check_sees_a_core_dml_write(db, make_user):
drive(commit=False)
assert db.info["unfinished"] == ["POST /probe"]
db.info["unfinished"].clear() # recorded as it should be — not this test's failure
drive(commit=True, test_wrote=True)
assert db.info["unfinished"] == []
drive(commit=False, test_wrote=True)
assert db.info["unfinished"] == ["POST /probe"]
db.info["unfinished"].clear()