test: real conflict-refresh assertions; AST-exact probe guard

- task-instances matrix test asserts same row id + rewritten due_time
  + pre-refresh None (the vacuous refreshed_same_id walrus is gone)
- compensating guard parses the two sanctioned functions' ASTs: each
  must contain its raw INSERT (children NOT NULL, admin_users PK),
  lexically inside a pytest.raises block, and no other raw SQL may
  name these tables anywhere else in the matrix file
This commit is contained in:
Joshua King
2026-09-14 08:52:30 -04:00
parent c41e28cb29
commit 2265b5c3f1
2 changed files with 76 additions and 29 deletions
+8 -6
View File
@@ -276,20 +276,22 @@ def test_matrix_task_instances_crud_and_constraints(tmp_path) -> None:
# insert (seeded) + read
fetched = await w.instances.get(w.definition.id, D1)
assert fetched == w.instance
# update path: conflict refresh on the OPEN instance
# update path: conflict refresh on the OPEN instance — same row
# id, snapshot columns (due_time) actually rewritten.
refreshed = await w.instances.upsert(
w.definition.id, w.child.id, D1, _stamp(), due_time="17:00"
)
assert refreshed_same_id(fetched, refreshed := refreshed_same_id)
assert refreshed.id == fetched.id, (
"the conflict path must refresh the existing row in place"
)
assert refreshed.due_time == "17:00"
assert fetched.due_time is None
assert await w.instances.get_by_id(fetched.id) is not None
return True
assert _with_world(tmp_path / "m-instances.db")(_body) is True
def refreshed_same_id(original, replacement):
return replacement
def test_matrix_task_instances_constraints(tmp_path) -> None:
async def _body(w: World):
# D20 has no instance yet: a raw insert succeeds, then an