fix(insights,dashboard): rest-mode web banner, sleep per-chart assessments, steps explainer, recovery heading level

This commit is contained in:
Marc-André Bombeck committed 2026-06-16 23:20:41 +02:00
commit cdc76620fb
18 files changed
+249 -21

No files matched your search

+17 -3
View File
@@ -294,7 +294,14 @@ describe("buildDashboardSnapshot — per-type thick-phase gate", () => {
expect(snap.extras).not.toBeNull();
expect(snap.extras!.bpInTargetPct).toBe(80);
expect(snap.healthScore).toEqual({ score: 71, band: "yellow", delta: 3 });
// v1.18.1 — `restMode` is null when no illness episode is active (the
// fail-soft resolver reads no active episodes off the fake prisma).
expect(snap.healthScore).toEqual({
score: 71,
band: "yellow",
delta: 3,
restMode: null,
});
// v1.17 W1b — two runs (current + prior-week), identical to the analytics
// route, so the ring's delta reflects BP movement.
expect(computeBpInTargetFastPath).toHaveBeenCalledTimes(2);
@@ -426,8 +433,15 @@ describe("buildDashboardSnapshot — healthScore (warm phase only)", () => {
const snap = await buildDashboardSnapshot(fakePrisma, baseUser());
// Score + band + delta only — components never reach the wire.
expect(snap.healthScore).toEqual({ score: 72, band: "yellow", delta: -12 });
// Score + band + delta (+ the v1.18.1 value-free restMode annotation)
// only — components never reach the wire. `restMode` is null with no
// active illness episode.
expect(snap.healthScore).toEqual({
score: 72,
band: "yellow",
delta: -12,
restMode: null,
});
// The fast path reuses the BP windows + coverage map already
// computed for `extras` (no re-probe, graded score threaded).
+33 -1
View File
@@ -77,7 +77,11 @@ import {
type MedsTodayBlock,
} from "@/lib/dashboard/meds-today";
import { computeUserHealthScoreFastPath } from "@/lib/analytics/health-score-fast-path";
import type { HealthScoreBand } from "@/lib/analytics/health-score";
import type {
HealthScoreBand,
RestModeAnnotation,
} from "@/lib/analytics/health-score";
import { resolveRestMode } from "@/lib/illness/rest-mode";
import { resolveModuleMap, type ModuleKey } from "@/lib/modules/gate";
/** Briefing freshness window — mirrors the 24 h TTL on the advisor cache. */
@@ -270,6 +274,17 @@ export interface DashboardSnapshotHealthScore {
score: number;
band: HealthScoreBand;
delta: number | null;
/**
* v1.18.1 — Rest Mode annotation. When an illness/condition episode is
* active the dashboard frames the score ("you were unwell during this
* window") WITHOUT changing it — the same value-free context the
* `/api/analytics` payload carries and iOS mirrors. Null when the account
* is not in Rest Mode. Resolved server-side (fail-soft) so the surface
* never recomputes it. Optional on the type (additive contract) so older
* cached snapshots + test fixtures without the field stay valid; the live
* builder always sets it (null when not in Rest Mode).
*/
restMode?: RestModeAnnotation | null;
}
export interface DashboardSnapshot {
@@ -509,11 +524,28 @@ async function buildExtras(
coverage,
}),
);
// v1.18.1 — resolve the value-free Rest Mode annotation alongside the score
// so the dashboard hero can frame (never penalise) the number, matching the
// `/api/analytics` payload + iOS. Fail-soft inside `resolveRestMode`, and
// only resolved when a score actually rendered.
const restMode: RestModeAnnotation | null = scoreResult
? await (async () => {
const ctx = await resolveRestMode(user.id, now);
return ctx.active
? {
active: true,
since: ctx.since,
episodeCount: ctx.episodeCount,
}
: null;
})()
: null;
const healthScore: DashboardSnapshotHealthScore | null = scoreResult
? {
score: scoreResult.score,
band: scoreResult.band,
delta: scoreResult.delta,
restMode,
}
: null;
@@ -118,6 +118,11 @@ export type MetricStatusMetricId =
| "STAIR_ASCENT_SPEED"
| "STAIR_DESCENT_SPEED"
| "BREATHING_DISTURBANCES"
// v1.18.1 — nightly sleep-quality headline (WHOOP / Oura sleep score).
// Carries a generic assessment so the Sleep page reads one matching text
// per distinct chart group (duration/architecture AND quality), meeting
// the canonical "multiple charts ⇒ multiple texts" rule recovery meets.
| "SLEEP_SCORE"
// v1.18.1 — device-native recovery / strain signals (WHOOP / Polar /
// Oura). Each carries a generic assessment so the rebuilt
// `/insights/recovery` page reads one matching text per chart.
@@ -505,6 +510,20 @@ const REGISTRY: Record<MetricStatusMetricId, MetricStatusMeta> = {
direction: "lower-better",
archetype: "sleep",
},
// Sleep score — the nightly headline sleep-quality score (WHOOP sleep
// performance lineage / Oura sleep score), 0–100. Higher is the better
// night. No fixed clinical band: the scales differ by device and the
// user's own baseline carries the read; the assessment frames the trend.
// Sits on the dedicated sleep template so its prose matches the duration
// assessment's tone.
SLEEP_SCORE: {
id: "SLEEP_SCORE",
measurementType: "SLEEP_SCORE",
displayName: "Sleep score",
unit: "score",
direction: "higher-better",
archetype: "sleep",
},
// ── v1.18.1 device-native recovery / strain signals ──
// ANS charge — autonomic-nervous-system recharge (Polar Nightly
// Recharge / ring readiness lineage). Higher = better recovered. No