Let a delegate read the dashboard they land on

Ten routes on `/` refused with `undeclared_mode`, which made the first page
of account sharing the only page in it that does not work. Each one now
declares a mode, per route rather than as a class.

Eight are record reads: the dashboard snapshot, the Today digest, the badge
grid, the Coach nudge signal and reminder ledger, the medication low-stock
thresholds, and the two presentation blobs. The old objection to admitting an
aggregate — a summary can carry a finding from a module the grant does not
cover — does not hold while a grant is whole-record and all-or-nothing. Every
admission site names that, so the day per-module scope lands the aggregates
are findable.

The layout routes split their verbs. Reading the owner's arrangement is right
and, for the dashboard, forced: the snapshot already carries the layout and
the client seeds the same cache cell from it, so an actor answer would put two
people's layouts in one key. Writing it is not a caregiver's job, so the PUT
and DELETE stay bare and refuse. Same on the medication list, where the stored
order names the owner's medication ids and means nothing anywhere else.

Two are actor surfaces: the UI language belongs to the person reading the
screen and must not be transplanted onto the record, and the feature-flag
matrix reads the settings singleton and no user row at all.

Also fixes a second instance of the delegate-data-under-owner-banner defect,
on the same page: the dashboard's client-side band fallback derived blood-
pressure targets and the weight range from `/api/auth/me`, which answers about
the caller, and painted them over the record's charts. Under a switch it now
derives nothing and waits for the snapshot's own bands.

The integration suite drives every admitted route with both accounts seeded,
proves the two answers differ, and then demands the owner's back.
This commit is contained in:
Marc-André Bombeck committed 2026-08-03 21:12:35 +02:00
1 parent a0fc404fb8
commit 508cc8a60a
17 files changed
+1025 -49

No files matched your search

@@ -9,12 +9,17 @@
* - `getSession()` answers who is CALLING and deliberately never the record
* being acted on (`src/lib/auth/session.ts`), so the RSC read the
* delegate's own rows;
* - a NON-delegable route (`/api/dashboard/snapshot`, `/api/daily/digest`,
* `/api/dashboard/widgets`) refuses the refetch outright, so the seeded
* value is what stays on screen — under a banner naming somebody else;
* - a DELEGABLE route (`/api/measurements/series-batch`, `/api/medications`)
* answers with the owner's rows, so the same page paints two people at
* once until the refetch lands.
* - a NON-delegable route (`/api/user/thresholds`, `/api/mood/analytics`)
* refuses the refetch outright, so the seeded value is what stays on
* screen — under a banner naming somebody else;
* - a DELEGABLE route (`/api/dashboard/snapshot`, `/api/daily/digest`,
* `/api/dashboard/widgets`, `/api/measurements/series-batch`,
* `/api/medications`) answers with the owner's rows, so the same page
* paints two people at once until the refetch lands.
*
* The front-door reads moved from the first bullet to the second when `/` was
* made usable under a switch. That changed which ending a bad prefetch has,
* not whether it is one.
*
* These tests assert what reaches the cache, not which branch ran. Each one
* reads the dehydrated queries off the returned `<HydrationBoundary>` and