Repository navigation
test(loader): pin that diagnostics do not depend on input order - #1962
Conversation
#1902 Phase 1 proposes "validation is deterministic and order-independent". The determinism half is already covered THREE times over in rustledger-validate - validation_pipeline_is_deterministic, coupled_pipeline_is_deterministic, prop_validation_deterministic - and every one of them runs the SAME input twice. That pins repeat-run stability and says nothing about ordering. This adds the order half: 720 permutations, exhaustive over a six-block ledger, asserting the diagnostics are identical. TWO EARLIER FRAMINGS WERE DISCARDED, BOTH BECAUSE THEY COULD NOT FAIL First I compared the LOADER's directive sequence across permutations, on the assumption that the loader canonicalizes order. It does not: `LoadResult.directives` preserves source order and the date sort happens downstream, in query, balance views and booking. Worth knowing; it is documented nowhere. That version also failed for a reason unrelated to ordering - directives carry source metadata, so renumbering the file changes every line number, and a Debug comparison reports that as a difference. Then I compared diagnostics but could not falsify it by deleting the loader's sorts, because the validators are order-insensitive in their own right. The sorts are not what makes the property hold. What ships is the user-facing claim WITH a demonstrated failure mode: a validator that reads `directives.first()` makes it fail. input order [3, 1, 2, 0, 4, 5] changed the diagnostics That is the shape a real regression would take - a validator that consults input position instead of ledger state - and it is why the test is worth having even though nothing today violates it. EXHAUSTIVE RATHER THAN SAMPLED 720 orderings is cheap, and exhaustive means a failure is reproducible without a seed. A randomized property is at its most annoying exactly when it finally trips. Carries a non-vacuity assertion: the fixture must produce diagnostics, or the comparison is between two empty vectors forever. Refs #1902.
📊 Benchmark Results
vs main branch (2026-08-04)
What do these numbers mean?
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Pull request overview
Adds an integration test in rustledger-loader to assert that validation diagnostics are invariant under permutations of directive (block) order, supporting the “order-independent” half of the determinism claim tracked in #1902.
Changes:
- Introduces an exhaustive-permutation test harness that rewrites a temp ledger file for each ordering and compares the resulting validation outputs.
- Adds a small permutation generator and a non-vacuity assertion to ensure the fixture actually produces diagnostics.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
| Metric | Result |
|---|---|
| Check Compatibility | 100% |
| BQL Compatibility | 95% (raw 89%, 162 masked) |
| Full AST Match | 100% |
| Total Files | 812 |
What's tested
- Check: Exit codes and error counts match
bean-check - BQL: Query results match
bean-query
The headline is the EFFECTIVE rate, after pairs where beanquery
itself is wrong are masked. raw is the same run with nothing
masked. A widening gap means the registry grew, not that rledger
changed. - Files: ~800 test files downloaded from 10+ beancount repositories
Full results available in workflow artifacts
Three review points, all real: - The module doc opened by claiming the loader produces a canonical directive order. It does not, and the body two paragraphs down says so - leftover from a framing that was discarded for that reason. - Codes were collected via Debug, i.e. the enum variant name. Renaming a variant is a refactor; here it would have read as a behavior change. Compare ErrorCode::code(), the stable rendered E-number. - blocks() defines eight blocks but only the first six were permuted, so the balance directive and the unopened-account transaction never moved, despite the fixture comments calling out the same-date pad and balance as the pair most likely to be order-sensitive. E1001 was not produced at all. Now exhaustive over all 40320 orderings (18s). Non-vacuity tightened from !is_empty() to a per-code check, since the unbalanced transaction alone satisfied the old form. Verified the test can still report dirty by dropping the last directive in run_early: it fails on [0, 1, 2, 3, 4, 6, 7, 5], a permutation only reachable now.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Suppressed comments (3)
crates/rustledger-loader/tests/validation_order_independence.rs:77
ValidationSession::run_lateis documented as requiring booking to have run between Early and Late, but the test callsrun_late(&plain, ...)on the pre-booking directives. This can silently become incorrect if the fixture (or validators) starts relying on booked/interpolated transactions, and it doesn’t match the real pipeline shape (Early → book → Late → finalize).
let session = rustledger_validate::ValidationSession::new(options);
let (session, early) = session.run_early(&plain, today);
let (session, late) = session.run_late(&plain, today);
let pad = session.finalize();
crates/rustledger-loader/tests/validation_order_independence.rs:102
- The doc comment says “720 orderings”, but the test currently permutes
blocks().len()items (8 blocks), and even references “40320 orderings” later. This is misleading and also conflicts with the PR description’s stated 720-permutation scope; either update the docs to match the actual 8! = 40,320 permutations or reduce the fixture to 6 blocks if 720 is the intended bound.
/// 720 orderings is cheap, and exhaustive means a failure is reproducible
/// without a seed — the thing that makes a randomized property annoying to act
/// on when it finally trips.
crates/rustledger-loader/tests/validation_order_independence.rs:49
blocks()allocates a freshVecevery time it’s called, but it’s invoked insidecodes_for(once per permutation). With 40,320 permutations, that’s a lot of unnecessary allocations; using aconstarray (or astaticslice) avoids repeated heap work and reduces test runtime noise.
fn blocks() -> Vec<&'static str> {
vec![
"2024-01-01 open Assets:Bank",
"2024-01-01 open Expenses:Food",
"2024-01-01 open Equity:Open",
#1902 Phase 1 proposes "validation is deterministic and order-independent". The determinism half is already covered three times over in
rustledger-validate—validation_pipeline_is_deterministic,coupled_pipeline_is_deterministic,prop_validation_deterministic— and every one runs the same input twice. That pins repeat-run stability and says nothing about ordering.This adds the order half: 720 permutations, exhaustive over a six-block ledger, asserting the diagnostics are identical.
Two earlier framings were discarded, both because they could not fail
First, I compared the loader's directive sequence across permutations, assuming the loader canonicalizes order. It does not —
LoadResult.directivespreserves source order, and the date sort happens downstream in query, balance views and booking. That's worth knowing; it's documented nowhere. That version also failed for a reason unrelated to ordering: directives carry source metadata, so renumbering the file changes every line number and aDebugcomparison reports it as a difference.Second, I compared diagnostics but couldn't falsify it by deleting the loader's sorts — because the validators are order-insensitive in their own right. The sorts are not what makes the property hold.
Both were dropped rather than shipped. A guard I can't make fail is decoration, and this session has already turned up four tests that were pinning the wrong thing.
What ships, with a demonstrated failure mode
A validator that reads
directives.first()makes it fail:That's the shape a real regression would take — a validator consulting input position instead of ledger state — and it's why the test is worth having even though nothing today violates it.
Exhaustive rather than sampled
720 orderings is cheap, and exhaustive means a failure is reproducible without a seed. A randomized property is at its most annoying exactly when it finally trips.
Carries a non-vacuity assertion: the fixture must produce diagnostics, or the comparison is between two empty vectors forever.
Verification
validation) and validate suites: 0 failurescargo fmt --checkcleanRefs #1902.