Goals 8.4b: quarter, half and three-quarter milestones on the projection chart

Merged
JA
2mo ago
+221-6

Summary

8.4b of #127: milestones on every goal's projection chart. It follows the 8.4 triage plan. 8.4a (the retirement planner's milestones) is #255.

Before this PR, a goal's chart showed the saved line, a projection line to the target date and the target line, but not when the goal would be a quarter, half or three-quarters of the way there.

After it, the chart marks 25%, 50% and 75% of the target where the projection line crosses each one still ahead, labelled with the month it's reached at the current pace. For example: "25% · Dec 2026".

  • The dates come from the server, using the arithmetic the "on track" callout already uses: today plus the whole months the remaining amount takes at the current pace. So the callout and the markers can't disagree.
  • A milestone already saved past is reached, and isn't marked; the saved line already shows it.
  • Without a positive pace, no milestone ahead has a date, and nothing is marked.

Commits

CommitLayer
5ec75208Model: Goal#milestones(as_of:); Goal#projection_payload reads the clock once and hands that date to it. One locale string
4221207eUI: goal_projection_chart_controller.js draws the markers. Held for Phase C
fe42d04cModel: a milestone the pace reaches only after the target date is left undated (review follow-up)
6a980081UI: each dot is drawn in the month its label names (review follow-up)
649ef863Locales: the milestone label in every goal locale (review follow-up)
00d71cd3Model: the projection end value measured from the payload's own today (review follow-up)

5ec75208, fe42d04c and 00d71cd3 are the model layer; the rest are UI and locales. Merge with a merge commit.

Scope and dependencies

  • Issue: #127 (8.4b only)
  • Base: main. It doesn't depend on #250–#255.
  • Intentionally out of scope: markers for milestones already passed; goals with no target date, which have no projection line; custom percentages; tax (#254).

Blast radius

CallerChange
Goal#projection_payload: Goals::LifecyclePanelComponent and goal_test.rbOne new key, milestones. Every other key is unchanged, and today now comes from the same single clock read as the milestones
goal_projection_chart_controller.jsDraws the markers after the projection line, only when the pace is positive. data.milestones || [] keeps a payload without the key drawing as before
Goal#pace, #current_balance, #target_amountRead only

Following the value one hop further: the chart places each dot at the server's milestone date, on its own projection line at that date, so the dot, the line and the label agree.

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. The existing projection payload test still passes.
  • Any gate test has an observed failing mutation transcript attached. See Validation.
  • Fixtures used as evidence assert internal consistency. Each test builds its own goal on a fresh account and stubs the balance and pace it measures.
  • Financial calculations use BigDecimal and documented rounding points. Amounts are BigDecimal; dates round up to whole months.
  • De-identification uses token-shape allowlists; no personal data is included.
  • Files changed, decisions, tests/runtime, risks, and next unblocked issue are documented below.

Validation

Fail-first: against a stub, 4 of the first 5 model tests failed on their assertions. The zero-pace test passes against a stub by construction, and its mutation below is the evidence for it. The page test failed with KeyError: key not found: "milestones" before the model change.

Hand-computed figures (target 1,000; 400 saved; as_of 2026-03-15):

CaseFigures
Pace 5025% reached; 50% on 2026-05-15 (100 ÷ 50 = 2 months); 75% on 2026-10-15 (350 ÷ 50 = 7)
Pace 60 (part months round up)50% on 2026-05-15 (1.67 → 2); 75% on 2026-09-15 (5.83 → 6); label "50% · May 2026"
Exactly on the threshold500 saved has reached 50%

Mutations, each caught (8): > for ≥; floor for ceil; the pace guard dropped; reached milestones dated too; the payload reading its own clock for the milestones (caught by a clock that moves on every read); the target guard dropped; a wrong percentage; the label dropped.

Commands:

  • test/models/goal_test.rb, test/controllers/goals_controller_test.rb and the component tests: 308 runs, 0 failures.
  • Full bin/rails test: 10,653 runs, 46,678 assertions, 4 failures, 3 errors, 33 skips. All 7 are the known local Ruby 3.3.6 environment failures: ActiveStorage variants, the admin profile picture, OpenAI extra_headers, the Registry anthropic ENV test, and HostingsController anthropic ×3.
  • bin/rubocop on the changed Ruby files: clean. bin/brakeman: no warnings. biome lint (what CI's lint_js runs) on the controller: clean.
  • The JavaScript is not covered by CI, which runs no JS tests. It was checked in a real browser (Chromium, through Playwright) against a goal of 10,000 with 1,500 saved at 450 a month. The page drew three markers on the projection line, labelled 25% · Dec 2026, 50% · May 2027 and 75% · Nov 2027, each matching the whole-month arithmetic from 2026-09-28. Labels are hidden below 320px of chart width, like the chart's other labels.

Checked against upstream AGENTS.md:

  • Logic lives in the model; the chart only positions and draws.
  • The chart's colours follow its existing pattern (the projection line's own colour and the container background), and every string goes through t().
  • No migration or new dependency; Minitest and fixtures with Mocha. The goals page is already preview-gated.

Risks, blockers, and follow-up

  • The JavaScript has no automated test in CI (see above). The payload it reads is tested in Minitest.
  • Next: #127 closes when 8.1–8.4 merge.

Review follow-up

FindingSourceHandling
The dot and its label could sit in different monthsProduction Readiness ReviewFixed in 6a980081: the dot is drawn at the milestone's own date, on the line. Browser-checked: the dots sit on the line in the months their labels name
A slow pace could date a milestone decades past the chartPRRFixed in fe42d04c: a milestone reached only after the target date has no date, and the chart skips undated ones. A milestone on the target date keeps it. Both tests failed first; a >= mutation is caught
The label only in en.ymlPRRFixed in 649ef863: added to all eleven other goal locales
The payload reads the clock twicePRRFixed for the payload in 00d71cd3: projection_end_amount takes the date and the payload passes its own today (its only caller). A test on a clock that moves on every read failed first (5,400 against 5,301.45) and catches the mutation. months_remaining / monthly_target_amount still read the clock: they are memoised once per goal and shared by the status, card and callouts across the page, so threading a date through them is a wider change than this PR, and they agree with the rest of the page
No negative-pace testPRR test adequacyAdded in 00d71cd3: "a negative pace dates no milestone ahead"; dropping the positive? guard is caught

Goal model, controller and component tests after 00d71cd3: 312 runs, 0 failures. rubocop and biome clean.