Give the demo loans real terms and schedule-driven payments
Summary
Closes #408.
A fresh install with demo data had three loans (Home Mortgage, Car Loan, Student Loan) created as bare Loan.new: no rate, term, rate type or start date. None was amortizable, so the demo showed none of the loan pages. On top of that:
- the mortgage was paid twice a month, on two unrelated sets of figures;
- its 320,000 arrived as a "Mortgage Principal" transaction rather than an opening valuation.
This ports upstream's fix (we-promise/sure#3327's demo half, plus we-promise/sure#3933's reload) from mirror/upstream-main. No adaptation was needed: every attribute and method it uses exists on #405's branch. app/models/demo/generator.rb is upstream's file except for one fork-side hunk: the "Long-term portfolio" demo goal's target, raised to 300,000 in a07186cf8 (see Risks).
| Loan | Terms |
|---|---|
| Home Mortgage | adjustable, 6.25%, 360 months from 5 years ago, 320,000; 70,000 down; level-term insurance at 0.36; rate changes to 5.5% at month 24 and 6.75% at month 48 |
| Car Loan | fixed, 6.9%, 60 months from 37 months ago, 24,000; 4,000 down; decreasing-life insurance at 0.5 |
| Student Loan | fixed, 5.5%, 120 months, 42,000; one 2,000 extra payment a year ago, so it is ahead of schedule for a real reason |
- Opening valuations.
open_demo_loan!gives each loan an opening-anchor valuation for its principal on its start date. - Payments from the schedule.
generate_loan_payments!pays each loan's own schedule (principal and interest per payment) up to today. - What goes:
- the housing step's flat mortgage lines (2,800 from checking plus 800 principal a month);
generate_loan_payments!'s flat 600/1,100;- the "Mortgage Principal" transaction.
- Also from upstream, beyond the issue's list:
- The previous car's flat 385 "Auto Loan Payment" stops the day before the car loan starts, so the car isn't paid twice.
- Mortgage interest is filed under Rent/Mortgage, so that category stays in use: 60 transactions, up from 36.
Scope and dependencies
-
Issue: #408
-
Parent PR/branch, if stacked: #405 (
claude/loans-184-engine-swap). The issue names both #402 and #405 as dependencies; #405's base already carries #402's columns:- The payment loop reads
Payment#principalandPayment#interest, which exist only after #405's engine swap. down_paymentand the insurance columns come from #402.
Merge after #405, then retarget to
main. - The payment loop reads
-
Intentionally out of scope:
- every other demo account, the generator's counts, and every goal target but "Long-term portfolio";
- any loan model or engine change;
- #404's
docker-verifyloan checks still create their own loan. Switching them to read a demo loan is possible now, but it is a separate change.
-
Merged into #404 at
455385584, cleanly; demo tests on that merge give 28 runs, 0 failures. #404'sdocker-verify / build-and-runpassed at that head (run 38074559092):demo_data:defaultcompletes with this generator inside the built image. -
Refreshed 2026-10-11. This branch merges #405's new head
22e65fb03asafe0afd37. The merge was clean, and nothing in this PR's two files changed. #405's head carries the reviewed fixes from #393, #394, #397–#401 and #403, through its base.- #404 merges
afe0afd37as8cf45291f, anda07186cf8(the goal target) asbb0a101b8. - #404's
docker-verify / build-and-runpassed atbb0a101b8(run 38142384473), sodemo_data:defaultcompletes with the new target inside the built image.
- #404 merges
-
Refreshed again 2026-10-12. This branch merges #405's new head
24746641dasf35c392be. The merge was clean, and this PR's two files are unchanged.- #405 brought in three nightly-review fixes from the integration base: #397's and #398's day-count rollbacks now refuse rather than rewrite loans, and #400's parser refuses "Rate change 0.25%"-style wording.
- Migration, parser, rule-action and loan tests on
f35c392be: 156 runs, 0 failures. - #404 merges
f35c392bein6836ad49d. Its full suite gives 12,671 runs, 1 failure (the knownProvider::OpenaiTeststring), and the contract gate catches all 18 mutations. - CI on
f35c392be: all checks green.
-
Refreshed a third time 2026-10-12. This branch merges #405 at
185130824(934b26563) and then ata344aaa25(95ff79e4c). Both merges were clean, and this PR's two files are unchanged. They bring:- #394's softened minimum-payment caption: "The next repayment your loan's schedule sets, ...", no longer "your lender's minimum";
- the payoff projection's offset fix, on #405's engine and #403's: it reads the offsets once per projection, not once per period, taking a 360-month loan page with two offsets from 1.74 s to 0.56 s.
#404 merges
95ff79e4cind838e0336. Its full suite gives 12,673 runs, 1 failure (the knownProvider::OpenaiTeststring), and the contract gate catches all 18 mutations. -
Refreshed a fourth time 2026-10-13. This branch merges #405 at
fc3ea844fas78d6eb228. The merge was clean, and this PR's two files are unchanged. It brings:- #400's parser fixes: movement wording is refused unless a marker names the new rate, and "your rate is X%" is read as the new rate;
- #400's and #402's added tests.
Full
bin/rails teston78d6eb228: 12,651 runs, 0 failures, 0 errors, 33 skips. #404 merges78d6eb228in16f59b96d.
Blast radius: who consumes demo data, and what changes for them
-
Who runs the generator:
demo_data:defaultandgenerate_new_user_data_for!;DemoFamilyRefreshJob(app/jobs/demo_family_refresh_job.rb:43) andFamilyResetJob(:12).
The two un-skipped tests cover both transaction paths.
-
Demo::FinancekitGeneratorfunds from checking, but it doesn't read checking's balance (app/models/demo/financekit_generator.rb:170-183). -
Checking ends about 53.6k higher (151,858 → 205,486 in a seed-42 run), because the 2,800-a-month mortgage line is gone. The goal target change below is its one visible effect.
-
The generator's own end-of-run checks still pass: 8,555 entries (8k–12k required) and 87.9% categorised (75% or more required; it was 88.1%).
Future upstream syncs. I found no automation that treats generator.rb as fork-side:
bin/upstream-sync:23stops on any conflict..github/workflows/upstream-sync-reminder.ymlsays conflicts are resolved by hand.- The "fork-side" choice exists only in sync merge messages:
798002ee8listedgenerator.rband its test under "Resolved to the fork's side", and959bf6f3edid the same for #3933's reload.
Decision: from now on, take upstream's side for generator.rb, except the "Long-term portfolio" target hunk: keep the fork's 300,000 until upstream moves its own. An upstream-only change elsewhere in the file merges with no conflict. For generator_test.rb, take upstream's hunks and keep the fork-only block, which sits just before private, and the fork-only seed_long_term_portfolio helper just after it.
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. (No contract row changed.)
- Any gate test has an observed failing mutation transcript attached. (Not a gate; mutations below anyway.)
- Fixtures used as evidence assert internal consistency. (No fixtures changed.)
- Financial calculations use
BigDecimaland documented rounding points. (Upstream's amounts come from the schedule'sMoneyvalues.) - De-identification uses token-shape allowlists; no personal data is included. (Demo data only.)
- Files changed, decisions, tests/runtime, risks, and next unblocked issue are documented below.
Tests (test/models/demo/generator_test.rb)
- Un-skipped: the two tests the fork had skipped because demo loans "carry no terms and pay flat figures".
- Ported verbatim from upstream:
- "demo loans carry the terms and principal a schedule is built from"
- "demo loans owe what their own schedules say, the student loan ahead by its extra payment"
- "demo loans project payoffs that match their balances"
- Fork-only:
- "demo loans carry the terms the issue specifies". Upstream's tests can't see a dropped rate change, since the schedule then agrees with itself.
- "the mortgage is paid once per scheduled date, by its schedule alone". It measures the housing step's delta on the mortgage, not presence.
- "the previous car's flat payments stop before the demo car loan starts"
- "every demo loan has an applicable payoff projection"
- "the long-term portfolio goal reads on track at the demo's highest checking balance" and "... lowest checking balance" (
a07186cf8). Each seeds the goal matrix with the goal holding an exact balance (pinned by a precondition) and a 7,000-a-month 90-day pace, and asserts:on_track.
Fail first, on the unchanged generator:
- the un-skipped tests and "owe what their own schedules say":
NoMethodError: undefined method 'payments' for nil(no schedule); - "carry the terms and principal": "the demo mortgage should be adjustable";
- "project payoffs": the projection must clear the balance;
- "the terms the issue specifies": all nine terms nil;
- "paid once per scheduled date": the housing step added 36 mortgage entries;
- "applicable payoff projection": no projection;
- "reads on track at the demo's highest checking balance", at the 200,000 target:
:reached.
"The previous car's flat payments" failed only on its guard (the old car loan had no start_date); mutation M6 shows it failing for the right reason. "Reads on track at the demo's lowest checking balance" passes at 200,000 by design: it guards the other side, a target set so high the goal falls behind (M14).
Mutations, each run against the whole file, with the file restored and compared with cmp afterwards:
| Mutation | Caught by |
|---|---|
| M1 drop the extra payment | owe-schedules; project-payoffs |
| M2 pay each schedule payment twice | 6 tests, including paid-once and both un-skipped |
| M3 put back the housing 2,800/800 lines | paid-once; owe-schedules; project-payoffs |
| M4 drop the mortgage's opening valuation | owe-schedules; applicable; paid-once; project-payoffs |
| M5 drop the 6.75% rate change | terms-the-issue-specifies only (why it was added) |
| M6 put back the old car payment's end date | previous-car |
| M7 put back the "Mortgage Principal" transaction | paid-once |
| M8 book a flat 100 interest | owe-schedules |
M9 drop .reload | both un-skipped tests |
| M10 make the mortgage fixed | carry-terms; terms-the-issue-specifies |
| M11 pay past today | 6 tests |
| M12 down payment 60,000 with the deposit left at 70,000 | carry-terms; terms-the-issue-specifies |
| M13 goal target 200,000 or 210,000 | on-track at the highest balance (:reached) |
| M14 goal target 600,000 | on-track at the lowest balance (:behind) |
Targets of 220,000, 400,000 and 500,000 pass both goal tests; 300,000 sits inside that range with room on both sides.
Demo run (generate_default_data!, seed 42, scratch database, before and after):
| Before | After | |
|---|---|---|
| Home Mortgage balance / schedule balance today | 269,000 / no schedule | 297,813.13 / 297,813.13 |
| Car Loan | no schedule | 10,186.50 / 10,186.50 |
| Student Loan | no schedule | 29,409.08, schedule 31,409.08 (2,000 ahead, 6 months saved) |
Payoff projections applicable? | false for all three | true for all three, all converging |
Demo goal, full runs across seeds ("Long-term portfolio", 60 months out):
| Seed | Goal balance | 90-day pace / month | At 200,000 | At 300,000 (needs / month) |
|---|---|---|---|---|
| 42 | 200,653.93 | 7,056.60 | reached | on track (1,632.20) |
| 1 | 212,392.01 | 9,081.58 | reached | on track (1,439.35) |
| 7 | 165,872.45 | 11,318.84 | on track | on track (2,203.63) |
| 2024 | 184,191.97 | 14,721.98 | on track | on track (1,902.66) |
On every seed and both targets the other eight goals keep their designed states:
- Vacation in Italy: behind;
- Wedding fund: reached;
- Emergency fund: no target date;
- House downpayment: behind;
- Tax prep buffer: on track;
- Sabbatical: paused;
- Old laptop fund: archived;
- Paid-off car: completed.
Validation
- CI on
95ff79e4c: all 7 checks green, on the first attempt. - CI on
f35c392be: all checks green. - CI on
a07186cf8: all 8 checks green, includingci / test_unit,ci / test_systemon its first attempt,github-advanced-securityand Codacy ("Up to standards"). - CI on
afe0afd37: all 8 checks green, the same set. - Local, on
a07186cf8:- full
bin/rails test: 12,629 runs, 53,735 assertions, 1 failure, 0 errors, 33 skips. The failure is the known local-onlyProvider::OpenaiTest#test_extra_headers_stringifies_nested_values_Ruby-style(Ruby 3.3 here; CI pins 3.4); - demo suite: 30 runs, 0 failures;
bin/rubocopon both files: no offenses.bin/brakeman --no-pager -q: 0 warnings.
- full
- Local full suite on
afe0afd37: 12,627 runs, 1 failure (the sameProvider::OpenaiTest). - CI on
a6adefc3a(the earlier head): all checks green.- The first attempt of
ci / test_systemhad one failure in 220 runs:PropertiesEditTest#test_can_persist_property_subtype("expected to find fieldaccount_accountable_attributes_subtypethat is not disabled but there were no matches"). - That test opens a property account's edit dialog. Nothing in this PR reaches it, and its own comments describe the Turbo morph-refresh race it retries around.
- A single re-run of the failed job passed. No code changed.
- The first attempt of
- Full
bin/rails testona6adefc3a: 12,608 runs, 53,671 assertions, 1 failure (the sameProvider::OpenaiTest), 0 errors, 33 skips. - Loans, components and the loans controller: 679 runs green.
- erb_lint, Biome: not applicable.
bin/rails demo_data:defaultwas not run locally.generate_default_data!was called directly, so the task's summary block didn't print; its figures were computed separately (above).- #404's container check runs the task itself, and it passed at
bb0a101b8, which carries this head.
docs/llm-guides/goals.mddescribes the goal matrix without figures, so it needs no change.- Checked against upstream
AGENTS.md. The loan half converges a fork file on upstream's copy. The goal target is a fork-side divergence; upstream's demo has the same "reached" state, so the same change could be proposed there.
Review findings
-
"code master" review (comment 6106127138), mergeable-after-fixes, on
a6adefc: nothing to change.- At that head,
app/models/demo/generator.rbwas upstream's file exactly: objectd11f562b6both here and onorigin/mirror/upstream-main(94e71a8c2), with an empty diff. - So every finding is about upstream's code, and a fork-only fix would re-diverge it. Each was still checked on its merits;
generator_test.rbandamortization_schedule_test.rbgive 73 runs, 0 failures.
- Loans never paid if
paymentscame back newest first: declined. The schedule is oldest first by construction: the dates come from(1..term_months).map { |n| start_date >> n }(amortization_schedule.rb:136), and#paymentsis documented "oldest first" (:76). Reversing the loop on purpose fails 5 of the 14 demo tests, so it couldn't go unnoticed. - About 900 writes, so a web request could time out: declined.
- It is 134 payments (60 on the mortgage, 37 each on the car and student loans), not about 300. That is about 405 entries, against about 406 before this PR.
- Every web caller queues
FamilyResetJob.perform_later(users_controller.rb:56,61,api/v1/users_controller.rb:11); otherwise the generator runs only in jobs and rake tasks.
- The extra student-loan payment is a transfer, not a loan payment: declined.
make_loan_payment!books every scheduled payment's principal through the samecreate_transfer!(generator.rb:1111-1117). The extra payment is all principal, so it looks exactly like that part of every other payment. - Mortgage interest moved to Rent/Mortgage, undocumented: already recorded above ("Mortgage interest is filed under Rent/Mortgage, so that category stays in use"). Rent/Mortgage sits under Housing (
generator.rb:239), so Housing totals still include it. Demo data is regenerated, not upgraded. - No guard if
amortization_schedulereturns nil: declined. The generator gives all three loans full terms just before paying them, and "demo loans carry the terms the issue specifies" pins them. A guard would bring back finding 1's silent no-op; failing loudly inside the generation transaction is right.
- At that head,
-
Nightly review (comment 6120444214), READY WITH CONDITIONS, on
a07186cf8: no blocking findings.-
MEDIUM, sequencing: agreed. It is already the plan ("Stacked on #405", under Risks):
- merge #405 and its dependencies;
- retarget this PR to
main; - run the generator and loan tests at the resulting head before this PR merges.
The retarget leaves this PR's two files as they are, but it changes the base under them. So the green runs on #405's branch are not taken as evidence for
main. The closest check available today is #404, which carries this head together with #405 and the rest of the stack. Its full suite passed atd838e0336, which carries95ff79e4c.
-
-
Nightly review (comment 6134299716), READY WITH CONDITIONS, on
3848dd0f0. No blocking findings. MEDIUM, renew the evidence on the final base: agreed, and it is already the plan. Once #405 and its prerequisites merge, this PR is retargeted tomain, and the generator and loan suites run again at that head. Nothing to change now.
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
- The demo goal: fixed fork-side in
a07186cf8, at the owner's request (2026-10-11: "Fix the demo goal target fork-side in #415").- With checking higher, "Long-term portfolio" read reached instead of its designed on track on two of four seeds, seed 42 included.
docs/llm-guides/goals.md:337-339says goal targets must move when demo balances change. The target is now 300,000; the measurements are under Evidence.- Upstream's
generate_goals!is identical, so upstream's demo shows the same effect. Proposing the same change there is optional, and is left to you.
- The car loan's 4,000
down_paymentdoesn't match the existing "Car Down Payment" transaction (3,000, six years ago, for the previous car). Upstream only checks the mortgage deposit against its down payment, so I left it alone. - Stacked on #405. It retargets to
mainonce #405 merges, then the generator and loan tests run again at that head (nightly review above). - No Issue Gatekeeper review before building: your "Build #406, 408 and 409" is the override I acted on.
- Next unblocked issue: none.