chore(release): v1.28.21 — sleep history heals itself; plateau context; sync diagnostics

A one-time background pass re-reads each connected account's Google Health
sleep history so nights stored twice before the sleep fix collapse to their
true total (new sleep_repaired_at marker, migration 0238; watermark-safe,
enqueued once at boot per un-repaired connection).

The sleep night read reports when two writers disagree about the same night —
the served total is unchanged, the disagreement rides along as an annotation
(sourceDiscrepancy on the night DTO) so clients can mark the number instead of
silently picking a side.

A GLP-1 medication whose weight has plateaued on the current dose says so next
to the estimated drug level (efficacy tab + insights) — a factual note from the
existing detector, association only, verb-guard covered.

Google Health diagnostics: the sync log now separates a daily-totals read that
returned nothing from one the importer could not parse
(googleHealth.rollup.emptyResponse vs droppedAll), and the connection test's
structure probe reports the raw response envelope key names when a rollup type
parses to zero — a per-account naming drift becomes visible from one report.
This commit is contained in:
Marc-André Bombeck committed 2026-07-10 21:23:00 +02:00
1 parent 49be6851ec
commit 1212ed91d5
34 files changed
+1256 -7

No files matched your search

@@ -164,3 +164,29 @@ describe("<SleepHypnogram> — timeline bar visibility", () => {
expect(html).toContain('data-slot="sleep-hypnogram-breakdown"');
});
});
describe("<SleepHypnogram> — source discrepancy marker", () => {
const discrepancy = {
deltaMinutes: 160,
sources: [
{ source: "WITHINGS", deviceType: null, asleepMinutes: 615 },
{ source: "GOOGLE_HEALTH", deviceType: null, asleepMinutes: 455 },
],
};
it("renders the discreet marker when the server flags disagreeing sources", () => {
const html = render({ ...baseSession, sourceDiscrepancy: discrepancy });
expect(html).toContain('data-slot="sleep-source-discrepancy"');
// Muted marker, no colour wash — the trigger stays on the muted tier.
expect(html).toContain("Sources disagree");
});
it("omits the marker when the night carries no discrepancy", () => {
expect(render(baseSession)).not.toContain(
'data-slot="sleep-source-discrepancy"',
);
expect(render({ ...baseSession, sourceDiscrepancy: null })).not.toContain(
'data-slot="sleep-source-discrepancy"',
);
});
});
@@ -0,0 +1,76 @@
"use client";
/**
* v1.28.21 — compact GLP-1 weight-plateau note.
*
* Renders the existing server-side plateau detection (`detectGlp1Plateau`,
* until now prompt-only) as a discreet card on both GLP-1 curve surfaces:
* the medication detail "Wirkung" tab (below the estimated
* active-substance curve) and /insights/medications (below the same curve
* block). Reads `GET /api/insights/glp1-plateau`; when the detector
* returns `null` (no active GLP-1 medication, < 21 days on the current
* dose, weight still dropping, or too few readings) the card renders
* nothing.
*
* Association only, matching the efficacy-tab posture: the copy is a
* title + one evidence line (Δ kg over the window, reading count, days on
* the current dose) — no verdict, no advice, no dose suggestion. The
* strings live under `medications.efficacy.plateau.*` so the banned-verb
* guard (`medications-efficacy-verb-guard.test.ts`) covers them
* structurally.
*/
import { Scale } from "lucide-react";
import { useQuery } from "@tanstack/react-query";
import { Card, CardContent, CardHeader } from "@/components/ui/card";
import { TileHeader } from "@/components/insights/tile-header";
import { queryKeys } from "@/lib/query-keys";
import { apiGet } from "@/lib/api/api-fetch";
import { useTranslations } from "@/lib/i18n/context";
import type { Glp1PlateauContext } from "@/lib/insights/glp1-plateau";
interface Glp1PlateauResponse {
plateau: Glp1PlateauContext | null;
windowDays: number;
}
export function Glp1PlateauNote() {
const { t } = useTranslations();
const { data } = useQuery({
queryKey: queryKeys.insightsGlp1Plateau(),
queryFn: () => apiGet<Glp1PlateauResponse>("/api/insights/glp1-plateau"),
staleTime: 60_000,
});
if (!data?.plateau) return null;
const plateau = data.plateau;
const delta =
plateau.weightDeltaKg > 0
? `+${plateau.weightDeltaKg}`
: `${plateau.weightDeltaKg}`;
const dose = `${plateau.drug} ${plateau.doseValue} ${plateau.doseUnit}`;
return (
<Card className="gap-2 py-3 md:py-4" data-slot="glp1-plateau-note">
<CardHeader>
<TileHeader
size="sm"
icon={Scale}
title={t("medications.efficacy.plateau.title")}
/>
</CardHeader>
<CardContent>
<p className="text-muted-foreground text-sm">
{t("medications.efficacy.plateau.evidence", {
delta,
window: data.windowDays,
readings: plateau.readingsCount,
days: plateau.daysOnDose,
dose,
})}
</p>
</CardContent>
</Card>
);
}
@@ -22,6 +22,7 @@ import dynamic from "next/dynamic";
import { useQuery } from "@tanstack/react-query";
import { ChartSkeleton } from "@/components/charts/chart-skeleton";
import { Glp1PlateauNote } from "@/components/insights/glp1-plateau-note";
import { queryKeys } from "@/lib/query-keys";
import { apiGet } from "@/lib/api/api-fetch";
@@ -80,6 +81,10 @@ export function Glp1SubstanceCurveSummary({
/>
</div>
))}
{/* v1.28.21 — weight-plateau note (association only), below the
curve(s). Self-gating: renders nothing unless the server-side
detector reports a plateau on the current dose. */}
<Glp1PlateauNote />
</div>
);
}
+119 -1
View File
@@ -10,7 +10,15 @@ import {
YAxis,
} from "recharts";
import { TriangleAlert } from "lucide-react";
import { Card, CardContent, CardHeader } from "@/components/ui/card";
import {
Tooltip,
TooltipContent,
TooltipProvider,
TooltipTrigger,
} from "@/components/ui/tooltip";
import { TileHeader } from "@/components/insights/tile-header";
import { useTranslations, useTimeFormatPreference } from "@/lib/i18n/context";
import { hourCycleOptions } from "@/lib/format-locale";
@@ -71,6 +79,20 @@ export interface SleepHypnogramSession {
* Withings, Fitbit) is `false` and keeps the timeline.
*/
reconstructed?: boolean;
/**
* Non-null when two writer buckets reported clearly different asleep
* totals for this night (server-computed, observational only — the
* headline total stays the winning writer's). Renders as a discreet
* marker with a per-source breakdown in a tooltip.
*/
sourceDiscrepancy?: {
deltaMinutes: number;
sources: {
source: string;
deviceType: string | null;
asleepMinutes: number;
}[];
} | null;
}
export interface SleepHypnogramProps {
@@ -112,6 +134,61 @@ function formatMinutes(total: number, locale: string): string {
return hours > 0 ? `${hours}h ${mins}m` : `${mins}m`;
}
/**
* Localised label keys per `MeasurementSource` — the same map the
* source-priority settings surface uses (`sources-section.tsx`), so both
* surfaces humanise a source identically.
*/
const SOURCE_LABEL_KEYS: Record<string, string> = {
WITHINGS: "settings.sections.sources.sourceLabels.WITHINGS",
APPLE_HEALTH: "settings.sections.sources.sourceLabels.APPLE_HEALTH",
MANUAL: "settings.sections.sources.sourceLabels.MANUAL",
IMPORT: "settings.sections.sources.sourceLabels.IMPORT",
WHOOP: "settings.sections.sources.sourceLabels.WHOOP",
COMPUTED: "settings.sections.sources.sourceLabels.COMPUTED",
FITBIT: "settings.sections.sources.sourceLabels.FITBIT",
};
/**
* Brand names for sources without a localised settings label — brand
* spellings are locale-invariant, so no i18n key is needed for them.
*/
const SOURCE_BRAND_NAMES: Record<string, string> = {
OURA: "Oura",
POLAR: "Polar",
GOOGLE_HEALTH: "Google Health",
NIGHTSCOUT: "Nightscout",
STRAVA: "Strava",
TELEGRAM: "Telegram",
MCP: "MCP",
};
/**
* Localised device-type label keys (`Measurement.deviceType`), reused from
* the source-priority settings surface. Appended in parentheses so two
* writer apps behind the same source (watch vs phone under Apple Health)
* stay distinguishable in the discrepancy tooltip.
*/
const DEVICE_TYPE_LABEL_KEYS: Record<string, string> = {
watch: "settings.sections.sources.deviceLabels.watch",
band: "settings.sections.sources.deviceLabels.band",
ring: "settings.sections.sources.deviceLabels.ring",
phone: "settings.sections.sources.deviceLabels.phone",
scale: "settings.sections.sources.deviceLabels.scale",
other: "settings.sections.sources.deviceLabels.other",
};
function sourceDisplayName(
source: string,
deviceType: string | null,
t: (key: string) => string,
): string {
const labelKey = SOURCE_LABEL_KEYS[source];
const base = labelKey ? t(labelKey) : (SOURCE_BRAND_NAMES[source] ?? source);
const deviceKey = deviceType ? DEVICE_TYPE_LABEL_KEYS[deviceType] : undefined;
return deviceKey ? `${base} (${t(deviceKey)})` : base;
}
export function SleepHypnogram({ session }: SleepHypnogramProps) {
const { t, locale } = useTranslations();
const timeFormat = useTimeFormatPreference();
@@ -251,10 +328,51 @@ export function SleepHypnogram({ session }: SleepHypnogramProps) {
<CardHeader>
<div className="flex flex-col gap-0.5">
<TileHeader title={t("insights.sleep.hypnogram.title")} />
<span className="text-muted-foreground text-xs">
<span className="text-muted-foreground flex items-center gap-1 text-xs">
{t("insights.sleep.hypnogram.subtitle", {
asleep: formatMinutes(session.asleepMinutes, locale),
})}
{/* Discreet source-discrepancy marker: two writers reported
clearly different totals for this night. Observational — the
headline stays the winning writer's number; the tooltip lists
each source's own total. Muted, no colour wash, no banner;
negative margins keep the 44 px hit target from growing the
caption line (same trick as measurement-diversity-nudge). */}
{session.sourceDiscrepancy ? (
<TooltipProvider delayDuration={150}>
<Tooltip>
<TooltipTrigger asChild>
<button
type="button"
data-slot="sleep-source-discrepancy"
aria-label={t(
"insights.sleep.sourceDiscrepancy.tooltipTitle",
)}
className="text-muted-foreground focus-visible:ring-ring/50 -mx-3 -my-3 inline-flex min-h-11 min-w-11 shrink-0 items-center justify-center rounded-full focus-visible:ring-2 focus-visible:outline-none"
>
<TriangleAlert className="size-3.5" aria-hidden="true" />
</button>
</TooltipTrigger>
<TooltipContent
data-slot="sleep-source-discrepancy-body"
align="start"
className="max-w-xs leading-relaxed"
>
<p className="font-medium">
{t("insights.sleep.sourceDiscrepancy.tooltipTitle")}
</p>
<p>
{session.sourceDiscrepancy.sources
.map(
(b) =>
`${sourceDisplayName(b.source, b.deviceType, t)} ${formatMinutes(b.asleepMinutes, locale)}`,
)
.join(" · ")}
</p>
</TooltipContent>
</Tooltip>
</TooltipProvider>
) : null}
</span>
{/* The night's measuring source rides the header as a muted
caption — it is already on the wire, and "which device
@@ -16,6 +16,7 @@ import { useQuery, useQueryClient } from "@tanstack/react-query";
import { MedicationDetailSection } from "@/components/medications/medication-detail-section";
import { TileHeader } from "@/components/insights/tile-header";
import { Glp1PlateauNote } from "@/components/insights/glp1-plateau-note";
import { Card, CardContent, CardHeader } from "@/components/ui/card";
import { Button } from "@/components/ui/button";
import {
@@ -170,7 +171,7 @@ export function EfficacyTab({
straight into the tab's `space-y-6` rhythm. Additive: no existing
Wirkung content changes. */}
{isGlp1 && medicationName != null && medicationDose != null ? (
<div data-slot="wirkung-drug-level-section">
<div className="space-y-6" data-slot="wirkung-drug-level-section">
<DrugLevelChart
medication={{
id: medicationId,
@@ -178,6 +179,10 @@ export function EfficacyTab({
dose: medicationDose,
}}
/>
{/* v1.28.21 — weight-plateau note (association only). Self-gating:
renders nothing unless the server-side detector reports a
plateau on the current dose. */}
<Glp1PlateauNote />
</div>
) : null}