fix(tests): the sweep assertions read the WHERE clause, not the SELECT list (#3166)
CI & Build / Python lint (push) Successful in 3s
CI & Build / Plugin hooks (push) Successful in 9s
CI & Build / TypeScript typecheck (push) Successful in 23s
CI & Build / integration (push) Successful in 25s
CI & Build / Python tests (push) Successful in 1m6s
CI & Build / Build & push image (push) Successful in 24s

select(Note) names every column, so searching the whole statement for
"notes.note_type" always finds the projection, and sql.index("notes.id") finds
the first column rather than the ORDER BY tiebreak. Both tests were asking the
wrong string.

The ordering test now asserts on the END of the statement, and the filter test
reads the WHERE clause — extracted by regex rather than split on a literal,
because the exact whitespace SQLAlchemy puts around WHERE is not something a
test should depend on.

The product is unchanged: the two assertions that mattered — NULLS FIRST
present, and no legal-carrier filter in the predicate — were both already
true.
This commit is contained in:
2026-08-28 16:59:41 -04:00
parent 8489206224
commit b51621fca7
+26 -6
View File
@@ -44,6 +44,22 @@ async def _sweep_sql(**kwargs):
return captured["sql"]
def _where(sql: str) -> str:
"""Just the WHERE clause. `select(Note)` names every column, so searching
the whole statement for a column name always finds the SELECT list — which
is how one of these tests first failed for the wrong reason.
Matched by regex rather than split on a literal, because the exact
whitespace SQLAlchemy emits around WHERE is not something a test should
depend on.
"""
import re
m = re.search(r"\bWHERE\b(.*?)(?:\bORDER BY\b|$)", sql, re.S)
assert m, "no WHERE clause — the sweep must never select the whole table"
return m.group(1)
# ── the ordering, which is the whole signal ──────────────────────────────────
@pytest.mark.asyncio
@@ -62,9 +78,13 @@ async def test_never_checked_sorts_first_not_last():
@pytest.mark.asyncio
async def test_the_order_is_total():
"""A tiebreak, so two notes verified in the same transaction do not swap
places between calls and make a page boundary lie."""
sql = await _sweep_sql()
assert sql.index("NULLS FIRST") < sql.index("notes.id")
places between calls and make a page boundary lie.
Asserted on the END of the statement, not by searching it: `select(Note)`
names every column, so the first `notes.id` in the text is the SELECT
list, not the ORDER BY."""
sql = (await _sweep_sql()).rstrip()
assert sql.endswith("ORDER BY notes.verified_at ASC NULLS FIRST, notes.id")
# ── which rows are eligible ──────────────────────────────────────────────────
@@ -98,9 +118,9 @@ async def test_a_task_carrying_a_check_is_NOT_filtered_out():
so such a row would be in an ILLEGAL state — and this is the one surface
that could tell somebody. Hiding it to match the invariant would make the
sweep agree with a database it had stopped describing."""
sql = await _sweep_sql()
assert "notes.status IS NULL" not in sql
assert "notes.note_type" not in sql
where = _where(await _sweep_sql())
assert "notes.status" not in where
assert "notes.note_type" not in where
# ── the filters ──────────────────────────────────────────────────────────────