feat: lay down the shared v1.42 contract

Land every file the v1.42 work shares before any of it is built, so the
parts built side by side never edit the same file.

Schema and migrations 0379-0386: the HEALTH_CONNECT measurement source,
ImportJob.kind, the air-quality columns and the per-user switch on the
environment tables, sealed environment locations with nullable plaintext,
managed-profile handover links, the per-type HealthKit arrival ledger, lab
unit-conversion provenance, and user-defined vaccines. Every new column is
annotated for the column-reader sweep.

HEALTH_CONNECT reaches every exhaustive list: the source labels, the
read enum (not the write allowlist), the source-priority ladder cap, now
the number of sources rather than a fixed eight, and the write-path smoke
test. RMSSD gets its own priority class and a 300 ms ceiling. The batch
syncTrigger gains `manual`, with its label on the Apple Health card.

Queues for the Health Connect import, the compaction-tombstone purge and
the measurement-table maintenance are registered with stub handlers;
host-metric sampling moves to every five minutes. Environment and work_mem
variables reach the compose whitelist, the production example and the
manifest. The proxy admits the handover link and redirects it at the edge,
and the Health Connect upload bypasses the proxy body limit.

The new routes answer 501 behind their final authentication and are
published in the contract; backup, wipe and key rotation classify the new
models and columns; the seven message bundles carry the base copy. Guards
that list release-pending keys and columns fail once an entry is wired, so
those lists empty themselves before the tag.

Also re-anchor a login-throttle fixture to the wall clock, where its
expiry is compared, and re-base the aggregate bundle cap on a measured
12 KB of new locale strings.
This commit is contained in:
Marc-André Bombeck committed 2026-10-08 07:56:59 +02:00
1 parent 125b15bfb7
commit e63be67b5a
82 files changed
+5099 -727

No files matched your search

