mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-16 23:33:29 +00:00
fix(integrations): report a page walk that stops short instead of ending quietly
The WHOOP, Oura and Withings list walks and the Fitbit exercise walk each kept a page loop that, at its ceiling or on a cursor that did not advance, returned what it had read and said nothing, and the backfill around it stamped the history complete. `walkPages` keeps a ceiling but reports a walk that stops with a page pending, or on a cursor it already followed, as truncated. A backfill reads that through one verdict: a failure retries, a truncated collection leaves the marker unset without a retry, a clean run stamps it. The Fitbit exercise walk may read a hundred pages during a backfill instead of twelve. A guard keeps page-counting loops out of the provider directories, with Google Health and Strava listed until their next change.
This commit is contained in:
1 parent
0497685db0
commit
483c84b42e
12 files changed
+655
-295
No files matched your search
@@ -0,0 +1,66 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
vi.mock("@/lib/logging/context", () => ({ annotate: vi.fn() }));
|
||||
|
||||
import { backfillVerdict, walkPages, withPageWalkLedger } from "../page-walk";
|
||||
|
||||
describe("walkPages", () => {
|
||||
it("reads until a page has no next", async () => {
|
||||
const walk = await walkPages<number, string>(
|
||||
"test.done",
|
||||
10,
|
||||
async (cursor) => ({
|
||||
items: [`p${cursor ?? 0}`],
|
||||
next: (cursor ?? 0) < 2 ? (cursor ?? 0) + 1 : null,
|
||||
}),
|
||||
);
|
||||
expect(walk).toEqual({
|
||||
items: ["p0", "p1", "p2"],
|
||||
pages: 3,
|
||||
truncated: false,
|
||||
});
|
||||
});
|
||||
|
||||
it("reports a walk that reaches its ceiling with a page pending", async () => {
|
||||
const walk = await walkPages<number, number>(
|
||||
"test.ceiling",
|
||||
4,
|
||||
async (cursor) => ({ items: [cursor ?? 0], next: (cursor ?? 0) + 1 }),
|
||||
);
|
||||
expect(walk.truncated).toBe(true);
|
||||
expect(walk.pages).toBe(4);
|
||||
expect(walk.items).toEqual([0, 1, 2, 3]);
|
||||
});
|
||||
|
||||
it("stops on a cursor it already followed, the first one included", async () => {
|
||||
const fetchPage = vi.fn(async () => ({ items: [1], next: 0 }));
|
||||
const walk = await walkPages<number, number>(
|
||||
"test.repeat",
|
||||
50,
|
||||
fetchPage,
|
||||
0,
|
||||
);
|
||||
expect(walk.truncated).toBe(true);
|
||||
expect(fetchPage).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("withPageWalkLedger and backfillVerdict", () => {
|
||||
it("collects the truncated walks of a run", async () => {
|
||||
const { result, truncated } = await withPageWalkLedger(async () => {
|
||||
await walkPages("b.walk", 1, async () => ({ items: [], next: "x" }));
|
||||
await walkPages("a.walk", 5, async () => ({ items: [], next: null }));
|
||||
return "done";
|
||||
});
|
||||
expect(result).toBe("done");
|
||||
expect(truncated).toEqual(["b.walk"]);
|
||||
});
|
||||
|
||||
it("retries a failure, leaves a truncated history incomplete, stamps a clean one", () => {
|
||||
expect(backfillVerdict({ failed: true, truncated: ["a"] })).toBe("retry");
|
||||
expect(backfillVerdict({ failed: false, truncated: ["a"] })).toBe(
|
||||
"incomplete",
|
||||
);
|
||||
expect(backfillVerdict({ failed: false, truncated: [] })).toBe("complete");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user