Skip to main content

positions_are_not_reused_after_removal

Function positions_are_not_reused_after_removal 

pub async fn positions_are_not_reused_after_removal<F: Fixture>(
    open: impl AsyncFn() -> F,
) -> RuleOutcome
Expand description

ES-38 (ADR-0028, decision 2): a store that has had events removed outside the port never hands a removed position out again, and its read(Query::all()) and head describe exactly the events it still holds.

The rule removes the tail, appends, then removes everything and appends again. Each append must land above every position the store has ever assigned, head must name the last event still held (or be None once nothing is), and the removed tail’s identity must stay unheld after the position above it is taken.

The wrong implementations, each in tests/mutation_coverage/removed_history.rs, and each removing exactly what it is told to, so the guard passes them:

  • RowidReuseFixture is ES-38’s named wrong implementation: a rowid table without AUTOINCREMENT, which allocates one above the largest rowid it still holds and so hands the deleted tail’s position out again. happenstance-sqlite’s migration test shows the shape on real SQLite.
  • SequenceHeadFixture reads head from the allocator (sqlite_sequence, a sequence’s last_value) rather than from the rows, so after the removal it names the tail that is gone.
  • TruncatingWhenEmptyFixture removes a part correctly and rewinds the allocator when told to remove everything, which is TRUNCATE … RESTART IDENTITY.

RenumberingFixture, which rebuilds the log from its survivors, fails here too: after a tail removal its survivors keep their positions, and the next append takes the tail’s. That is ES-38’s Rejects.

Only the tail and everything are removed. An interior removal adds nothing the guard does not already check, and the tail is where an allocator that reads its last row goes wrong.

It passes on CF-27’s instrument by delegation, because the store under the decorator still holds every withheld event, so the instrument’s pass is not evidence about any allocator; the adapters’ passes are. It asserts nothing about positions before the first removal, which are other rules’ business, and it stands on removal_outside_the_port_removes_exactly_the_named_events: a store the removal did not leave is refused, not judged.