Two milestones: a note can carry its own check (317), and a rule keeps what it used to say (323) #135
@@ -44,6 +44,22 @@ async def _sweep_sql(**kwargs):
|
|||||||
return captured["sql"]
|
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 ──────────────────────────────────
|
# ── the ordering, which is the whole signal ──────────────────────────────────
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
@@ -62,9 +78,13 @@ async def test_never_checked_sorts_first_not_last():
|
|||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_the_order_is_total():
|
async def test_the_order_is_total():
|
||||||
"""A tiebreak, so two notes verified in the same transaction do not swap
|
"""A tiebreak, so two notes verified in the same transaction do not swap
|
||||||
places between calls and make a page boundary lie."""
|
places between calls and make a page boundary lie.
|
||||||
sql = await _sweep_sql()
|
|
||||||
assert sql.index("NULLS FIRST") < sql.index("notes.id")
|
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 ──────────────────────────────────────────────────
|
# ── 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
|
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
|
that could tell somebody. Hiding it to match the invariant would make the
|
||||||
sweep agree with a database it had stopped describing."""
|
sweep agree with a database it had stopped describing."""
|
||||||
sql = await _sweep_sql()
|
where = _where(await _sweep_sql())
|
||||||
assert "notes.status IS NULL" not in sql
|
assert "notes.status" not in where
|
||||||
assert "notes.note_type" not in sql
|
assert "notes.note_type" not in where
|
||||||
|
|
||||||
|
|
||||||
# ── the filters ──────────────────────────────────────────────────────────────
|
# ── the filters ──────────────────────────────────────────────────────────────
|
||||||
|
|||||||
Reference in New Issue
Block a user