From c2133203fbb81207bad73718e73a13e38967000f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Tue, 20 Oct 2026 06:06:24 +0200 Subject: [PATCH] test(google-health): hold the parked walk to the consecutive-attempt rule A day that brings one more page is progress, so the walk parks again and counts afresh; only a day that ends at the same edge ends it. --- ...gle-health-backfill-progress-bound.test.ts | 48 +++++++++++++------ 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/tests/integration/google-health-backfill-progress-bound.test.ts b/tests/integration/google-health-backfill-progress-bound.test.ts index 1d7b5b604..ac40e43d1 100644 --- a/tests/integration/google-health-backfill-progress-bound.test.ts +++ b/tests/integration/google-health-backfill-progress-bound.test.ts @@ -331,7 +331,7 @@ describe("Google Health backfill bounded by progress, not pages (#1220)", () => expect(fake.heartRateRequests).toBeLessThanOrEqual(10 + 2 * slices); }, 600_000); - it("parks a walk Google keeps answering with the same page, tries it again a day later, and only then ends it", async () => { + it("parks a walk Google keeps answering with the same page, and ends it only after a day brings no progress", async () => { await seed({ total: 5_000, spacing: 60_000, perPage: 1000 }); fake.loop = true; const { GOOGLE_HEALTH_NO_PROGRESS_PAGES } = @@ -339,6 +339,21 @@ describe("Google Health backfill bounded by progress, not pages (#1220)", () => const { googleHealthBackfillEndedList } = await import("@/lib/google-health/backfill-progress"); const walk = 1 + GOOGLE_HEALTH_NO_PROGRESS_PAGES; + const prisma = getPrismaClient(); + /** Let a day pass for the parked walk. */ + const dayLater = async () => { + const progress = (await connection()).backfillProgress as { + ended: Record; + }; + progress.ended.fetchHeartRate!.endedAt = new Date( + Date.now() - 25 * HOUR, + ).toISOString(); + await prisma.googleHealthConnection.update({ + where: { userId: USER }, + data: { backfillProgress: progress }, + }); + return progress.ended.fetchHeartRate!; + }; // First attempt: the first page and the twenty that repeat it. Not // complete, nothing published, and the next slice a day out. @@ -354,23 +369,26 @@ describe("Google Health backfill bounded by progress, not pages (#1220)", () => expect(fake.heartRateRequests).toBe(walk); expect((await connection()).backfillCompletedAt).toBeNull(); - // A day later the walk goes on from its edge, gets one page further, - // meets the same wall, and this time the history ends there. - const prisma = getPrismaClient(); - const progress = c.backfillProgress as { - ended: Record; - }; - progress.ended.fetchHeartRate!.endedAt = new Date( - Date.now() - 25 * HOUR, - ).toISOString(); - await prisma.googleHealthConnection.update({ - where: { userId: USER }, - data: { backfillProgress: progress }, - }); + // A day later the walk goes on from its edge and gets one page further + // before the wall. That is progress: it parks again, counting afresh, + // rather than ending a history that is still coming in. + expect((await dayLater()).attempts ?? 1).toBe(1); await runChain(5, sent.slices.at(-1)!); - expect(fake.heartRateRequests).toBe(2 * walk); c = await connection(); + expect(c.backfillCompletedAt).toBeNull(); + expect(await pulseRows()).toBe(1999); + expect((await dayLater()).attempts ?? 1).toBe(1); + + // Another day, and nothing lies past the edge any more: the walk meets + // the wall where it stood, and this time the history ends there. + fake.total = 1999; + await runChain(5, sent.slices.at(-1)!); + // No page of this attempt is new, the first included. + expect(fake.heartRateRequests).toBe( + 2 * walk + GOOGLE_HEALTH_NO_PROGRESS_PAGES, + ); + c = await connection(); expect(c.backfillCompletedAt).toBeInstanceOf(Date); expect(googleHealthBackfillEndedList(c.backfillProgress)).toEqual([ {