Repository navigation
Commit b074bad
authored
fix(booking): stop padding a balance on the pad's own date (#2187)
* fix(booking): stop padding a balance on the pad's own date
A `pad` and the `balance` it targets on the same date synthesized a
padding transaction beancount does not. On the issue's fixture the
account ended 60.00 USD richer -- 100.00 where beancount reports 40.00 --
and `check` reported the pad as UNUSED in the same run that booked it.
beancount checks a balance at the START of its day: `entry_sortkey` gives
Balance -1 and Pad the default 0, so a same-date balance is evaluated
before the pad exists and consumes nothing. Ours had `DirectivePriority`
Pad=2 before Balance=3, with a comment asserting "padding before balance
assertions", and `process_pads` sorted by DATE ALONE -- so a pad written
above its balance was processed first and the balance consumed it.
Both are fixed: Balance now precedes Pad, and `process_pads` sorts by the
canonical `booking_sort_key` rather than by date.
Two tests pinned the old behavior and are inverted, with the evidence in
their comments. One asserted a same-date synth exists and precedes the
balance; the ordering guarantee it was really protecting is preserved in
a new test on the day-earlier case, which is where a synth actually
exists. The other was named `test_sort_directives_pad_before_balance`.
Verified:
- the fixture now returns 40.00, matching beancount; a pad one day
earlier still pads to 100.00, also matching
- `check` still emits E2003 and E2001, which is what bean-check emits
for the same file -- the difference is that we no longer book the pad
we call unused
- booked values UNCHANGED on all four corpus files that contain a
same-date pad+balance, compared against a main-built binary
- directive order changes only in files containing pads: 59 pad-free
files produce byte-identical `#entries` output
- the four new `corpus_parity` divergences are the prebuilt component
still using the old order (`native=(balance) component=(pad)`), which
is what a correct engine change looks like against a stale component
Not fixed here, and worth stating: beancount interleaves same-date pads
and transactions by lineno (both sort at 0) while we still group by type.
That is the ordering divergence in #2149, unchanged by this.
The booked-value gate reports clean, but its axis is prices; it does not
compare balances and so does not exercise this.
Closes #2150
* test(booking): pin the pad that follows a same-date balance
Review find on #2187. Sweeping the pad scenarios against beancount turned
up a second broken case, worse than the reported one: a pad written after
a balance on the same date, serving a LATER balance.
2024-06-15 balance Assets:A 0.00 USD
2024-06-15 pad Assets:A Equity:O
2024-07-01 balance Assets:A 50.00 USD
bean-check accepts that file. On main the account came back with NO
balance at all and `check` reported nothing -- silently empty rather than
silently wrong. The same-date balance consumed the pad, so the later
assertion had nothing left.
The fix already covers it, because Balance now precedes Pad and the pad
stays pending. This adds the test.
Both halves of the fix are confirmed by mutation: restoring
Pad-before-Balance fails two tests, restoring the date-only sort in
`process_pads` fails one.
* style(booking): count instead of collecting in the new pad test
* test(ffi): cover the same-date pad+balance on the FFI path
Review find on #2187. The issue explicitly left the FFI path unverified,
noting that `expand_pads` runs its own date-only sort and could diverge
from the CLI either way. Nothing there covered the case: the existing
`SAME_DATE_LEDGER` shares a date between a pad and an UNRELATED
transaction, with the balance a day later.
It is correct -- `expand_pads` gets its pads from `process_pads`, which
this branch fixed, so the decision is shared rather than duplicated --
but that was unverified rather than untrue. Now asserted, and confirmed
to fail when Pad-before-Balance is restored.
The date-only sort at the top of `expand_pads` is left alone. It orders
the OUTPUT pairs, not the pad decision, and changing it would reorder
same-date directives on the FFI path only. Whether the two paths should
share an ordering rule is worth deciding on its own, not as a rider here.
* docs(booking): mark the stale same-date-balance rule in pad_insertion_index
* fix(wasm): bump the cache version the priority swap invalidates
`LedgerPayload` archives the output of the shared `process()` pipeline,
which sorts by `canonical_sort_key` -- and that key reads
`DirectivePriority`. Swapping `Pad` and `Balance` therefore changes the
LIST this cache holds without changing a single directive in it: every
one archives to the same bytes, in a different order.
What a stale blob costs is narrower than it first looks, and the first
draft of this message got it wrong by saying the pad AMOUNTS come back
stale. They do not: `process_pads` re-sorts its input by
`booking_sort_key`, the same `(date, priority)`, so amounts computed
from a v16 blob still come out right. What differs is the order of the
directives the cache hands back -- what journal output, `SELECT` row
order and the FFI directive stream all read. A cache that returns a
different sequence than a fresh run is stale by definition, which is
reason enough and is the reason recorded.
`processed_ledger_archived_form_is_pinned`, which landed on main with
#2189 for exactly this class, failed on the rebase and had to be
re-pinned. That is the guard working: the version bump was argued for in
review before, and is now also demanded by a test.
Also folds in two review corrections: `pad.rs` no longer claims to sort
"by date" directly above the comment explaining that it sorts by the
booking key, and the variant census in `cache.rs` identifies variants by
`Directive::type_name` rather than `Debug` on `mem::Discriminant`, whose
format is not a documented guarantee -- it also names the missing
variant when it fails.1 parent 1ef068d commit b074bad
4 files changed
Lines changed: 207 additions & 31 deletions
File tree
- crates
- rustledger-booking/src
- rustledger-core/src
- rustledger-ffi-wasi/src
- rustledger-wasm/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
142 | 142 | | |
143 | 143 | | |
144 | 144 | | |
145 | | - | |
146 | 145 | | |
147 | | - | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
148 | 153 | | |
149 | 154 | | |
150 | 155 | | |
| |||
339 | 344 | | |
340 | 345 | | |
341 | 346 | | |
342 | | - | |
343 | | - | |
344 | | - | |
345 | | - | |
346 | | - | |
347 | | - | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
348 | 361 | | |
349 | 362 | | |
350 | 363 | | |
| |||
435 | 448 | | |
436 | 449 | | |
437 | 450 | | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
438 | 458 | | |
439 | 459 | | |
440 | 460 | | |
| |||
822 | 842 | | |
823 | 843 | | |
824 | 844 | | |
825 | | - | |
826 | | - | |
827 | | - | |
828 | | - | |
829 | | - | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
830 | 856 | | |
831 | 857 | | |
832 | 858 | | |
| |||
840 | 866 | | |
841 | 867 | | |
842 | 868 | | |
843 | | - | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
844 | 937 | | |
845 | 938 | | |
846 | 939 | | |
847 | | - | |
| 940 | + | |
848 | 941 | | |
849 | 942 | | |
850 | 943 | | |
851 | 944 | | |
852 | 945 | | |
853 | 946 | | |
854 | | - | |
| 947 | + | |
855 | 948 | | |
856 | 949 | | |
857 | 950 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
487 | 487 | | |
488 | 488 | | |
489 | 489 | | |
490 | | - | |
491 | | - | |
492 | | - | |
493 | | - | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
494 | 503 | | |
495 | 504 | | |
496 | 505 | | |
| |||
1744 | 1753 | | |
1745 | 1754 | | |
1746 | 1755 | | |
1747 | | - | |
| 1756 | + | |
| 1757 | + | |
| 1758 | + | |
| 1759 | + | |
1748 | 1760 | | |
1749 | 1761 | | |
1750 | 1762 | | |
| |||
1788 | 1800 | | |
1789 | 1801 | | |
1790 | 1802 | | |
1791 | | - | |
1792 | | - | |
| 1803 | + | |
| 1804 | + | |
| 1805 | + | |
| 1806 | + | |
| 1807 | + | |
| 1808 | + | |
| 1809 | + | |
| 1810 | + | |
| 1811 | + | |
1793 | 1812 | | |
1794 | 1813 | | |
1795 | 1814 | | |
| |||
1805 | 1824 | | |
1806 | 1825 | | |
1807 | 1826 | | |
1808 | | - | |
1809 | | - | |
| 1827 | + | |
| 1828 | + | |
1810 | 1829 | | |
1811 | 1830 | | |
1812 | 1831 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
616 | 616 | | |
617 | 617 | | |
618 | 618 | | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
619 | 658 | | |
620 | 659 | | |
621 | 660 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | | - | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
81 | 96 | | |
82 | 97 | | |
83 | 98 | | |
| |||
319 | 334 | | |
320 | 335 | | |
321 | 336 | | |
322 | | - | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
323 | 342 | | |
324 | 343 | | |
325 | | - | |
326 | | - | |
| 344 | + | |
327 | 345 | | |
328 | 346 | | |
329 | 347 | | |
330 | 348 | | |
331 | | - | |
| 349 | + | |
332 | 350 | | |
333 | 351 | | |
334 | 352 | | |
| |||
374 | 392 | | |
375 | 393 | | |
376 | 394 | | |
377 | | - | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
378 | 400 | | |
379 | 401 | | |
380 | 402 | | |
| |||
390 | 412 | | |
391 | 413 | | |
392 | 414 | | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
393 | 418 | | |
394 | 419 | | |
395 | 420 | | |
| |||
0 commit comments