Files
KomediruzeckiandGitHub b58c662a84 fix(retirement): saving a default was indistinguishable from not saving (#411)
* fix(retirement): saving a default was indistinguishable from not saving

Derivation decided "the user has not set this" by comparing the stored value to
the default. Every default is also a perfectly ordinary answer, so anyone who
saved one had it quietly overwritten on the next load. Reported as a monthly
contribution of exactly 500 reverting to a derived 7.29 after a profile switch;
the same hole swallowed a net worth of 0, an income or spending of 0, and a
retirement spend of 2000.

The fix is to stop inferring it. deriveSettings now takes the stored row rather
than a normalised object and asks which keys are present, because normalising
invents a default for every absent key and destroys exactly the distinction the
function turns on. Both loaders return raw rows to match. A key counts as set
when it is present and not null: null is how the client says "no value" for an
optional field such as birthMonth, so it keeps meaning that, while 0 and 500 are
now treated as the answers they are.

Both PUT handlers re-derive and return the provenance with the settings. Saving
is precisely what stops a field being derived, so a client that only took
`settings` back went on crediting "filled in from your data" for figures the
user had just typed.

Field hints move into info tips
------------------------------
The explanations under the controls were block text, so a field that had one was
taller than the field beside it and its control sat out of line — visible as the
date-of-birth picker floating above the net worth box. They are now revealed
from a circled-i beside the label, painted over the page and costing no layout.

The old InfoTip leaned on the native `title` attribute, which is hover-only: on
a phone every explanation in the app was unreachable. The rewrite opens on
hover, on focus, and on tap, pins on click, closes on Escape, outside press or
blur, and follows its icon when the page scrolls. Writing the tests turned up
that Escape closed the panel and the focus it returned reopened it, so Escape
appeared to do nothing.

Withdrawal rate
---------------
The most misread control on the page: a higher rate reads as "more money", when
the spending never changes and only the pot you call sufficient does. It is now
a slider — the number is a trade-off, and dragging it moves the chart and the
runway together — with the number box kept for exact entry, and a tip that says
what the percentage is a percentage of.

A chip under the lifestyle cards turns the rate into the answer people actually
want: retired for as long as you like, or for about eleven years, to around age
46. The cards say when you can stop; nothing said how long stopping then lasts.

Chart markers
-------------
A dashed line at the month each lifestyle becomes affordable, labelled with a
pill in that lifestyle's own colour, on by default. The crossing was in the
cards and the target was on the chart, but nothing showed where the two met.
Drawn as a Chart.js plugin so it redraws with the chart and clips to the plot
area; pills stack when they would overlap and long names are cut with an
ellipsis.

Tests
-----
Every derivable field from both sides, a saved plan stable across reloads, the
save response clearing the provenance, and the round trip at the route level in
the Worker. Mutation-checked: restoring the old sentinel for netWorth, income,
spending, contribution or lifestyles fails a test each. birthMonth is the one
where the two rules genuinely coincide, since null is both its sentinel and its
unset marker.

The layout defect gets a measured guard rather than an eyeball: no field may
carry text below its control, checked across every field in the form, so the
next hint someone adds inline is caught wherever it lands.

InfoTip, RangeField and the marker plugin are at 100% of lines and functions.

* fix(retirement): every profile in browser mode shared one saved plan

Reviewing the branch turned up the third runtime. The settings store in
IndexedDB is keyed by `key` alone — it has no profile column — and the
assumptions were saved under a bare 'retirement_settings'. So one plan served
every profile in the browser: opening a second profile showed the first one's
figures, and saving there overwrote them. Both server runtimes have always
separated profiles through the settings table's (key, profile_id) primary key,
so this was browser mode alone, which is where the demo account runs.

The profile now goes in the key, since the store has nowhere else to put it. A
plan saved under the old bare key is adopted by whichever profile opens the page
first and the old row is removed — leaving it would hand the same plan to every
profile that has not saved one yet, which is the behaviour being fixed.

Eight tests, driven through the local API router against real idb: two profiles
never see each other's plan, a row per profile rather than one overwritten, the
legacy row adopted exactly once, a saved default surviving the round trip, JSON
text as a server backup restores it, an unparseable blob falling back to
defaults, and the projection endpoint scoped too. Reverting the key to its bare
form fails six of them.

Chart options wear the app's switch
-----------------------------------
Three native checkboxes above the chart, in a page that has a branded switch
everywhere else. Toggle grows a compact size for rows of switches that annotate
something rather than being the subject, and an optional label rendered inside
the button — so clicking the words flips it and the text names the control for a
screen reader, which a <label> wrapped round a <button> would not do. The pill
moved into its own span; with no label the wrapper shrinks to the pill and the
control is the same 44x26 box it has always been, which the tests hold.

The info tip's accent hairline spans a panel with rounded corners, so it ran
straight past where the corner curves away and overhung the edge. The panel
clips it.

Also from the review
--------------------
- The legacy backend keys these per profile while the Worker keys on the plain
  name; that reads as an accident but is not. Its settings repository looks rows
  up by key alone with no profile filter, so a shared key there would hand back
  whichever profile's row came first. Said so, at the key.
- Both PUT handlers re-derive and hand back `filled` and `missing`. What is
  stored is the normalised object, so `filled` is empty by construction — but
  `missing` reports what the data cannot answer at all, which a save does not
  change, so the extra read earns its place. The comments now say which is which
  rather than implying both are computed.
- `.field-warn` lost its last user when the withdrawal-rate hint became a chip.
  Deleted.
- Said which lifestyle the runway chip counts from. It is the first, the one the
  cards mark primary, and a single chip has to pick one.

Two more e2e guards on what was reported: the tip panel clips its accent and
stays on screen, and the chart options are switches with markers on by default
whose label text flips them.
2026-08-23 13:33:39 +02:00
..