Merge branch 'feat/v146-server-meds2' into feat/v146-server

# Conflicts:
#	src/__tests__/external-id-stability-guard.test.ts
This commit is contained in:
Marc-André Bombeck committed 2026-10-23 14:52:03 +02:00
commit 40eb1255b7
148 files changed
+96447 -3191

No files matched your search

@@ -69,6 +69,15 @@ const SCOPED_DIRS = [
"lib/measurements/batch-ingest/",
"lib/measurements/create/",
"lib/measurements/list/measurement-list.ts",
"lib/medications/read-medication.ts",
"lib/medications/update-medication/",
"lib/medications/delete-medication.ts",
"lib/medications/record-intake/",
"lib/medications/list-intake-events.ts",
"lib/medications/intake-today.ts",
"lib/medications/intake-compliance.ts",
"lib/medications/update-intake-status/",
"lib/medications/intake-bulk/",
];
/** Types a device writes at sampling rate rather than a few times a day. */
@@ -365,7 +365,7 @@ describe("the intake idempotency key is never read across users", () => {
const found = intakeQueriesFilteringOnTheKey();
expect(found.length).toBeGreaterThanOrEqual(6);
expect(found.map((f) => f.file)).toContain(
"app/api/medications/intake/bulk/route.ts",
"lib/medications/intake-bulk/entry-write.ts",
);
});
@@ -403,7 +403,10 @@ describe("the batch surfaces refuse per entry, never whole-batch", () => {
"lib/measurements/batch-ingest/ingest.ts",
],
"app/api/mood-entries/bulk/route.ts": ["lib/mood/bulk-ingest.ts"],
"app/api/medications/intake/bulk/route.ts": [],
"app/api/medications/intake/bulk/route.ts": [
"lib/medications/intake-bulk/entry.ts",
"lib/medications/intake-bulk/ingest.ts",
],
"app/api/workouts/batch/route.ts": [
"lib/workouts/batch-ingest/entries.ts",
"lib/workouts/batch-ingest/ingest.ts",
@@ -309,9 +309,44 @@ function actionsReachableFrom(
out.push(...packageActions(reexported, read));
}
}
for (const body of HANDLER_BODY_MODULES[relative(SRC, file)] ?? []) {
out.push(...actionsReachableFrom(join(SRC, body), read));
}
return out;
}
/**
* Delegated routes whose handler bodies live in service modules under
* `src/lib/`, keyed by the route relative to `src/`. A handler body is the
* route's own code moved, so it counts at the route's level: its actions and
* those of its direct imports (the medication lifecycle a dose write
* reconciles through) are reached as they were before the move. Each module
* has to be a direct import of its route (leg below), so an entry cannot
* outlive the delegation it describes.
*/
const HANDLER_BODY_MODULES: Record<string, readonly string[]> = {
"app/api/medications/route.ts": ["lib/medications/create-medication.ts"],
"app/api/medications/[id]/route.ts": [
"lib/medications/read-medication.ts",
"lib/medications/update-medication/update-medication.ts",
"lib/medications/delete-medication.ts",
],
"app/api/medications/[id]/intake/route.ts": [
"lib/medications/record-intake/record-intake.ts",
"lib/medications/list-intake-events.ts",
],
"app/api/medications/[id]/intake/[eventId]/route.ts": [
"lib/medications/update-intake-event.ts",
"lib/medications/delete-intake-event.ts",
],
"app/api/medications/intake/route.ts": [
"lib/medications/intake-today.ts",
"lib/medications/intake-compliance.ts",
"lib/medications/update-intake-status/admission.ts",
"lib/medications/update-intake-status/update-intake-status.ts",
],
};
/**
* The actions of a re-exported module together with the sibling modules it
* imports from its own folder. The re-exported module is a package's public
@@ -553,6 +588,21 @@ describe("every delegated action has a sentence of its own", () => {
expect(manageOnly).not.toContain(anchor);
});
it("reads each moved handler body where its route imports it from", () => {
const entries = Object.entries(HANDLER_BODY_MODULES);
expect(entries.length).toBeGreaterThan(0);
for (const [route, bodies] of entries) {
const file = join(SRC, route);
expect(delegatedModules, route).toContain(file);
for (const body of bodies) {
expect(
read(file).imports,
`${route} does not import ${body}`,
).toContain(join(SRC, body));
}
}
});
it("reaches the actions a route files through what it imports", () => {
// Both halves of the fix, pinned against the two that were invisible.
expect(actions).toContain("medication.intake.import.kickoff.denied");
@@ -68,13 +68,13 @@ const INTAKE_MAY_SEE_EVERY_ROW: Record<string, string> = {
"lib/jobs/measurement-tombstone-cleanup.ts": "tombstone purge",
"lib/ai/coach/tools/availability.ts":
"whether any intake history exists, and its date range",
"app/api/medications/[id]/intake/route.ts":
"one medication's recorded history, listed or written",
"lib/medications/list-intake-events.ts":
"one medication's recorded history, listed",
"app/api/medications/[id]/intake/bulk-delete/route.ts":
"deletes rows the person chose",
"app/api/medications/[id]/route.ts":
"one medication's slots; tombstones on the tracking switch",
"app/api/medications/intake/bulk/route.ts": "writes recorded doses",
"lib/medications/update-medication/write.ts":
"one medication's open slots, tombstoned on a schedule replace or the tracking switch",
"lib/medications/intake-bulk/ingest.ts": "writes recorded doses",
"lib/medications/scheduling/slot-upsert.ts":
"binds a recorded dose to its slot",
"lib/medications/scheduling/worker-helpers.ts":
@@ -115,6 +115,14 @@ const MAY_READ_EVERY_ROW: Record<string, string> = {
"units consumed by a recorded dose",
"lib/medications/intake-slot-dedup.ts":
"folds duplicate rows of doses already recorded",
// The medication edit: the schedule count and the primary schedule's id
// for the reminder-window bridge, and the replaced rows archived as an era
// whose payload is empty for a stretch with tracking off. Nothing due comes
// out of either; the edit answers through scheduleWireFields.
"lib/medications/update-medication/preflight.ts":
"schedule count and the primary schedule's id, derives nothing due",
"lib/medications/update-medication/write.ts":
"archives the replaced schedule; the era payload follows the tracking switch",
// Readers that hand the rows to a builder whose input TYPE requires
// `trackIntake` and which gates on it: the per-medication compliance
// payload (`buildCompliancePayload`, INTAKE_NOT_TRACKED) and the doctor
@@ -435,6 +435,17 @@ function callsSymbol(rel: string, symbol: string): boolean {
*/
const HANDLER_BODY_MODULES: Record<string, readonly string[]> = {
"app/api/medications/route.ts": ["lib/medications/create-medication.ts"],
"app/api/medications/[id]/route.ts": [
"lib/medications/update-medication/update-medication.ts",
"lib/medications/delete-medication.ts",
],
"app/api/medications/[id]/intake/route.ts": [
"lib/medications/record-intake/record-intake.ts",
],
"app/api/medications/intake/route.ts": [
"lib/medications/update-intake-status/admission.ts",
"lib/medications/update-intake-status/update-intake-status.ts",
],
"app/api/medications/[id]/intake/[eventId]/route.ts": [
"lib/medications/update-intake-event.ts",
"lib/medications/delete-intake-event.ts",