chore(insights): retire the InsightAdvisorCard surface

Drop the InsightAdvisorCard component, its four integration tests
under src/components/insights/__tests__, the page-level mount on
/insights, the orphan i18n keys (advisorTitle, aiOverviewTitle), the
e2e advisor-card spec, the dashboard.spec.ts advisor assertion and
every related comment. The InsightsTabStrip regenerate icon stays
untouched as the sole power-user refresh affordance. The iOS-consumed
POST /api/insights/generate endpoint and its request/response shape
stay byte-stable.
This commit is contained in:
Marc-André Bombeck committed 2026-05-16 01:19:14 +02:00
1 parent cad53a68a3
commit 52edf85f02
19 files changed
+32 -2209

No files matched your search

+11 -91
View File
@@ -110,83 +110,13 @@ test.describe("authenticated dashboard render", () => {
});
});
// The /insights mother page gates the InsightAdvisorCard on
// `/api/insights/comprehensive` returning a non-null payload
// (`totalMeasurements` is the gate). Mock it so the page renders
// the card surface instead of the EmptyState CTA.
await page.route("**/api/insights/comprehensive", (route) =>
route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify({
data: {
summaries: {},
bmi: 24.2,
bmiClassification: null,
bpClassification: null,
bpPctInTarget: 78,
bpTargets: { sysLow: 120, sysHigh: 140, diaLow: 80, diaHigh: 90 },
weightBpCorrelation: null,
scatterData: [],
bpMedicationCorrelation: null,
bpMedicationScatterData: [],
medications: [],
alerts: [],
hasOpenAiKey: true,
dataSpanDays: 90,
totalMeasurements: 25,
moodSummary: null,
moodBpCorrelation: null,
moodBpScatterData: [],
moodWeightCorrelation: null,
moodWeightScatterData: [],
moodPulseCorrelation: null,
moodPulseScatterData: [],
},
error: null,
}),
}),
);
// InsightAdvisorCard reads `/api/insights/generate` (a POST that
// doubles as cache-aware read). Mock a minimal-but-valid
// InsightResult so the card renders the populated body branch with
// the `data-slot="insight-summary"` container the assertion below
// pins on. The exact prose is intentionally NOT asserted — AI
// Insights are HealthLog's differentiator and the rendered text
// depends on provider + cache state. The contract under test is
// "an insight card with a populated body is visible", not "the
// string X is on screen".
await page.route("**/api/insights/generate", (route) =>
route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify({
data: {
insights: {
insightType: "general",
summary: "Blood-pressure trend is stable; continue routine.",
classification: "gut",
classificationLabel: "Good",
findings: [],
correlations: [],
primaryRecommendation: "Keep up the current routine.",
recommendations: [],
dataQuality: {
coverage: "good",
gaps: [],
confidence: "hoch",
},
disclaimer: "Not medical advice.",
},
cached: true,
cachedAt: new Date().toISOString(),
legacyPayload: false,
},
error: null,
}),
}),
);
// v1.4.28 retired the InsightAdvisorCard surface. Coach drawer
// remains the conversational entry point on /insights, but the
// bottom-of-page card with its own summary container is gone. The
// dashboard render assertion below no longer touches /insights, so
// we don't need to mock /api/insights/comprehensive or
// /api/insights/generate any more (the iOS-consumed POST endpoint
// is preserved server-side; only the web mount retired).
});
test("dashboard tile strip + chart + insight card render", async ({
@@ -219,20 +149,10 @@ test.describe("authenticated dashboard render", () => {
page.locator(".recharts-wrapper, .recharts-surface").first(),
).toBeVisible({ timeout: 10_000 });
// AI insight card: visit the dedicated /insights page (the
// mother surface that mounts the InsightAdvisorCard). We assert
// on the populated-card's stable structural hook
// (`data-slot="insight-summary"`) rather than a literal piece of
// AI prose. AI Insights are evidence-grounded and dynamic by
// design — the rendered text changes per provider + cache state
// and never repeats verbatim, so pinning a literal substring is
// brittle and contradicts the differentiator. The contract under
// test is "the insight card mounts its summary body when the
// payload arrives", which is exactly what the slot signals.
await page.goto("/insights", { waitUntil: "domcontentloaded" });
await expect(
page.locator('[data-slot="insight-summary"]'),
).toBeVisible({ timeout: 10_000 });
// v1.4.28 — the bottom-of-page InsightAdvisorCard retired; the
// dashboard spec no longer asserts on its summary slot. The hero
// strip and the Coach drawer carry the differentiator on /insights
// and are covered by their own specs.
// Filter out a small set of known-noise messages — we care about
// real React/JS uncaught errors only. 404s from optional assets
-245
View File
@@ -1,245 +0,0 @@
import { expect, test } from "@playwright/test";
import { STORAGE_STATE_PATH } from "./setup/global-setup";
/**
* v1.4.16 phase D reconcile (CRITICAL C1) — proves the polished
* `<InsightAdvisorCard>` is mounted on `/insights` and consumes the
* `/api/insights/generate` payload.
*
* Before this fix the page rendered only `<InsightStatusCard>` (text-
* only summary per section); the rec card surface from B5c/d/e/B1b
* (severity-ordered grid + per-rec rationale + confidence meter +
* thumbs feedback + medical-citation footnote) was reachable only from
* unit tests. This spec asserts the live route now reaches it.
*/
test.describe("insights advisor card on /insights (C1)", () => {
test.use({ storageState: STORAGE_STATE_PATH });
test.beforeEach(async ({ page }) => {
// Stub the analytics + comprehensive endpoints with a small but
// populated dataset so the page clears the `if (!data)` empty
// gate and renders the body.
await page.route("**/api/analytics", (route) =>
route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify({
data: {
summaries: {
WEIGHT: {
latest: 78.5,
avg7: 78.2,
avg30: 77.9,
slope30: { slope: -0.05, direction: "down" },
count: 30,
},
BLOOD_PRESSURE_SYS: {
latest: 124,
avg7: 122,
avg30: 121,
slope30: { slope: 0.1, direction: "flat" },
count: 25,
},
BLOOD_PRESSURE_DIA: {
latest: 80,
avg7: 79,
avg30: 78,
slope30: { slope: 0.05, direction: "flat" },
count: 25,
},
PULSE: {
latest: 68,
avg7: 70,
avg30: 71,
slope30: { slope: -0.2, direction: "down" },
count: 25,
},
},
bpInTargetPct: 78,
glucoseByContext: {},
},
error: null,
}),
}),
);
await page.route("**/api/insights/comprehensive", (route) =>
route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify({
data: {
summaries: {},
bmi: 24.2,
bmiClassification: null,
bpClassification: null,
bpPctInTarget: 78,
bpTargets: { sysLow: 120, sysHigh: 140, diaLow: 80, diaHigh: 90 },
weightBpCorrelation: null,
scatterData: [],
bpMedicationCorrelation: null,
bpMedicationScatterData: [],
medications: [],
alerts: [],
hasOpenAiKey: true,
dataSpanDays: 90,
totalMeasurements: 25,
moodSummary: null,
moodBpCorrelation: null,
moodBpScatterData: [],
moodWeightCorrelation: null,
moodWeightScatterData: [],
moodPulseCorrelation: null,
moodPulseScatterData: [],
},
error: null,
}),
}),
);
// Per-status cards still render below the advisor card; mock them
// to a simple connected payload so the section bodies don't bail.
for (const slug of [
"general-status",
"blood-pressure-status",
"weight-status",
"pulse-status",
"bmi-status",
"mood-status",
"medication-compliance-status",
]) {
await page.route(`**/api/insights/${slug}*`, (route) =>
route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify({
data: {
hasProvider: true,
text: `Mock ${slug} text.`,
summary: `Mock ${slug} text.`,
cached: true,
updatedAt: new Date().toISOString(),
medications: [],
},
error: null,
}),
}),
);
}
await page.route("**/api/dashboard/widgets", (route) =>
route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify({
data: {
version: 1,
widgets: [
{ id: "weight", visible: true, tileVisible: true, order: 0 },
],
comparisonBaseline: "none",
},
error: null,
}),
}),
);
await page.route("**/api/measurements*", (route) =>
route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify({
data: { measurements: [], meta: { total: 0 } },
error: null,
}),
}),
);
// The advisor query — return a populated InsightResult with one
// urgent rec carrying rationale + confidence so the rec card has
// something to render.
await page.route("**/api/insights/generate", (route) =>
route.fulfill({
status: 200,
contentType: "application/json",
body: JSON.stringify({
data: {
insights: {
insightType: "general",
summary: "Your blood pressure has improved slightly.",
classification: "gut",
classificationLabel: "Good",
findings: [
{
label: "BP avg dropped 2 mmHg",
value: "120/78",
assessment: "positive",
},
],
correlations: [],
primaryRecommendation: "Keep up the current routine.",
recommendations: [
{
id: "rec-1",
text: "Consider reducing sodium intake on weekends.",
severity: "important",
confidence: 78,
rationale: {
dataWindow: "last30days",
comparedTo: "your 90-day median",
deviation: "BP averages drift up on weekends",
},
metricSource: {
type: "bloodPressureSys",
timeRange: "last30days",
summary: "Sys BP avg 124 vs 121 weekly median",
},
},
],
dataQuality: { coverage: "good", gaps: [], confidence: "hoch" },
disclaimer: "Not medical advice.",
},
cached: true,
cachedAt: new Date().toISOString(),
legacyPayload: false,
},
error: null,
}),
}),
);
});
test("renders InsightAdvisorCard with severity-ordered recommendation grid", async ({
page,
}) => {
await page.goto("/insights", { waitUntil: "domcontentloaded" });
// Hero + advisor card both render. v1.4.20 B1 replaced the legacy
// `<InsightsPageHero>` (data-slot="insights-page-hero") with the
// condensed `<HeroStrip>` (data-slot="insights-hero-strip"); the
// advisor card is the C1 deliverable below it.
await expect(page.locator('[data-slot="insights-hero-strip"]')).toBeVisible(
{
timeout: 10_000,
},
);
// The recommendation card surface from B5c — `data-slot` markers
// are pinned in tests, look for the rec text the mock provided.
await expect(
page.getByText("Consider reducing sodium intake on weekends."),
).toBeVisible({ timeout: 10_000 });
// ConfidenceMeter is mounted in the rec-card slot; B5d marks the
// component with `data-slot="confidence-meter"`.
await expect(
page.locator('[data-slot="confidence-meter"]').first(),
).toBeVisible({ timeout: 10_000 });
// Summary surface from the advisor card carries the prose.
await expect(
page.getByText("Your blood pressure has improved slightly."),
).toBeVisible({ timeout: 10_000 });
});
});