Skip to content

test(core): pin STRICT_WITH_SIZE's two tie rules - #2124

Merged
robcohen merged 2 commits into
mainfrom
chore/strict-with-size-tiebreak-coverage
Aug 24, 2026
Merged

robcohen merged 2 commits into
mainfrom
chore/strict-with-size-tiebreak-coverage

Conversation

@robcohen

Copy link
Copy Markdown
Member

Variant sweep from #2115 and #2122, looking for the same shape: an ordering whose secondary key nothing checks.

plan_strict_with_size is correct — no bug here

It uses min_by_key on (date_key, slot) ascending, never reverses a walk, and encodes None dates to sort last rather than relying on Option's natural order:

.map_or((1, NaiveDate::MAX), |d| (0, d)),
i,

That is the same house rule order_key follows — put the direction in the key, keep the tiebreak ascending. Reporting that as the result: the sibling defect I went looking for is not there.

Both tie rules were unpinned

The comment above that key states each as a promise, and nothing held it:

  • reversing the slot tiebreak to Reverse(i) left all 485 core tests passing, plus rustledger, rustledger-validate and rustledger-query
  • flipping the None encoding so date-less lots sort first did the same

strict_with_size_takes_the_oldest_of_several_exact_size_lots covers the primary date order from #2097 and stops there. Two size matches that share a date, and a date-less size match, both fell through.

Each new test kills exactly its mutant and nothing else fails. Both fixtures put the lot that must not win first, so insertion order alone cannot produce the expected answer — otherwise they would pass for the wrong reason.

Why it matters beyond determinism-for-its-own-sake

report capgains splits short from long on the surviving lot's acquisition date, and per-lot IRR keys eligibility off it. A reduction choosing arbitrarily between two same-date lots moves tax figures, silently — the postings still balance and no error is reported.

Tests only; no behavior change. Independent of #2119, #2120, #2121 and #2123.

🤖 Generated with Claude Code

https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr

Variant sweep from #2115 and #2122, looking for the same shape -- an
ordering whose secondary key nothing checks. `plan_strict_with_size` is
CORRECT: it uses `min_by_key` on `(date_key, slot)` ascending, never
reversing a walk, and encodes `None` dates to sort last rather than relying
on `Option`'s natural order. No bug here.

Both of those tie rules were unpinned, though, and its comment states each
as a promise:

  - reversing the slot tiebreak to `Reverse(i)` left all 485 core tests
    passing, plus `rustledger`, `rustledger-validate` and `rustledger-query`
  - flipping `map_or((1, NaiveDate::MAX), ..)` so `None` sorts FIRST did the
    same

`strict_with_size_takes_the_oldest_of_several_exact_size_lots` covers the
primary date order from #2097 and stops there.

Each test now kills exactly its mutant. Both fixtures put the lot that must
NOT win first, so insertion order alone cannot produce the expected answer.

Determinism here reaches the user: `report capgains` splits short from long
on the surviving lot's date and per-lot IRR keys eligibility off it, so an
arbitrary choice between two same-date lots moves tax figures.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
@robcohen
robcohen requested a review from a team as a code owner August 24, 2026 03:28
Copilot AI lite review requested due to automatic review settings August 24, 2026 03:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds regression tests for STRICT_WITH_SIZE lot-selection tie-breaking without changing production behavior.

Changes:

  • Covers same-date exact-size lot selection.
  • Verifies dated lots sort before date-less lots.
Suppressed comments (1)

crates/rustledger-core/src/inventory/booking.rs:1862

  • This test name reads as “date less one” rather than “date-less,” so the scenario is hard to understand/search for. Rename it to use an unambiguous term such as strict_with_size_prefers_a_dated_lot_over_an_undated_lot.
    fn strict_with_size_prefers_a_dated_lot_over_a_date_less_one() {

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@codecov

codecov Bot commented Aug 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@github-actions

github-actions Bot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Shape rustledger beancount Speedup RSS (rledger / beancount)
simple 49.3ms ± 4.1ms 857.8ms ± 1.0ms 17.4x 55.1 MB / 50.0 MB
investment 74.6ms ± 2.2ms 3249.5ms ± 59.1ms 43.6x 59.1 MB / 58.0 MB
fifo 70.7ms ± 3.8ms 16970.8ms ± 114.5ms 239.9x 61.0 MB / 57.9 MB

vs base, measured in this run

Shape base this PR Change RSS base → PR
simple 47.9ms ± 3.0ms 49.3ms ± 4.1ms +3.0% ✅ within noise 55.0 MB → 55.1 MB (+0.2%)
investment 73.7ms ± 1.5ms 74.6ms ± 2.2ms +1.2% ✅ within noise 58.9 MB → 59.1 MB (+0.3%)
fifo 71.3ms ± 3.4ms 70.7ms ± 3.8ms -0.8% ✅ within noise 60.9 MB → 61.0 MB (+0.1%)

A difference counts only when it clears the combined spread of the two measurements, per shape (2σ: simple 2.3ms, investment 1.2ms, fifo 2.3ms), and is at least 5%.
10,000 transactions per shape · 20 runs, 3 warmup · hyperfine

What do these numbers mean?
  • simple — Two-posting transfers, one currency. The historical workload — keep as the floor, not as the benchmark.
  • investment — Cost specs, per-unit prices and lot reductions. Exercises booking and inventory, which simple leaves at 0.3%.
  • fifo — Bare {} reductions against a FIFO account — how FIFO sells are normally written. The other four shapes reach the ordered-selection path twice in 2k transactions between them, so it was effectively unprofiled until it turned out to be quadratic (plan_ordered scans every lot per reduction: FIFO ledgers are quadratic (8.8s at 20k transactions) #2083).
  • vs base: the PR and the base-branch commit it is built on, built and measured in the same job
  • RSS: peak resident set size, a single sample — reported without a verdict because there is no spread to test it against
  • A shape with no beancount column is one bean-check reports errors on; it is timed for rledger only

@github-actions

Copy link
Copy Markdown
Contributor

✅ Compatibility Test Results

Metric Result
Check Compatibility 100%
BQL Compatibility 100% (raw 93%, 170 masked)
Full AST Match 100%
Total Files 811
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

"a_date_less_one" reads as "date less one" and does not match a search
for "undated". Renamed to `strict_with_size_prefers_a_dated_lot_over_an_undated_lot`, with the surrounding prose aligned.

Reported by Copilot on #2124.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
@robcohen

Copy link
Copy Markdown
Member Author

Good point on the name — taken in cdae37f. a_date_less_one reads as "date less one" and, more practically, does not match a search for "undated". Renamed to strict_with_size_prefers_a_dated_lot_over_an_undated_lot and aligned the surrounding prose so the doc comment and the assertion message use the same word.

@robcohen
robcohen merged commit 629d9c4 into main Aug 24, 2026
61 checks passed
@robcohen
robcohen deleted the chore/strict-with-size-tiebreak-coverage branch August 24, 2026 10:38
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.

2 participants