mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-14 22:50:51 +00:00
chore(release): v1.4.40 — comprehensive Critical+High architecture closure plus iOS PB30 enablement
Eleven touch-disjoint waves landed on develop plus a six-axis QA reconcile round before tagging. See CHANGELOG.md for the user-facing prose; this commit message documents the wave + report inventory for release-management traceability. Waves shipped (each with a phase report under .planning/): - phase-W-POOL-v1440-report.md — p-limit(4) wrapper around the analytics 15-way fan-out + pg.Pool max raised 10 -> 20. Closes the v1.4.39 empirical-trace finding #1 (Prisma pool starvation). - phase-W-DELETED-v1440-report.md — 11 reader-tier helpers + 3 integration contracts close audit Critical Finding #3 (soft-delete invisibility) across dashboard, analytics, summaries, rollup tiers, and the Coach snapshot path. - phase-W-INSIGHTS-v1440-report.md — mood-rollup swap on the three /api/insights/{features,targets,cards} routes plus the compliance-rollup hook gap closure for bulk-projection mints; the post-QA reconcile patch closes the six remaining measurement.findMany sites in the cluster that still leaked tombstoned rows. - phase-W-INFRA-v1440-report.md — rollup helper umbrella consolidation under src/lib/rollups/* with zero orphan re-exports; lint, typecheck, knip, and 93/93 rollup tests green post-restructure. - phase-W-RSC-v1440-report.md — per-tile Suspense boundaries plus the queryKey factory-bypass walker test (extended to comparison/ in the reconcile pass). - phase-W-PRIVACY-v1440-report.md — bilingual /privacy page with 17 paired-section tests pinning the 9 SB-3 disclosure requirements. - phase-W-AASA-v1440-report.md — /.well-known/apple-app-site-association endpoint pinned to S8WDX4W5KX.dev.healthlog.app with app-ID parity assertions guarding against split rotation. - phase-W-APNS-NOTIFY-v1440-report.md — MEDICATION_REMINDER time-sensitive APNs payload (priority 10 + interruption-level) scoped via a parameterised test that pins all 6 other event-types do not bypass Focus. AP-2 .p8 install gates real delivery. - phase-W-CONSENT-v1440-report.md — AI consent receipts CRUD with append-only invariant pinned in test; revoke-then-regrant leaves both rows; idempotent DELETE returns 200 + receipt: null. - phase-W-WMY-WIRE-v1440-report.md — three previously-dead WMY readers (week/month/year) wired through summaries-slice and health-score-fast-path with a linear-composability parity test pinning the cross-consumer routing contract. - phase-W-GHOSTS-v1440-report.md — ~1 177 lines of dead code removed across 9 atomic commits; startOfUtcDay + wallClockInTz consolidation eliminates a sibling-drift risk; knip whitelist trimmed to three files pending follow-up. QA reconcile patches applied per the v1.4.40 QA round (six reports under .planning/round-v1440-QA-*-findings.md): - senior C1 — dashboard-suspense-boundaries regex aligned with the post-W-INFRA Thread 2 userTimezone-local lift. - senior H1 — soft-delete filter added to the six remaining insights measurement.findMany sites. - specialist H1 — Promise.allSettled around bulk-projection compliance recompute on both /api/medications/intake and /api/dashboard/summary. - ux H1 — compare-toggle migrated to queryKeys.dashboardWidgets factory; walker test extended to src/components/comparison/. - security M1 — consent artefact 64 KB cap enforced via Buffer.byteLength (UTF-8 bytes, not UTF-16 code units). Quality gates green at tag: pnpm typecheck, pnpm lint, pnpm knip --include files,dependencies,binaries,unlisted, pnpm test --run (4726 passing / 1 skipped). Tests 4525 -> 4726 unit + 1 skipped over the v1.4.39 -> v1.4.40 span. User-facing prose: see CHANGELOG.md.
This commit is contained in:
1 parent
f9996552ed
commit
1114cf7e63
146 files changed
+8207
-2279
No files matched your search
@@ -10,7 +10,7 @@ import {
|
||||
} from "@/lib/api-response";
|
||||
import { updateIntakeEventSchema } from "@/lib/validations/medication";
|
||||
import { invalidateUserMedications } from "@/lib/cache/invalidate";
|
||||
import { recomputeMedicationComplianceForEvent } from "@/lib/medications/compliance-rollups";
|
||||
import { recomputeMedicationComplianceForEvent } from "@/lib/rollups/medication-compliance-rollups";
|
||||
import { NextRequest } from "next/server";
|
||||
|
||||
type RouteParams = { params: Promise<{ id: string; eventId: string }> };
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
import {
|
||||
recomputeMedicationComplianceForDay,
|
||||
dayKeyForScheduledFor,
|
||||
} from "@/lib/medications/compliance-rollups";
|
||||
} from "@/lib/rollups/medication-compliance-rollups";
|
||||
import { NextRequest } from "next/server";
|
||||
import { z } from "zod/v4";
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ import { withIdempotency } from "@/lib/idempotency";
|
||||
import { consumeOneDose } from "@/lib/medications/inventory/service";
|
||||
import { assertMedicationOwnership } from "@/lib/medications/route-guards";
|
||||
import { invalidateUserMedications } from "@/lib/cache/invalidate";
|
||||
import { recomputeMedicationComplianceForEvent } from "@/lib/medications/compliance-rollups";
|
||||
import { recomputeMedicationComplianceForEvent } from "@/lib/rollups/medication-compliance-rollups";
|
||||
import { NextRequest } from "next/server";
|
||||
|
||||
type RouteParams = { params: Promise<{ id: string }> };
|
||||
|
||||
@@ -1,105 +0,0 @@
|
||||
import { NextRequest } from "next/server";
|
||||
import { z } from "zod/v4";
|
||||
import { prisma } from "@/lib/db";
|
||||
import { apiHandler, requireAuth } from "@/lib/api-handler";
|
||||
import { annotate } from "@/lib/logging/context";
|
||||
import { apiError, apiSuccess } from "@/lib/api-response";
|
||||
|
||||
const querySchema = z.object({
|
||||
from: z.iso
|
||||
.datetime({ offset: true })
|
||||
.transform((value) => new Date(value))
|
||||
.optional(),
|
||||
to: z.iso
|
||||
.datetime({ offset: true })
|
||||
.transform((value) => new Date(value))
|
||||
.optional(),
|
||||
});
|
||||
|
||||
function toBerlinDayKey(date: Date): string {
|
||||
return new Intl.DateTimeFormat("sv-SE", {
|
||||
timeZone: "Europe/Berlin",
|
||||
year: "numeric",
|
||||
month: "2-digit",
|
||||
day: "2-digit",
|
||||
}).format(date);
|
||||
}
|
||||
|
||||
interface DailySummary {
|
||||
date: string;
|
||||
total: number;
|
||||
medications: Record<string, number>;
|
||||
}
|
||||
|
||||
export const GET = apiHandler(async (request: NextRequest) => {
|
||||
const { user } = await requireAuth();
|
||||
|
||||
const parsed = querySchema.safeParse(
|
||||
Object.fromEntries(request.nextUrl.searchParams),
|
||||
);
|
||||
if (!parsed.success) {
|
||||
return apiError(parsed.error.issues[0].message, 422);
|
||||
}
|
||||
|
||||
const { from, to } = parsed.data;
|
||||
|
||||
const events = await prisma.medicationIntakeEvent.findMany({
|
||||
where: {
|
||||
userId: user.id,
|
||||
skipped: false,
|
||||
takenAt: {
|
||||
not: null,
|
||||
...(from && { gte: from }),
|
||||
...(to && { lte: to }),
|
||||
},
|
||||
},
|
||||
select: {
|
||||
takenAt: true,
|
||||
medication: {
|
||||
select: {
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
orderBy: { takenAt: "asc" },
|
||||
});
|
||||
|
||||
const medicationNames = new Set<string>();
|
||||
const byDay = new Map<string, DailySummary>();
|
||||
|
||||
for (const event of events) {
|
||||
if (!event.takenAt) continue;
|
||||
|
||||
const medicationName = event.medication.name;
|
||||
const dayKey = toBerlinDayKey(event.takenAt);
|
||||
medicationNames.add(medicationName);
|
||||
|
||||
const existing = byDay.get(dayKey) ?? {
|
||||
date: dayKey,
|
||||
total: 0,
|
||||
medications: {},
|
||||
};
|
||||
|
||||
existing.total += 1;
|
||||
existing.medications[medicationName] =
|
||||
(existing.medications[medicationName] ?? 0) + 1;
|
||||
byDay.set(dayKey, existing);
|
||||
}
|
||||
|
||||
const points = [...byDay.values()].sort((a, b) =>
|
||||
a.date.localeCompare(b.date),
|
||||
);
|
||||
|
||||
annotate({
|
||||
action: { name: "medication.intake_summary" },
|
||||
meta: {
|
||||
point_count: points.length,
|
||||
medication_count: medicationNames.size,
|
||||
},
|
||||
});
|
||||
|
||||
return apiSuccess({
|
||||
points,
|
||||
medications: [...medicationNames].sort((a, b) => a.localeCompare(b, "de")),
|
||||
});
|
||||
});
|
||||
@@ -201,6 +201,15 @@ describe("GET /api/medications/intake", () => {
|
||||
source: "REMINDER",
|
||||
},
|
||||
],
|
||||
// v1.4.39 W-SERVER-FIX-2 — the createMany must ship
|
||||
// `skipDuplicates: true` so a concurrent dashboard-summary hit
|
||||
// can't race a duplicate `(userId, medicationId, scheduledFor,
|
||||
// REMINDER)` row in between this route's existence probe and
|
||||
// insert. The schema-level @@unique([userId, medicationId,
|
||||
// scheduledFor, source]) is the structural backstop; this flag
|
||||
// is the defense-in-depth that keeps the route returning 2xx
|
||||
// when the constraint rejects the second mint.
|
||||
skipDuplicates: true,
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ import { invalidateUserMedications } from "@/lib/cache/invalidate";
|
||||
import {
|
||||
recomputeMedicationComplianceForDay,
|
||||
dayKeyForScheduledFor,
|
||||
} from "@/lib/medications/compliance-rollups";
|
||||
} from "@/lib/rollups/medication-compliance-rollups";
|
||||
|
||||
const MAX_ENTRIES_PER_BATCH = 500;
|
||||
const BATCH_RATE_LIMIT_MAX = 60;
|
||||
|
||||
@@ -32,7 +32,7 @@ import {
|
||||
recomputeMedicationComplianceForEvent,
|
||||
enqueueUserMedicationComplianceBackfill,
|
||||
type ComplianceBucket as RollupComplianceBucket,
|
||||
} from "@/lib/medications/compliance-rollups";
|
||||
} from "@/lib/rollups/medication-compliance-rollups";
|
||||
import { expandTodayIntakes } from "@/lib/medication-schedule";
|
||||
|
||||
const querySchema = z.object({
|
||||
@@ -156,6 +156,39 @@ export const GET = apiHandler(async (request: NextRequest) => {
|
||||
// structural backstop, this is the defense-in-depth.
|
||||
skipDuplicates: true,
|
||||
});
|
||||
|
||||
// v1.4.40 — close the compliance-rollup hook gap from v1.4.39.4.
|
||||
// The bulk projection mints fresh `(medicationId, scheduledFor)`
|
||||
// rows in PENDING state; without this hook the rollup for the
|
||||
// affected `(user, medication, day)` tuples stays at its previous
|
||||
// (pre-projection) `scheduled` count, which inflates the apparent
|
||||
// compliance % until the user actually logs against the new
|
||||
// row. Coalesce by `(medicationId, dayKey)` so we fire one
|
||||
// recompute per distinct day-tuple instead of one per row.
|
||||
// Best-effort: errors stay caught inside the helper so a
|
||||
// populator hiccup doesn't surface as a 5xx on the intake
|
||||
// request. Mirror call site in `dashboard/summary/route.ts`.
|
||||
const seenDayKeys = new Set<string>();
|
||||
const recomputeJobs: Array<Promise<void>> = [];
|
||||
for (const m of missing) {
|
||||
const key = `${m.medicationId}|${m.scheduledFor.toISOString().slice(0, 10)}`;
|
||||
if (seenDayKeys.has(key)) continue;
|
||||
seenDayKeys.add(key);
|
||||
recomputeJobs.push(
|
||||
recomputeMedicationComplianceForEvent({
|
||||
userId: user.id,
|
||||
medicationId: m.medicationId,
|
||||
scheduledFor: m.scheduledFor,
|
||||
tz: userTz,
|
||||
}),
|
||||
);
|
||||
}
|
||||
// Defence in depth (specialist H1): the helper swallows internally
|
||||
// today, but any future refactor that lets a throw escape would
|
||||
// turn the intake POST into a 5xx. `allSettled` keeps the
|
||||
// best-effort contract explicit at the call site so the request
|
||||
// stays 200-OK regardless of helper behaviour.
|
||||
await Promise.allSettled(recomputeJobs);
|
||||
}
|
||||
|
||||
const events = await prisma.medicationIntakeEvent.findMany({
|
||||
|
||||
Reference in new issue
Block a user