From dead4096c9a6c6287bc7b3bf465a1d4e86e20bc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Wed, 21 Oct 2026 19:52:05 +0200 Subject: [PATCH] test(google-health): pin that the backfill tracks every collection the sync reads --- .../__tests__/backfill-coverage.test.ts | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/lib/google-health/__tests__/backfill-coverage.test.ts diff --git a/src/lib/google-health/__tests__/backfill-coverage.test.ts b/src/lib/google-health/__tests__/backfill-coverage.test.ts new file mode 100644 index 000000000..344afcfc2 --- /dev/null +++ b/src/lib/google-health/__tests__/backfill-coverage.test.ts @@ -0,0 +1,40 @@ +/** + * Every Google Health collection the sync reads is one the backfill tracks. + * + * The backfill walks `GOOGLE_HEALTH_COLLECTION_KEYS` and stamps its marker + * only when each is done or has ended with a reason. A collection the sync + * reads but the key list leaves out would never be backfilled, and the card + * would still say the history finished. Read off the sync modules' own call + * labels so a new collection cannot join the sync without joining this list. + */ +import { readFileSync, readdirSync } from "node:fs"; +import { join } from "node:path"; +import { describe, expect, it } from "vitest"; + +import { GOOGLE_HEALTH_COLLECTION_KEYS } from "../collection-keys"; + +/** Not time series: one profile read each, outside any history walk. */ +const NOT_A_HISTORY = new Set(["fetchProfile", "fetchHeight"]); +/** The sleep walk is tracked under its own key. */ +const ALIASES: Record = { fetchSleep: "sleep" }; + +describe("Google Health backfill coverage", () => { + it("tracks every collection the sync reads", () => { + const dir = join(process.cwd(), "src/lib/google-health"); + const labels = new Set(); + for (const file of readdirSync(dir)) { + if (!/^sync-.*\.ts$/.test(file)) continue; + const src = readFileSync(join(dir, file), "utf8"); + for (const m of src.matchAll(/"(fetch[A-Z][A-Za-z0-9]+)"/g)) { + labels.add(m[1]!); + } + } + expect(labels.size).toBeGreaterThan(10); + const keys = new Set(GOOGLE_HEALTH_COLLECTION_KEYS); + const untracked = [...labels] + .filter((l) => !NOT_A_HISTORY.has(l)) + .map((l) => ALIASES[l] ?? l) + .filter((l) => !keys.has(l)); + expect(untracked).toEqual([]); + }); +});