Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions scripts/clean_live_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,14 +562,19 @@ def clean_database():
)
stmts.append(f"DELETE FROM repositories WHERE project_id IN ({sub});")
stmts.append(f"DELETE FROM projects WHERE {conditions};") # noqa: S608
# The ledger references the user, so the user cannot go first. Deleting a
# run's rows and then failing here left every later phase unrun: the sweep
# raises, and what it had not reached yet stayed on the stand.
# The synthetic test user is a fixture reused by every run, not residue of
# one, and the attempt ledger that references it is append-only by design —
# a database rule refuses to delete from it, and rightly so. So the user goes
# only while nothing points at it; once a run has recorded an attempt, the
# row stays and the next run reuses it.
#
# Deleting the user unconditionally made the whole sweep raise, and a raising
# sweep is not a partial one: every phase after the database went unrun and
# its residue stayed on the stand.
stmts.append(
"DELETE FROM engineering_attempt_ledger WHERE user_id IN "
"(SELECT id FROM users WHERE telegram_id = 999000001);"
"DELETE FROM users WHERE telegram_id = 999000001 "
"AND NOT EXISTS (SELECT 1 FROM engineering_attempt_ledger l WHERE l.user_id = users.id);"
)
stmts.append("DELETE FROM users WHERE telegram_id = 999000001;")
sql = "\n".join(stmts)
result = run_cmd(
[
Expand Down
15 changes: 8 additions & 7 deletions scripts/tests/test_clean_live_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,16 +831,17 @@ def test_another_contour_is_not_this_contour_s_residue(monkeypatch):
importlib.reload(clean_live_tests)


def test_the_test_user_s_ledger_goes_before_the_test_user():
"""The ledger references the user; deleting the user first fails the sweep.
def test_the_sweep_never_deletes_from_the_append_only_ledger():
"""The ledger is append-only by a database rule, and that rule is deliberate.

And a failed sweep is not a partial sweep — it raises, so every phase after
the database was never reached.
Deleting the referenced user unconditionally made the sweep raise — and a
raising sweep is not a partial one: every phase after the database went
unrun. The user is a fixture reused by every run, so it goes only while
nothing points at it.
"""
import inspect

source = inspect.getsource(clean_live_tests.clean_database)
ledger = source.index("engineering_attempt_ledger")
user = source.index("DELETE FROM users")

assert ledger < user
assert "DELETE FROM engineering_attempt_ledger" not in source
assert "NOT EXISTS (SELECT 1 FROM engineering_attempt_ledger" in source