mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-10 05:12:14 +00:00
The no-key and timeout fallback text carried zero reference to the user's own readings and, on a provider timeout, rendered as hasProvider:true — indistinguishable from a fresh assessment. Compose each fallback from the per-metric signal the card already builds: name the current value, place it against the user's own baseline, and close with one plain-language pointer, in the same warm voice as the model surfaces. Degrade to the prior generic tip only when a metric has no usable history. The timeout envelope now reports hasProvider:false so the UI surfaces it as the computed summary it is rather than mislabelling it as provider prose.
29 lines
1.1 KiB
TypeScript
29 lines
1.1 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import { returnTimeoutFallback } from "@/lib/insights/timeout-fallback";
|
|
|
|
describe("returnTimeoutFallback", () => {
|
|
it("reports hasProvider:false so a deterministic fallback is never mislabelled as a fresh AI assessment", () => {
|
|
const result = returnTimeoutFallback({
|
|
cacheAction: "insights.pulse-status.en",
|
|
reason: "timeout",
|
|
stubText: "Your resting pulse is at 72 bpm right now.",
|
|
// No userId/todayKey → no negative-stub write, pure render path.
|
|
});
|
|
expect(result.hasProvider).toBe(false);
|
|
expect(result.cached).toBe(true);
|
|
expect(result.updatedAt).toBeNull();
|
|
expect(result.text).toContain("72 bpm");
|
|
});
|
|
|
|
it("passes the grounded stub text through verbatim on an error", () => {
|
|
const stub = "Your blood pressure is at 128 right now.";
|
|
const result = returnTimeoutFallback({
|
|
cacheAction: "insights.blood-pressure-status.en",
|
|
reason: "error",
|
|
stubText: stub,
|
|
});
|
|
expect(result.text).toBe(stub);
|
|
expect(result.hasProvider).toBe(false);
|
|
});
|
|
});
|