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:
Marc-André Bombeck committed 2026-05-21 12:48:02 +02:00
1 parent f9996552ed
commit 1114cf7e63
146 files changed
+8207 -2279

No files matched your search

+68 -1
View File
@@ -73,7 +73,7 @@ vi.mock("next/headers", () => ({
})),
}));
import { GET } from "../route";
import { ANALYTICS_TYPE_FETCH_CONCURRENCY, GET } from "../route";
import { prisma } from "@/lib/db";
import { getSession } from "@/lib/auth/session";
import { __resetAllCachesForTests } from "@/lib/cache/server-cache";
@@ -376,4 +376,71 @@ describe("GET /api/analytics", () => {
expect(body.data.lastSeenByType.WEIGHT?.daysAgo).toBeLessThanOrEqual(6);
expect(body.data.lastSeenByType.PULSE).toBeNull();
});
// v1.4.40 W-POOL — pin the bounded-concurrency cap on the per-type
// fan-out inside `buildAnalyticsResponse`. The v1.4.39 empirical
// trace (`.planning/round-v1439-empirical-trace.md` §B1) showed the
// raw `Promise.all` over `fetchMeasurementSeriesChunked` holding
// ≥8 of the default-10 pg.Pool slots for 6.5 s on a power-user cold
// mount. The p-limit(4) wrapper keeps the same total work but caps
// inflight Prisma round-trips for this branch at 4.
//
// The assertion instruments the `prisma.measurement.findMany` mock
// to track peak inflight count + total batches. With N≥15 types and
// a 20 ms per-call delay, an unbounded `Promise.all` would peak at
// ~15 and finish in ~20 ms; the bounded version peaks at exactly 4
// and finishes in ~80 ms (4 batches × 20 ms ceiling).
it("caps per-type Prisma fan-out at ANALYTICS_TYPE_FETCH_CONCURRENCY", async () => {
// Default-slice path requires no coverage so the route falls into
// the live per-type loop where the fan-out lives.
vi.mocked(prisma.measurementRollup.findMany).mockResolvedValue([] as never);
let inflight = 0;
let peak = 0;
let calls = 0;
vi.mocked(prisma.measurement.findMany).mockImplementation(
(async () => {
// Only count the per-type chunked fan-out calls (not the
// narrower glucose / sleep-stage `findMany` reads inside the
// same route; those run sequentially AFTER the fan-out
// completes so they never overlap with peak inflight).
calls += 1;
inflight += 1;
peak = Math.max(peak, inflight);
// 20 ms is large enough to make the bounded vs unbounded
// distinction observable but small enough to keep the suite
// under a second.
await new Promise((resolve) => setTimeout(resolve, 20));
inflight -= 1;
// Return an empty page so the chunked reader exits after one
// round-trip per type.
return [] as never;
}) as never,
);
const t0 = Date.now();
const res = await (
GET as unknown as (...args: never[]) => Promise<Response>
)();
const elapsed = Date.now() - t0;
expect(res.status).toBe(200);
// The cap itself — peak inflight Prisma reads against
// `measurements` never crosses the configured ceiling.
expect(ANALYTICS_TYPE_FETCH_CONCURRENCY).toBe(4);
expect(peak).toBeLessThanOrEqual(ANALYTICS_TYPE_FETCH_CONCURRENCY);
// Sanity: more than one type was actually walked, otherwise the
// bound is unfalsifiable.
expect(calls).toBeGreaterThanOrEqual(8);
// Wall-clock proves the lanes are saturated rather than serialised
// by accident. 4 lanes × 20 ms × ⌈calls/4⌉ ≈ 60-100 ms; an
// unbounded fan-out would finish in ~25-40 ms; a fully serial
// walk would take calls × 20 ms ≈ 300+ ms. The window catches
// both regressions.
expect(elapsed).toBeGreaterThanOrEqual(40);
expect(elapsed).toBeLessThan(calls * 20);
});
});