@@ -11,6 +11,7 @@ import {
parseSourcePriority,
sourcePrioritySchema,
} from "../source-priority";
import { measurementSourceEnum } from "../measurement";
/**
* v1.4.25 W5e — per-user, per-metric-class source-priority foundation.
@@ -116,21 +117,17 @@ describe("sourcePrioritySchema", () => {
expect(result.success).toBe(false);
});
it("rejects more than 8 sources in a single metric class", () => {
const result = sourcePrioritySchema.safeParse({
weight: [
"WITHINGS",
"APPLE_HEALTH",
"MANUAL",
"IMPORT",
"WITHINGS",
"APPLE_HEALTH",
"MANUAL",
"IMPORT",
"WITHINGS",
],
});
expect(result.success).toBe(false);
// The cap is the number of sources: every source may be ranked once (a
// ladder that ranks all sixteen is valid), and one entry more is refused.
it("accepts a ladder that ranks every source, and rejects one entry more", () => {
const every = [...measurementSourceEnum.options];
expect(every.length).toBeGreaterThan(8);
expect(sourcePrioritySchema.safeParse({ weight: every }).success).toBe(
true,
);
expect(
sourcePrioritySchema.safeParse({ weight: [...every, "MANUAL"] }).success,
).toBe(false);
});
it("rejects a non-array value for a metric class", () => {
+47 -6
View File
@@ -1091,6 +1091,10 @@ const labResultBackupSchema = z
sourceReferenceLow: z.number().nullable().optional(),
sourceReferenceHigh: z.number().nullable().optional(),
sourceReferenceText: z.string().nullable().optional(),
// v1.42 (#1095) — the value and unit as printed, kept beside a converted
// reading. Optional: absent on every file written before the columns.
sourceValue: z.number().nullable().optional(),
sourceUnit: z.string().nullable().optional(),
takenAt: isoDateTime,
source: z.string().min(1),
biomarkerName: z.string().nullable().optional(),
@@ -1112,6 +1116,8 @@ const biomarkerBackupSchema = z
upperBound: z.number().nullable().optional(),
panel: z.string().nullable().optional(),
hidden: z.boolean().optional(),
// v1.42 (#1095) — the catalogue analyte the marker resolves to.
analyteKey: z.string().nullable().optional(),
context: z.string().nullable().optional(),
createdAt: isoDateTime.optional(),
updatedAt: isoDateTime.optional(),
@@ -1293,6 +1299,9 @@ const vaccinationBackupSchema = z
// Remapped against the restored reminders (they travel since v1.37.20);
// dropped to NULL, with the drop named, only when the file lacks the row.
reminderId: z.string().nullable().optional(),
// v1.42 (#1005) — the person's own vaccine definition the dose names;
// remapped against the restored definitions like `reminderId`.
customVaccineId: z.string().nullable().optional(),
// Ciphertext on a disaster-recovery file, readable on a portable one.
noteEncrypted: base64BytesSchema.nullable().optional(),
note: z.string().nullable().optional(),
@@ -1421,9 +1430,12 @@ const environmentDayKey = z.string().regex(/^\d{4}-\d{2}-\d{2}$/, {
const environmentContextBackupSchema = z
.object({
date: environmentDayKey,
lat: z.number(),
lon: z.number(),
locationLabel: z.string(),
// Nullable since v1.42 (migration 0382): once the encryption backfill has
// run, the location travels sealed in `locationEncrypted` instead.
lat: z.number().nullable(),
lon: z.number().nullable(),
locationLabel: z.string().nullable(),
locationEncrypted: base64BytesSchema.nullable().optional(),
source: z.enum(EnvironmentLocationSource),
tempMin: z.number().nullable().optional(),
tempMax: z.number().nullable().optional(),
@@ -1437,6 +1449,29 @@ const environmentContextBackupSchema = z
humidityMean: z.number().nullable().optional(),
cloudMean: z.number().nullable().optional(),
weatherCode: z.number().int().nullable().optional(),
// v1.42 (#615) — air quality, pollen and UV. Optional throughout.
apparentMax: z.number().nullable().optional(),
pm25Mean: z.number().nullable().optional(),
pm25Max: z.number().nullable().optional(),
pm10Mean: z.number().nullable().optional(),
no2Mean: z.number().nullable().optional(),
so2Mean: z.number().nullable().optional(),
coMean: z.number().nullable().optional(),
o3Max8h: z.number().nullable().optional(),
eaqiMax: z.number().nullable().optional(),
usaqiMax: z.number().nullable().optional(),
uvIndexMax: z.number().nullable().optional(),
dustMax: z.number().nullable().optional(),
aodMax: z.number().nullable().optional(),
pollenAlderMax: z.number().nullable().optional(),
pollenBirchMax: z.number().nullable().optional(),
pollenGrassMax: z.number().nullable().optional(),
pollenMugwortMax: z.number().nullable().optional(),
pollenOliveMax: z.number().nullable().optional(),
pollenRagweedMax: z.number().nullable().optional(),
aqDomain: z.string().nullable().optional(),
aqHours: z.number().int().nullable().optional(),
aqFetchedAt: isoDateTime.nullable().optional(),
fetchedAt: isoDateTime.optional(),
createdAt: isoDateTime.optional(),
updatedAt: isoDateTime.optional(),
@@ -1452,9 +1487,11 @@ const environmentTravelLocationBackupSchema = z
.object({
startDate: environmentDayKey,
endDate: environmentDayKey,
lat: z.number(),
lon: z.number(),
label: z.string(),
// Nullable since v1.42 (migration 0382), as above.
lat: z.number().nullable(),
lon: z.number().nullable(),
label: z.string().nullable(),
locationEncrypted: base64BytesSchema.nullable().optional(),
createdAt: isoDateTime.optional(),
updatedAt: isoDateTime.optional(),
})
@@ -1903,6 +1940,10 @@ const accountSettingsBackupSchema = z
homeLabel: z.string().nullable().optional(),
homeTimezone: z.string().nullable().optional(),
homeSince: isoDateTime.nullable().optional(),
// v1.42 (#615) — the sealed home location rides a disaster-recovery file
// as ciphertext; a portable file carries the readable home above.
homeLocationEncrypted: base64BytesSchema.nullable().optional(),
environmentAirQualityEnabled: z.boolean().optional(),
timezone: z.string().optional(),
locale: z.string().nullable().optional(),
unitPreference: z.string().nullable().optional(),
+10 -4
View File
@@ -234,6 +234,12 @@ export const measurementSourceEnum = z.enum([
// above these rows stay value-editable; see
// `USER_CORRECTABLE_MEASUREMENT_SOURCES`.
"EXTERNAL",
// v1.42 — rows imported from an Android Health Connect export (#972).
// Server-owned: only the Health Connect import worker writes them, so the
// value is deliberately absent from `WRITABLE_MEASUREMENT_SOURCES` and the
// batch allowlist, like IMPORT. Part of this enum so the read/response
// shapes (and the iOS decoder) can decode the rows it surfaces.
"HEALTH_CONNECT",
]);
/**
@@ -602,10 +608,10 @@ export const VALUE_RANGES: Record<string, { min: number; max: number }> = {
STRESS_SCORE: { min: 0, max: 100 },
STRAIN_SCORE: { min: 0, max: 100 },
// ── v1.11.0 — WHOOP-native score classes ──
// RMSSD HRV (ms). Same plausibility band as the SDNN variant: lows reach
// single digits in stressed samples, 200 ms is a generous upper bound for
// relaxed athletic windows.
HRV_RMSSD: { min: 1, max: 200 },
// RMSSD HRV (ms). Lows reach single digits in stressed samples. RMSSD runs
// higher than SDNN in relaxed, well-trained sleepers, and nightly readings
// above 200 ms are real (#1110), so the ceiling sits at 300 ms.
HRV_RMSSD: { min: 1, max: 300 },
// Day / workout strain on WHOOP's bounded 0–21 scale.
DAY_STRAIN: { min: 0, max: 21 },
WORKOUT_STRAIN: { min: 0, max: 21 },
+14 -3
View File
@@ -94,10 +94,14 @@ export type DeviceType = z.infer<typeof deviceTypeEnum>;
* keys; lifted into a nested object so the schema has room for the new
* `deviceTypePriority` sibling without clobbering the metric keys.
*
* The 8-entry cap is a sanity bound (we have 4 sources today, the cap
* leaves headroom without inviting a megabyte-blob payload).
* The cap is the number of `MeasurementSource` values: a ladder may rank
* every source once, and no more. A fixed 8 stopped fitting once the
* longest default ladders reached eight entries and a ninth source
* (Health Connect, v1.42) had to be sortable into them.
*/
const metricSourceLadder = z.array(measurementSourceEnum).max(8);
const metricSourceLadder = z
.array(measurementSourceEnum)
.max(measurementSourceEnum.options.length);
/**
* Metric-class keys carried by `SourcePriority`. Listed once here so
@@ -144,6 +148,10 @@ export const SOURCE_PRIORITY_METRIC_KEYS = [
// Laddering it now keeps the picker deterministic — and the choice user-
// configurable, not WHOOP-hardcoded — the instant a native producer lands.
"sleepDebt",
// v1.42 (#1110) — RMSSD HRV as its own class. WHOOP, Oura and Polar report
// RMSSD natively, Apple Health relays it from third-party apps; SDNN keeps
// the `hrv` ladder, since the two measures are not interchangeable.
"hrvRmssd",
] as const;
export type SourcePriorityMetricKey =
@@ -395,6 +403,9 @@ export const DEFAULT_SOURCE_PRIORITY: Required<MetricPriority> = {
// rolling-balance debt; the COMPUTED engine is the fallback every user lands
// on now. Mirrors the recovery ladder's native-above-computed ordering.
sleepDebt: ["WHOOP", "OURA", "POLAR", "COMPUTED"],
// v1.42 (#1110) — the straps and rings that measure RMSSD overnight lead;
// the HealthKit relay of a third-party reading is the fallback.
hrvRmssd: ["WHOOP", "OURA", "POLAR", "APPLE_HEALTH"],
};
/**