Skip to content

test: model-based test of transact/retract/checkpoint/reopen (#385) - #475

Merged
adityamukho merged 1 commit into
v3from
test/385-model-based
Oct 7, 2026
Merged

adityamukho merged 1 commit into
v3from
test/385-model-based

Conversation

@adityamukho

Copy link
Copy Markdown
Collaborator

Refs #385 (tracker #383)

What

tests/model_based_test.rs: a stateful proptest that runs random sequences of operations against a file-backed database in a temp dir. After every step it compares results with a plain reference model.

  • Operations: transact (multi-valued batches, valid-time windows at transaction and fact level, a repeated triple with another window → API-011), retract (batched), WriteTransaction (0–4 statements, often retracting a triple it asserts, committed or rolled back), checkpoint, reopen (default, page_cache_size(4), wal_checkpoint_threshold(2)), and a simulated crash: the .graph file and WAL are copied while the handle is open, then the copy is opened, so the WAL is replayed.
  • Checks after every step: current_tx_count; verify() after checkpoint, reopen and crash; full rows ?e ?a ?v ?vf ?vt ?tc ?ti with :any-valid-time, both current and at :as-of N. Six query shapes (full scan, entity, entity+attribute, attribute, attribute+value, value) are each run four ways: no temporal option, :valid-at T, :as-of N :valid-at T, and :as-of N.
  • Model: one valid-time window per triple, taken from its newest assertion (bug: a later assertion does not replace an earlier valid-time window of the same [e a v]; :as-of N should see exactly one window per triple #435). A retraction in the same transaction wins.
  • CI: 24 cases in normal CI (about 3 s). The nightly property-tests.yml becomes a matrix of property_test (8,000,000 cases) and model_based_test (30,000 cases), so each runs on its own runner with its own 6-hour limit.
  • No new dependency. A plain Vec<Step> strategy replaces proptest-state-machine and still shrinks.

Spec: docs/superpowers/specs/2026-10-07-model-based-test-design.md

Verification

  • 3,000 local cases pass. No bugs in the target paths were found.
  • I injected each of these faults; each one made the test fail within 24 cases:
    • Model: ignored retractions, off-by-one :as-of, inclusive :valid-to, exclusive :valid-from, same-tx retraction losing, no API-011.
    • Library: on-disk retractions ignored (reader.rs), older on-disk transactions not hidden, seek skipping the :as-of transaction, WAL replay skipping an entry, tx counter not restored after replay.
  • Full suite: 1348 tests (1339 passing, 9 ignored).

Notes

  • Scheduled workflows run from the default branch, so the nightly model run starts once v3 becomes main. Until then it can be started by hand: gh workflow run property-tests.yml --ref v3.
  • The test found two behaviours outside its scope. They are reported separately and not asserted here:
    1. Dropping a handle opened with wal_checkpoint_threshold(usize::MAX) still saves the file, because PersistentFactStorage::drop saves whenever the data is dirty. The SyncMode::Normal docs say this sentinel suppresses the close-time checkpoint.
    2. Inside a WriteTransaction, retracting a triple and then re-asserting it reads back as live. After commit, the triple is retracted, because both get the same tx_count and the retraction wins.

🤖 Generated with Claude Code

https://claude.ai/code/session_015GgLEs8YozJjYhwPEYgTUn

tests/model_based_test.rs runs random sequences of transacts (multi-valued
batches, transaction- and fact-level valid-time windows), retracts, write
transactions (committed or rolled back, retracting their own assertions),
checkpoints, reopens (default, 4-page cache, auto-checkpoint every 2
writes) and simulated crashes (a copy of the .graph file and WAL taken
while the handle is open, so the WAL is replayed) against a file in a temp
dir. After every step, the tx counter, verify(), full rows with windows and
tx counts, and six query shapes under :as-of N and :valid-at T must match
a reference model.

Normal CI runs 24 cases. The nightly property-test workflow becomes a
matrix over property_test and model_based_test (30,000 cases).

Spec: docs/superpowers/specs/2026-10-07-model-based-test-design.md

Refs #385

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015GgLEs8YozJjYhwPEYgTUn
@codecov

codecov Bot commented Oct 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@adityamukho
adityamukho merged commit 19b0765 into v3 Oct 7, 2026
24 checks passed
@adityamukho
adityamukho deleted the test/385-model-based branch October 7, 2026 10:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant