Pin the 1,668.49 mid-period rate change on the fork engine
Summary
Part of #189, on the fork. Test only. #189 stays open as the tracker for the upstream port (see Review findings).
#189 asked for daily accrual so a mid-period rate change is charged at the right rate. On the fork that engine has been live since #25 (SCHEDULE_DAILY_ACCRUAL = true, Loan::InterestAccrual, Simulator#accrue_daily_period), and comment 5734326016 mapped each acceptance criterion to an existing test, except one: the issue's headline figure was never pinned by a named assertion. This adds it.
300,000 at 6% moving to 7% on the 15th of a 31-day month, actual/365:
14 days @ 6% = 300000 * 0.06 * 14 / 365 = 690.4110
17 days @ 7% = 300000 * 0.07 * 17 / 365 = 978.0822
= 1,668.4932 -> 1,668.49
Scope and dependencies
- Issue: #189
- Parent PR/branch, if stacked: none. Base
main. - Intentionally out of scope: the upstream proposal. The issue and its Gatekeeper review both recommend holding it until #184's reconciliation, and nothing here changes that. #189 stays open for it: this description says
Part of #189, notCloses.
Evidence checklist
- Each issue in this PR has its own acceptance criteria and no unrelated issue work is included.
- Contract rows touched by this change name existing tests.
- Any gate test has an observed failing mutation transcript attached.
- Fixtures used as evidence assert internal consistency.
- Financial calculations use
BigDecimaland documented rounding points. - De-identification uses token-shape allowlists; no personal data is included.
- Files changed, decisions, tests/runtime, risks, and next unblocked issue are documented below.
test/models/loan/mid_period_rate_change_test.rb:
- the engine charges a mid-period change from its effective date:
Loan::Simulatordirectly, 1,668.49; - a variable loan's schedule charges the split figure for that period: through
Loan#amortization_schedule, the path production runs, 1,668.49; - without the change the period is charged at the opening rate throughout: 1,528.77 (31/365 at 6%), so the split is the change's doing and not the fixture's.
This pins existing behaviour, so it can't fail first on main. Instead, the mutation:
SCHEDULE_DAILY_ACCRUAL = false
a variable loan's schedule charges the split figure ... Expected: 1668.49 Actual: 1750.0
without the change the period is charged at the opening... Expected: 1528.77 Actual: 1500.0
Validation
- The new file: 3 runs, 0 failures.
bin/rubocop: no offenses. - Checked against upstream
AGENTS.md.
Review findings
-
Gatekeeper light review (comment 6097494618, continued in 6097499172): DRAFT_ON_TRACK, risk LOW, no material findings. Its open item was the
Closeskeyword. Decided: #189 stays open, so this PR now saysPart of #189. The owner's own comment on #189 (5740049479, 2026-09-19) recommends keeping it open behind #184 until it becomes "port the fork's change-point accrual upstream", and this PR only pins the fork's figure. The upstream side is still open: #184 open question 2, proposing #405's interest hook upstream, is the route. -
"code master" review (comment 6106011219), hold, on
c758ab8: nothing to change in this PR. Each finding was checked against this head:- Rounding mode not checked: declined for this PR; one owner question outside it.
- The engine rounds with plain
round(n)(simulator.rb:133,interest_accrual.rb:17,amortization_math.rb:66), which is Ruby's ROUND_HALF_UP. - 1,668.493151 gives 1,668.49 under half-up, half-even, half-down, floor and truncate alike, so "1668.50 in some cases" is false for this figure.
- The wider gap is real, though: no contract row names a rounding mode. With both rounding sites switched to HALF_EVEN, only one golden-master scenario fails, and only because a half cent happens to land in it.
- A one-day accrual of exactly 1.825 (36,500 at 1.825%, actual/365) separates the modes: 1.83 under half-up, 1.82 under half-even.
- Decided (owner, 2026-10-11): not pinned now. HALF_UP stays Ruby's default rather than a contract rule until a lender statement (G2b) shows which mode the lender uses; C12 ties rounding to statement tolerance.
- The engine rounds with plain
- Per-segment vs once-only rounding not checked: covered elsewhere.
- Here they agree: 690.41 + 978.08 = 1,668.49 = round(1,668.4932).
- C12/C13's test "charge accumulates segments unrounded and rounds once at the end" (
interest_accrual_test.rb:149) is built so the two disagree. - C12's mutation fails 7
InterestAccrualTesttests, and this file passes under it, as it should.
- The lambda ignores its arguments, so period filtering isn't tested: covered elsewhere.
- The engine filters by period at
simulator.rb:205andrate_resolver.rb:33. - Deleting both filters leaves this file passing and fails 3
SimulatorTesttests (:291,:321,:394). - C10's mutation targets that line. This file's second test runs through
loan.amortization_schedule.
- The engine filters by period at
- Symbol vs string
day_count_convention: declined.normalize_day_count_conventioncallsto_sym, checks inclusion and raises on anything else (interest_accrual.rb:118-126, tested atinterest_accrual_test.rb:63);Loanvalidates inclusion too. :holdmay not match production: declined. The production schedule uses:reamortize(amortization_schedule.rb:291), which the second test runs. First-period interest is computed before the payment step (simulator.rb:104-141), so the strategy cannot move the pinned figure.- Depends on the
dylan_familyfixture: declined.CLAUDE.mdrequires fixtures, and six loan test files use this one, the golden master included. - Mutation transcript not verified: reproduced. With
SCHEDULE_DAILY_ACCRUAL = false, 1,668.49 becomes 1,750.00 and 1,528.77 becomes 1,500.00, as recorded above. - Boundary-case claim not verified: the tests exist and pass:
simulator_test.rb:275,:301and:331. - "Risks: None" is overconfident: not worth changing. The risks it lists are answered above.
- No test for a change outside the period: covered by the C10 tests, as in 3.
#405 rewrites this file onto upstream's simulator (1,500.00 without the interest hook, 1,668.49 with
Loan::DailyInterest); the figures are unchanged. - Rounding mode not checked: declined for this PR; one owner question outside it.
Review responses are recorded here rather than as comments, because comments posted from this session get an assistant footer appended, which this repository's attribution rule forbids.
Risks, blockers, and follow-up
None. The boundary case (a change exactly on a period boundary) is already pinned at test/models/loan/simulator_test.rb.