mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-17 23:52:24 +00:00
style: apply prettier across the tree
One-shot prettier pass so the new format:check gate starts from a clean baseline. Formatting only — no behaviour change. Generator-owned and vendored artifacts stay untouched via .prettierignore.
This commit is contained in:
1 parent
b3fea2ef59
commit
1f4ba5939d
1000 files changed
+12130
-8385
No files matched your search
@@ -111,13 +111,17 @@ describe("computeEpisodeCorrelation — rollup-vs-live parity", () => {
|
||||
// trailing (to == now) episode-window read; the bounded baseline read
|
||||
// goes through measurement.findMany (to != now). ──
|
||||
const dayCoverage = onlyRhr(
|
||||
new Map<string, boolean>(ILLNESS_SCAN_TYPES.map((t) => [String(t), t === "RESTING_HEART_RATE"])),
|
||||
new Map<string, boolean>(
|
||||
ILLNESS_SCAN_TYPES.map((t) => [String(t), t === "RESTING_HEART_RATE"]),
|
||||
),
|
||||
);
|
||||
rollup.probeRollupCoverage.mockResolvedValue(dayCoverage);
|
||||
rollup.readBestGranularityRollups.mockImplementation(
|
||||
async (_u: string, type: string, windowDays: number) => {
|
||||
if (type !== "RESTING_HEART_RATE") return null;
|
||||
const since = new Date(NOW.getTime() - windowDays * 24 * 60 * 60 * 1000);
|
||||
const since = new Date(
|
||||
NOW.getTime() - windowDays * 24 * 60 * 60 * 1000,
|
||||
);
|
||||
const sinceKey = since.toISOString().slice(0, 10);
|
||||
const rows = DAILY.filter((d) => d.day >= sinceKey).map((d) => ({
|
||||
bucketStart: new Date(`${d.day}T00:00:00Z`),
|
||||
@@ -133,10 +137,16 @@ describe("computeEpisodeCorrelation — rollup-vs-live parity", () => {
|
||||
return rows.length > 0 ? { granularity: "DAY" as const, rows } : null;
|
||||
},
|
||||
);
|
||||
db.measurement.findMany.mockImplementation(async ({ where }: { where: { type: string; measuredAt: { gte: Date; lt: Date } } }) => {
|
||||
if (where.type !== "RESTING_HEART_RATE") return [];
|
||||
return rawRowsWithin(where.measuredAt.gte, where.measuredAt.lt);
|
||||
});
|
||||
db.measurement.findMany.mockImplementation(
|
||||
async ({
|
||||
where,
|
||||
}: {
|
||||
where: { type: string; measuredAt: { gte: Date; lt: Date } };
|
||||
}) => {
|
||||
if (where.type !== "RESTING_HEART_RATE") return [];
|
||||
return rawRowsWithin(where.measuredAt.gte, where.measuredAt.lt);
|
||||
},
|
||||
);
|
||||
|
||||
const dayOut = await computeEpisodeCorrelation("u1", EPISODE, "UTC", NOW);
|
||||
|
||||
@@ -151,7 +161,11 @@ describe("computeEpisodeCorrelation — rollup-vs-live parity", () => {
|
||||
rollup.probeRollupCoverage.mockResolvedValue(noCoverage);
|
||||
rollup.readBestGranularityRollups.mockResolvedValue(null);
|
||||
db.measurement.findMany.mockImplementation(
|
||||
async ({ where }: { where: { type: string; measuredAt: { gte: Date; lt?: Date } } }) => {
|
||||
async ({
|
||||
where,
|
||||
}: {
|
||||
where: { type: string; measuredAt: { gte: Date; lt?: Date } };
|
||||
}) => {
|
||||
if (where.type !== "RESTING_HEART_RATE") return [];
|
||||
const from = where.measuredAt.gte;
|
||||
const to = where.measuredAt.lt ?? NOW;
|
||||
@@ -192,7 +206,9 @@ describe("computeEpisodeCorrelation — user-tz day keying", () => {
|
||||
// The vital series must key by the user's day so it lines up with the
|
||||
// tz-keyed onset/feltBetter markers (the off-by-one this fix closes).
|
||||
rollup.probeRollupCoverage.mockResolvedValue(
|
||||
new Map<string, boolean>(ILLNESS_SCAN_TYPES.map((t) => [String(t), false])),
|
||||
new Map<string, boolean>(
|
||||
ILLNESS_SCAN_TYPES.map((t) => [String(t), false]),
|
||||
),
|
||||
);
|
||||
rollup.readBestGranularityRollups.mockResolvedValue(null);
|
||||
|
||||
@@ -203,7 +219,10 @@ describe("computeEpisodeCorrelation — user-tz day keying", () => {
|
||||
let cursor = Date.parse("2025-12-20T20:00:00Z");
|
||||
const jit = [-2, -1, 0, 1, 2];
|
||||
for (let i = 0; i < 20; i++) {
|
||||
rows.push({ value: 55 + jit[i % jit.length], measuredAt: new Date(cursor) });
|
||||
rows.push({
|
||||
value: 55 + jit[i % jit.length],
|
||||
measuredAt: new Date(cursor),
|
||||
});
|
||||
cursor += 24 * 60 * 60 * 1000;
|
||||
}
|
||||
// Episode-span readings, including the boundary-crossing 03:00Z spike.
|
||||
@@ -215,7 +234,11 @@ describe("computeEpisodeCorrelation — user-tz day keying", () => {
|
||||
rows.push({ value: 58, measuredAt: new Date("2026-01-17T20:00:00Z") });
|
||||
|
||||
db.measurement.findMany.mockImplementation(
|
||||
async ({ where }: { where: { type: string; measuredAt: { gte: Date; lt?: Date } } }) => {
|
||||
async ({
|
||||
where,
|
||||
}: {
|
||||
where: { type: string; measuredAt: { gte: Date; lt?: Date } };
|
||||
}) => {
|
||||
if (where.type !== "RESTING_HEART_RATE") return [];
|
||||
const from = where.measuredAt.gte.getTime();
|
||||
const to = where.measuredAt.lt?.getTime() ?? NOW.getTime();
|
||||
@@ -249,12 +272,18 @@ describe("computeEpisodeCorrelation — user-tz day keying", () => {
|
||||
describe("computeEpisodeCorrelation — contamination-guard read window", () => {
|
||||
it("never queries baseline rows on or after the pre-onset lookback start", async () => {
|
||||
rollup.probeRollupCoverage.mockResolvedValue(
|
||||
new Map<string, boolean>(ILLNESS_SCAN_TYPES.map((t) => [String(t), false])),
|
||||
new Map<string, boolean>(
|
||||
ILLNESS_SCAN_TYPES.map((t) => [String(t), false]),
|
||||
),
|
||||
);
|
||||
rollup.readBestGranularityRollups.mockResolvedValue(null);
|
||||
const seen: Array<{ gte: Date; lt?: Date }> = [];
|
||||
db.measurement.findMany.mockImplementation(
|
||||
async ({ where }: { where: { type: string; measuredAt: { gte: Date; lt?: Date } } }) => {
|
||||
async ({
|
||||
where,
|
||||
}: {
|
||||
where: { type: string; measuredAt: { gte: Date; lt?: Date } };
|
||||
}) => {
|
||||
if (where.type === "RESTING_HEART_RATE") seen.push(where.measuredAt);
|
||||
return [];
|
||||
},
|
||||
|
||||
@@ -24,11 +24,18 @@ import {
|
||||
const NOW = new Date("2026-02-01T00:00:00Z");
|
||||
|
||||
/** Build a flat baseline series of `days` days at `value`, ending `endDay`. */
|
||||
function flatBaseline(value: number, days: number, endDay: string): VitalDayPoint[] {
|
||||
function flatBaseline(
|
||||
value: number,
|
||||
days: number,
|
||||
endDay: string,
|
||||
): VitalDayPoint[] {
|
||||
const out: VitalDayPoint[] = [];
|
||||
let cursor = Date.parse(`${endDay}T00:00:00Z`);
|
||||
for (let i = 0; i < days; i++) {
|
||||
out.unshift({ day: new Date(cursor).toISOString().slice(0, 10), mean: value });
|
||||
out.unshift({
|
||||
day: new Date(cursor).toISOString().slice(0, 10),
|
||||
mean: value,
|
||||
});
|
||||
cursor -= 24 * 60 * 60 * 1000;
|
||||
}
|
||||
return out;
|
||||
@@ -39,16 +46,30 @@ function flatBaseline(value: number, days: number, endDay: string): VitalDayPoin
|
||||
* is non-zero and stable. Means cycle through `center − jitter … center +
|
||||
* jitter` so the median is `center` and the MAD is ~`jitter/2`.
|
||||
*/
|
||||
function jitteredBaseline(center: number, jitter: number, days: number, endDay: string): VitalDayPoint[] {
|
||||
function jitteredBaseline(
|
||||
center: number,
|
||||
jitter: number,
|
||||
days: number,
|
||||
endDay: string,
|
||||
): VitalDayPoint[] {
|
||||
const base = flatBaseline(center, days, endDay);
|
||||
const offsets = [-jitter, -jitter / 2, 0, jitter / 2, jitter];
|
||||
return base.map((p, i) => ({ ...p, mean: center + offsets[i % offsets.length] }));
|
||||
return base.map((p, i) => ({
|
||||
...p,
|
||||
mean: center + offsets[i % offsets.length],
|
||||
}));
|
||||
}
|
||||
|
||||
function input(over: Partial<IllnessCorrelationInput>): IllnessCorrelationInput {
|
||||
function input(
|
||||
over: Partial<IllnessCorrelationInput>,
|
||||
): IllnessCorrelationInput {
|
||||
return {
|
||||
episodeId: "ep1",
|
||||
window: { onsetDay: "2026-01-10", feltBetterDay: "2026-01-17", lifecycle: "ACUTE" },
|
||||
window: {
|
||||
onsetDay: "2026-01-10",
|
||||
feltBetterDay: "2026-01-17",
|
||||
lifecycle: "ACUTE",
|
||||
},
|
||||
series: [],
|
||||
source: "DAY",
|
||||
now: NOW,
|
||||
@@ -60,7 +81,8 @@ describe("computeIllnessCorrelation — coverage gate", () => {
|
||||
it("returns insufficient with no baselined vitals", () => {
|
||||
const out = computeIllnessCorrelation(input({ series: [] }));
|
||||
expect(out.status).toBe("insufficient");
|
||||
if (out.status === "insufficient") expect(out.reason).toBe("no_baselined_vitals");
|
||||
if (out.status === "insufficient")
|
||||
expect(out.reason).toBe("no_baselined_vitals");
|
||||
});
|
||||
|
||||
it("returns insufficient when a vital lacks the min baseline days", () => {
|
||||
@@ -164,7 +186,11 @@ describe("computeIllnessCorrelation — golden recovery-gap", () => {
|
||||
];
|
||||
const out = computeIllnessCorrelation(
|
||||
input({
|
||||
window: { onsetDay: "2026-01-10", feltBetterDay: "2026-01-15", lifecycle: "CHRONIC_ONGOING" },
|
||||
window: {
|
||||
onsetDay: "2026-01-10",
|
||||
feltBetterDay: "2026-01-15",
|
||||
lifecycle: "CHRONIC_ONGOING",
|
||||
},
|
||||
series: [{ type, baselineDays, episodeDays }],
|
||||
}),
|
||||
);
|
||||
@@ -185,7 +211,11 @@ describe("computeIllnessCorrelation — golden recovery-gap", () => {
|
||||
];
|
||||
const out = computeIllnessCorrelation(
|
||||
input({
|
||||
window: { onsetDay: "2026-01-10", feltBetterDay: null, lifecycle: "ACUTE" },
|
||||
window: {
|
||||
onsetDay: "2026-01-10",
|
||||
feltBetterDay: null,
|
||||
lifecycle: "ACUTE",
|
||||
},
|
||||
series: [{ type, baselineDays, episodeDays }],
|
||||
}),
|
||||
);
|
||||
@@ -354,7 +384,9 @@ describe("computeIllnessCorrelation — red-flag escalation", () => {
|
||||
);
|
||||
expect(out.status).toBe("ok");
|
||||
if (out.status !== "ok") return;
|
||||
const fever = out.value.redFlags.find((f) => f.reason === "sustained_fever");
|
||||
const fever = out.value.redFlags.find(
|
||||
(f) => f.reason === "sustained_fever",
|
||||
);
|
||||
expect(fever).toBeDefined();
|
||||
expect(fever?.days).toBe(3);
|
||||
expect(fever?.worstValue).toBe(39.2);
|
||||
@@ -391,7 +423,9 @@ describe("computeIllnessCorrelation — red-flag escalation", () => {
|
||||
);
|
||||
expect(out.status).toBe("ok");
|
||||
if (out.status !== "ok") return;
|
||||
const fever = out.value.redFlags.find((f) => f.reason === "sustained_fever");
|
||||
const fever = out.value.redFlags.find(
|
||||
(f) => f.reason === "sustained_fever",
|
||||
);
|
||||
expect(fever).toBeDefined();
|
||||
expect(fever?.days).toBe(3);
|
||||
});
|
||||
@@ -418,7 +452,11 @@ describe("computeIllnessCorrelation — return anchor", () => {
|
||||
];
|
||||
const out = computeIllnessCorrelation(
|
||||
input({
|
||||
window: { onsetDay: "2026-01-10", feltBetterDay: "2026-01-15", lifecycle: "ACUTE" },
|
||||
window: {
|
||||
onsetDay: "2026-01-10",
|
||||
feltBetterDay: "2026-01-15",
|
||||
lifecycle: "ACUTE",
|
||||
},
|
||||
series: [{ type, baselineDays, episodeDays }],
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -114,7 +114,12 @@ describe("upsertIllnessDayLog", () => {
|
||||
|
||||
it("reports inserted (existed=false) on a fresh row", async () => {
|
||||
db.illnessDayLog.findUnique.mockResolvedValue(null);
|
||||
const result = await upsertIllnessDayLog("u1", "ep1", base, "Europe/Berlin");
|
||||
const result = await upsertIllnessDayLog(
|
||||
"u1",
|
||||
"ep1",
|
||||
base,
|
||||
"Europe/Berlin",
|
||||
);
|
||||
expect(result.existed).toBe(false);
|
||||
const args = db.illnessDayLog.upsert.mock.calls[0][0];
|
||||
expect(args.where).toEqual({
|
||||
@@ -143,7 +148,12 @@ describe("upsertIllnessDayLog", () => {
|
||||
noteEncrypted: null,
|
||||
});
|
||||
// Only fever supplied — functionalImpact must keep the stored 3.
|
||||
await upsertIllnessDayLog("u1", "ep1", { date: "2026-06-16", feverC: 37 }, null);
|
||||
await upsertIllnessDayLog(
|
||||
"u1",
|
||||
"ep1",
|
||||
{ date: "2026-06-16", feverC: 37 },
|
||||
null,
|
||||
);
|
||||
const args = db.illnessDayLog.upsert.mock.calls[0][0];
|
||||
expect(args.update.functionalImpact).toBe(3);
|
||||
expect(args.update.feverC).toBe(37);
|
||||
|
||||
@@ -28,7 +28,13 @@ describe("summarizeIllnessRetrospective", () => {
|
||||
it("counts episodes, resolved, by-month, by-type", () => {
|
||||
const out = summarizeIllnessRetrospective([
|
||||
ep({ id: "a", onsetDay: "2026-01-05", type: "INFECTION" }),
|
||||
ep({ id: "b", onsetDay: "2026-11-20", type: "INFECTION", resolved: false, recoveryGapDays: null }),
|
||||
ep({
|
||||
id: "b",
|
||||
onsetDay: "2026-11-20",
|
||||
type: "INFECTION",
|
||||
resolved: false,
|
||||
recoveryGapDays: null,
|
||||
}),
|
||||
ep({ id: "c", onsetDay: "2026-11-02", type: "ALLERGY" }),
|
||||
]);
|
||||
expect(out.episodeCount).toBe(3);
|
||||
|
||||
@@ -94,7 +94,9 @@ describe("notifySafetyFloor", () => {
|
||||
it("stamps the ledger anchor (keyed by reason) before dispatching", async () => {
|
||||
await notifySafetyFloor({ userId: "u9", decision: bpHigh });
|
||||
expect(createMock).toHaveBeenCalledTimes(1);
|
||||
expect(createMock.mock.calls[0][0].data.reason).toContain("bp_hypertensive");
|
||||
expect(createMock.mock.calls[0][0].data.reason).toContain(
|
||||
"bp_hypertensive",
|
||||
);
|
||||
expect(createMock.mock.calls[0][0].data.eventType).toBe("SYSTEM_ALERT");
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user