fix(integrations): surface Google sync progress and canonical workouts

This commit is contained in:
Marc-André Bombeck committed 2026-07-29 15:55:37 +02:00
1 parent b9879e8829
commit 9354c649fe
15 files changed
+604 -67

No files matched your search

@@ -20,6 +20,22 @@ describe("GoogleHealthCard manual-sync terminal contract", () => {
expect(source).toMatch(/partial/);
expect(source).toMatch(/failed/);
expect(source).toMatch(/interrupted/);
expect(source).toContain("google-health-sync-progress");
expect(source).toContain("settings.googleHealthSyncInProgress");
expect(source).toMatch(
/syncProgress\?\.state === "in_progress"[\s\S]{0,180}refreshSyncStatus/,
);
});
it("renders actionable, allowlisted per-resource failure details", () => {
expect(source).toContain("google-health-resource-failures");
expect(source).toContain("failedGoogleHealthResources(syncProgress)");
expect(source).toContain("googleHealthReasonCode(resource)");
expect(source).toContain("settings.googleHealthReason.tokenFailed");
expect(source).toContain("settings.googleHealthReason.upsertFailed");
expect(source).not.toMatch(
/resourceFailureMessage[\s\S]{0,160}(resource\.reasonCode|\$\{[^}]*reasonCode)/,
);
});
it("invalidates every affected client query after a committed workout outcome", () => {
@@ -0,0 +1,53 @@
import { describe, expect, it } from "vitest";
import {
completedGoogleHealthResourceCount,
failedGoogleHealthResources,
googleHealthReasonCode,
readGoogleHealthProgress,
} from "../google-health-progress-view";
describe("Google Health progress view", () => {
it("preserves bounded in-progress resource completion and stable reasons", () => {
const progress = readGoogleHealthProgress({
data: {
state: "in_progress",
imported: 12,
resources: [
{
resource: "workout",
written: 12,
status: "complete",
reasonCode: null,
},
{
resource: "sleep",
written: 0,
status: "failed",
reasonCode: "collection_failed",
},
],
},
});
expect(progress?.state).toBe("in_progress");
expect(progress?.imported).toBe(12);
expect(completedGoogleHealthResourceCount(progress)).toBe(1);
expect(failedGoogleHealthResources(progress)).toHaveLength(1);
expect(
googleHealthReasonCode(failedGoogleHealthResources(progress)[0]),
).toBe("collection_failed");
});
it("rejects unknown run states and does not expose unknown reason codes", () => {
expect(readGoogleHealthProgress({ data: { state: "queued" } })).toBeNull();
expect(
googleHealthReasonCode({
resource: "sleep",
written: 0,
status: "failed",
reasonCode: "raw-provider-secret",
}),
).toBeNull();
});
});
@@ -21,6 +21,51 @@ describe("readSyncOutcome", () => {
).toEqual({ imported: 0, failed: true, outcome: "failed" });
});
it("preserves only bounded, sanitized per-resource outcomes", () => {
expect(
readSyncOutcome({
data: {
imported: 4,
failed: true,
outcome: "partial",
resources: [
{
resource: "Sleep",
written: 4,
status: "partial",
reasonCode: "collection_failed",
},
{
resource: "../raw secret",
written: -4,
status: "failed",
reasonCode: "provider error: token=secret",
},
{ resource: "ignored", status: "unknown" },
],
},
}),
).toEqual({
imported: 4,
failed: true,
outcome: "partial",
resources: [
{
resource: "sleep",
written: 4,
status: "partial",
reasonCode: "collection_failed",
},
{
resource: "-raw-secret",
written: 0,
status: "failed",
reasonCode: null,
},
],
});
});
it("refuses an envelope that carries only the count", () => {
// The pre-fix shape. A card that accepted it would be back to reporting a
// number with no verdict attached.