mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-18 16:12:11 +00:00
fix(insights): scope generation guard to prompt fields, clear cache on restore
This commit is contained in:
1 parent
666a85d311
commit
3aff2c16db
104 files changed
+8082
-651
No files matched your search
@@ -299,14 +299,16 @@ describe("every backed-up model travels both ways, or is named as debt", () => {
|
||||
).toEqual([]);
|
||||
});
|
||||
|
||||
it("proves the two named this release are on the covered side", () => {
|
||||
// Prerequisites for the structured-profile work: both were classified
|
||||
// BACKED_UP and carried by nothing, and the custom metric was live loss.
|
||||
it("proves the structured-profile models are on the covered side", () => {
|
||||
// These account-owned rows are exported and restored explicitly rather
|
||||
// than being treated as reconstructible data.
|
||||
for (const model of [
|
||||
"UserHealthProfile",
|
||||
"HealthProfileFactRevision",
|
||||
"CustomMetric",
|
||||
"CustomMetricEntry",
|
||||
]) {
|
||||
expect(BACKED_UP_MODELS).toContain(model);
|
||||
expect(TWO_ENDED_MODELS).toContain(model);
|
||||
expect(COVERAGE_PENDING).not.toHaveProperty(model);
|
||||
}
|
||||
|
||||
@@ -118,6 +118,10 @@ describe("data-wipe completeness", () => {
|
||||
).toContain("CoachConversation");
|
||||
});
|
||||
|
||||
it("wipes effective-dated health profile fact revisions", () => {
|
||||
expect(WIPE_MODELS).toContain("HealthProfileFactRevision");
|
||||
});
|
||||
|
||||
it("every model with a userId column is wiped or exempt with a reason", () => {
|
||||
const userScoped = [...models]
|
||||
.filter(([, shape]) => shape.scalars.includes("userId"))
|
||||
|
||||
@@ -372,6 +372,12 @@ const REGISTRY: DestructiveEntry[] = [
|
||||
recovery: "tombstoned-no-restore",
|
||||
confirm: ["DeleteButton"],
|
||||
},
|
||||
{
|
||||
file: "components/records/health-profile-facts-manager.tsx",
|
||||
destroys: "the current value of one effective-dated health-profile fact",
|
||||
recovery: "tombstoned-no-restore",
|
||||
confirm: ["ConfirmButton"],
|
||||
},
|
||||
{
|
||||
file: "hooks/use-measurement-reminders.ts",
|
||||
destroys: "a checkup or measurement reminder with its schedule",
|
||||
|
||||
@@ -74,9 +74,9 @@ describe("report scope gating — structural guard", () => {
|
||||
it("reads a plausible catalogue", () => {
|
||||
// Sanity floor: a silently degraded catalogue would pass everything below
|
||||
// vacuously.
|
||||
expect(ALL_LEAF_IDS.length).toBe(90);
|
||||
expect(ALL_LEAF_IDS.length).toBe(91);
|
||||
expect(Object.keys(MEASUREMENT_LEAF_GROUP)).toHaveLength(77);
|
||||
expect(Object.keys(STRUCTURED_LEAF_GROUP)).toHaveLength(13);
|
||||
expect(Object.keys(STRUCTURED_LEAF_GROUP)).toHaveLength(14);
|
||||
});
|
||||
|
||||
it("places every leaf in exactly one group", () => {
|
||||
@@ -136,6 +136,7 @@ describe("report scope gating — structural guard", () => {
|
||||
it("keeps every sensitive leaf in the fenced tier", () => {
|
||||
for (const leaf of [
|
||||
"MOOD",
|
||||
"ANAMNESIS",
|
||||
"CYCLE",
|
||||
"FAMILY_HISTORY",
|
||||
"PHQ9_SCORE",
|
||||
|
||||
@@ -37,6 +37,13 @@ const BACKUP_BUILDER = join(
|
||||
"export",
|
||||
"full-backup-payload.ts",
|
||||
);
|
||||
const PROFILE_BACKUP_BUILDER = join(
|
||||
ROOT,
|
||||
"src",
|
||||
"lib",
|
||||
"export",
|
||||
"profile-backup.ts",
|
||||
);
|
||||
|
||||
/**
|
||||
* Columns the backup is correct to omit, each with the reason.
|
||||
@@ -110,6 +117,26 @@ function serialisedFields(source: string): Set<string> {
|
||||
);
|
||||
}
|
||||
|
||||
function interfaceFields(source: string, name: string): Set<string> {
|
||||
const start = source.indexOf(`export interface ${name} {`);
|
||||
expect(start, `interface ${name} not found`).toBeGreaterThan(-1);
|
||||
const end = source.indexOf("\n}", start);
|
||||
expect(end).toBeGreaterThan(start);
|
||||
return new Set(
|
||||
[...source.slice(start, end).matchAll(/^ {2}([a-zA-Z_$][\w$]*)[?:]/gm)].map(
|
||||
(match) => match[1],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
function emittedModelFields(source: string, variable: string): Set<string> {
|
||||
return new Set(
|
||||
[
|
||||
...source.matchAll(new RegExp(`${variable}\\.([a-zA-Z_$][\\w$]*)`, "g")),
|
||||
].map((match) => match[1]),
|
||||
);
|
||||
}
|
||||
|
||||
describe("measurement backup completeness", () => {
|
||||
const schema = readFileSync(SCHEMA, "utf8");
|
||||
const source = readFileSync(BACKUP_BUILDER, "utf8");
|
||||
@@ -162,3 +189,33 @@ describe("measurement backup completeness", () => {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("health profile backup completeness", () => {
|
||||
const schema = readFileSync(SCHEMA, "utf8");
|
||||
const source = readFileSync(PROFILE_BACKUP_BUILDER, "utf8");
|
||||
const models = declaredModels(schema);
|
||||
const excluded = new Set(["userId"]);
|
||||
|
||||
it.each([
|
||||
["UserHealthProfile", "HealthProfileBackupEntry", "profileRow"],
|
||||
["HealthProfileFactRevision", "HealthProfileFactBackupEntry", "fact"],
|
||||
])(
|
||||
"%s columns are represented and emitted by the profile backup",
|
||||
(model, wireInterface, variable) => {
|
||||
const columns = scalarFields(modelBlock(schema, model), models).filter(
|
||||
(column) => !excluded.has(column),
|
||||
);
|
||||
const wire = interfaceFields(source, wireInterface);
|
||||
const emitted = emittedModelFields(source, variable);
|
||||
|
||||
expect(
|
||||
columns.filter((column) => !wire.has(column)),
|
||||
`${wireInterface} omits stored ${model} columns`,
|
||||
).toEqual([]);
|
||||
expect(
|
||||
columns.filter((column) => !emitted.has(column)),
|
||||
`${model} columns never reach either serialized arm`,
|
||||
).toEqual([]);
|
||||
},
|
||||
);
|
||||
});
|
||||
@@ -436,6 +436,16 @@ const RESULT_SURFACES: ReadonlyArray<{
|
||||
through: /toastWrittenOutcome/,
|
||||
forbidsMarkers: true,
|
||||
},
|
||||
{
|
||||
path: "src/components/records/ai-profile-inclusion-manager.tsx",
|
||||
through: /toastWrittenOutcome/,
|
||||
forbidsMarkers: true,
|
||||
},
|
||||
{
|
||||
path: "src/components/records/health-profile-facts-manager.tsx",
|
||||
through: /toastWrittenOutcome/,
|
||||
forbidsMarkers: true,
|
||||
},
|
||||
];
|
||||
|
||||
/** Code only — a comment naming a marker is prose, not an affordance. */
|
||||
|
||||
@@ -11,9 +11,8 @@
|
||||
*
|
||||
* Google Health broke that rule silently for three releases while the
|
||||
* comment above its type map asserted the opposite, and a user's workout
|
||||
* showed as "Other" with the original nowhere in the database. Three sibling
|
||||
* providers had carried the provenance write the whole time. Nothing
|
||||
* connected them, so nothing noticed.
|
||||
* showed as "Other" with the original nowhere in the database. Other workout
|
||||
* providers carried the provenance write, but nothing connected the paths.
|
||||
*
|
||||
* These are tripwires, not proofs. A grep cannot show that a metadata key
|
||||
* holds the right value — only that a registered ingest still writes one, and
|
||||
@@ -110,29 +109,17 @@ const PROVIDER_INGESTS: ProviderIngest[] = [
|
||||
writeFile: "lib/measurements/import-apple-health-export.ts",
|
||||
metadataKey: "activityType",
|
||||
},
|
||||
{
|
||||
provider: "Fitbit",
|
||||
mapper: "mapFitbitSportType",
|
||||
mapperFile: "lib/fitbit/client.ts",
|
||||
captureFile: "lib/fitbit/client.ts",
|
||||
captureField: "activityName",
|
||||
writeFile: "lib/fitbit/sync-workout.ts",
|
||||
metadataKey: "fitbitActivityName",
|
||||
},
|
||||
];
|
||||
|
||||
/**
|
||||
* Fitbit carries the identical defect Google Health just had: an unmapped
|
||||
* `activityName` collapses to `"other"` and the original is discarded. It is
|
||||
* excluded here deliberately, not overlooked. The standing rule for this
|
||||
* repository is that Fitbit changes ship as small isolated releases with
|
||||
* parity tests against a provider that already works, so it follows this one
|
||||
* rather than riding along inside it — the two providers share no code, so
|
||||
* deferring leaves nothing half-wired.
|
||||
*
|
||||
* The exception is written as an assertion rather than an omission: when
|
||||
* Fitbit gains the provenance write, this test fails and forces the entry to
|
||||
* move up into `PROVIDER_INGESTS`. An exception nobody has to retire is how
|
||||
* the original gap survived.
|
||||
*/
|
||||
const FITBIT_EXCEPTION = {
|
||||
provider: "Fitbit",
|
||||
mapper: "mapFitbitSportType",
|
||||
mapperFile: "lib/fitbit/client.ts",
|
||||
writeFile: "lib/fitbit/sync-workout.ts",
|
||||
} as const;
|
||||
|
||||
/**
|
||||
* Exported helpers whose name ends in `SportType` but which never see an
|
||||
* upstream label — they narrow a value that is already canonical, at read
|
||||
@@ -156,7 +143,6 @@ describe("T1 — the set of sport-label mappers is frozen", () => {
|
||||
|
||||
const registered = [
|
||||
...PROVIDER_INGESTS.map((p) => p.mapper),
|
||||
FITBIT_EXCEPTION.mapper,
|
||||
...READ_TIME_NARROWERS,
|
||||
].sort();
|
||||
|
||||
@@ -166,7 +152,7 @@ describe("T1 — the set of sport-label mappers is frozen", () => {
|
||||
});
|
||||
|
||||
it("each registered mapper lives where the registry says it does", () => {
|
||||
for (const p of [...PROVIDER_INGESTS, FITBIT_EXCEPTION]) {
|
||||
for (const p of PROVIDER_INGESTS) {
|
||||
expect(
|
||||
read(p.mapperFile).includes(`export function ${p.mapper}`),
|
||||
`${p.provider}: ${p.mapper} is no longer declared in ${p.mapperFile}`,
|
||||
@@ -198,7 +184,6 @@ describe("T2 — the set of files writing Workout rows is frozen", () => {
|
||||
|
||||
const expected = [
|
||||
...PROVIDER_INGESTS.map((p) => p.writeFile),
|
||||
FITBIT_EXCEPTION.writeFile,
|
||||
...Object.keys(NON_MAPPING_WRITERS),
|
||||
].sort();
|
||||
|
||||
@@ -230,23 +215,3 @@ describe("T3 — every mapping ingest preserves the raw label", () => {
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe("T4 — Fitbit is the one declared exception", () => {
|
||||
it("still discards its raw activity name, and says so when it stops", () => {
|
||||
const writer = read(FITBIT_EXCEPTION.writeFile);
|
||||
expect(
|
||||
/metadata[,:]/.test(writer),
|
||||
"Fitbit now writes workout metadata — move it into PROVIDER_INGESTS " +
|
||||
"with its provenance key and delete FITBIT_EXCEPTION.",
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("is the only ingest allowed to be non-compliant", () => {
|
||||
const nonCompliant = [
|
||||
...PROVIDER_INGESTS.map((p) => p.writeFile),
|
||||
FITBIT_EXCEPTION.writeFile,
|
||||
].filter((rel) => !/metadata[,:]/.test(read(rel)));
|
||||
|
||||
expect(nonCompliant).toEqual([FITBIT_EXCEPTION.writeFile]);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user