From ef36a6a81f0a17866b63214b9d39d7db9eb54d55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Sun, 14 Jun 2026 20:59:58 +0200 Subject: [PATCH] Cover Polar and Oura sync queues in the dead-queue guard Only the Nightscout sync queue was asserted in allQueues; the two OAuth- wearable polls shipped alongside it carry the same v1.4.37 dead-queue risk. Assert POLAR_SYNC_QUEUE and OURA_SYNC_QUEUE membership, cron, and handler wiring so a future refactor can't silently drop one. --- .../jobs/__tests__/nightscout-queues.test.ts | 50 ++++++++++++++++--- 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/src/lib/jobs/__tests__/nightscout-queues.test.ts b/src/lib/jobs/__tests__/nightscout-queues.test.ts index 35f8170d8..d0bb5b0f4 100644 --- a/src/lib/jobs/__tests__/nightscout-queues.test.ts +++ b/src/lib/jobs/__tests__/nightscout-queues.test.ts @@ -1,15 +1,13 @@ /** - * v1.17.0 — pg-boss queue registration for the Nightscout CGM sync layer. + * v1.17.0 — pg-boss queue registration for the three new poll-only sync layers: + * Nightscout CGM, Polar, and Oura. * * Source-as-text guard (the reminder-worker pulls heavy infra we don't boot - * here): assert the queue constant + cron + handler wiring + allQueues + * here): assert each queue constant + cron + handler wiring + allQueues * membership are present — the fast guard against the v1.4.37 dead-queue class * (a queue declared but never registered in `allQueues`, which silently never - * drains). - * - * Nightscout is poll-only (no webhook, no OAuth, no backfill queue): a single - * hourly `nightscout-sync` tick walks every configured instance via - * `syncUserNightscout`. + * drains). All three syncs are poll-only (no webhook, no backfill queue): a + * single hourly tick walks every configured account. */ import { readFileSync } from "node:fs"; import { join } from "node:path"; @@ -45,3 +43,41 @@ describe("reminder-worker — Nightscout sync queue", () => { ); }); }); + +describe("reminder-worker — Polar / Oura sync queues", () => { + // The same v1.4.37 dead-queue class applies to the two OAuth-wearable polls + // shipped alongside Nightscout in v1.17.0 — assert their allQueues membership + // so a future refactor can't silently drop one and starve the sync. + const allQueuesBlock = () => { + const block = /const allQueues = \[([\s\S]*?)\];/.exec(source); + expect(block).not.toBeNull(); + return block![1]!; + }; + + it("declares the polar-sync and oura-sync queue constants", () => { + expect(source).toMatch(/POLAR_SYNC_QUEUE\s*=\s*["']polar-sync["']/); + expect(source).toMatch(/OURA_SYNC_QUEUE\s*=\s*["']oura-sync["']/); + }); + + it("registers POLAR_SYNC_QUEUE in allQueues (v1.4.37 dead-queue guard)", () => { + expect(allQueuesBlock()).toContain("POLAR_SYNC_QUEUE"); + }); + + it("registers OURA_SYNC_QUEUE in allQueues (v1.4.37 dead-queue guard)", () => { + expect(allQueuesBlock()).toContain("OURA_SYNC_QUEUE"); + }); + + it("schedules the hourly poll cron for both", () => { + expect(source).toMatch(/\[POLAR_SYNC_QUEUE,\s*POLAR_SYNC_CRON\]/); + expect(source).toMatch(/\[OURA_SYNC_QUEUE,\s*OURA_SYNC_CRON\]/); + }); + + it("registers a boss.work handler for each queue", () => { + expect(source).toMatch( + /boss\.work[\s\S]{0,160}POLAR_SYNC_QUEUE[\s\S]{0,160}handlePolarSync/, + ); + expect(source).toMatch( + /boss\.work[\s\S]{0,160}OURA_SYNC_QUEUE[\s\S]{0,160}handleOuraSync/, + ); + }); +});