Files
HealthLog/src/lib/ai/__tests__/effective-timeout.test.ts
T
Marc-André Bombeck 6d250d092d fix(insights): wait as long as the response timeout allows in the browser
The regenerate button aborted its inline POST after a fixed 45 s, so on a
slow local model every regenerate was cut while the server still had
minutes left on the person's setting. It now uses clientAbortMs over the
route's sequential model calls, never less per call than the briefing's
own 180 s default, because the published value cannot say whether the
person set it.

A save of the about-me self-context derives the clarifying questions
inline and ran under the 15 s request default, which reported a failed
save while the server went on to commit it. All six save sites now take
their abort from the same setting. Every other browser request that waits
on a model either has no client timeout or only queues the work.

Refs #1267
2026-10-22 13:01:20 +02:00

57 lines
1.9 KiB
TypeScript

import { describe, it, expect } from "vitest";
import {
CLIENT_ABORT_MARGIN_MS,
clientAbortMs,
PROVIDER_DEFAULT_TIMEOUT_MS,
resolveEffectiveTimeoutMs,
} from "../effective-timeout";
const BUDGET = 120_000;
describe("resolveEffectiveTimeoutMs", () => {
it("converts a positive per-user setting from seconds to ms", () => {
expect(resolveEffectiveTimeoutMs(300, BUDGET)).toBe(300_000);
expect(resolveEffectiveTimeoutMs(10, BUDGET)).toBe(10_000);
});
it("falls back to the budget default when the setting is unset", () => {
expect(resolveEffectiveTimeoutMs(null, BUDGET)).toBe(BUDGET);
expect(resolveEffectiveTimeoutMs(undefined, BUDGET)).toBe(BUDGET);
});
it("falls back to the budget default for a non-positive value", () => {
expect(resolveEffectiveTimeoutMs(0, BUDGET)).toBe(BUDGET);
expect(resolveEffectiveTimeoutMs(-5, BUDGET)).toBe(BUDGET);
});
it("honours different budget defaults per surface", () => {
expect(resolveEffectiveTimeoutMs(null, 60_000)).toBe(60_000);
expect(resolveEffectiveTimeoutMs(45, 60_000)).toBe(45_000);
});
});
describe("clientAbortMs (#1267)", () => {
it("waits the published setting per call plus the margin", () => {
expect(clientAbortMs(600_000, 2)).toBe(
2 * 600_000 + CLIENT_ABORT_MARGIN_MS,
);
});
it("never waits less per call than the route's own longer default", () => {
// 60 s is what the payload publishes when nothing is set; the briefing
// route gives each call 180 s then.
expect(clientAbortMs(60_000, 2, 180_000)).toBe(
2 * 180_000 + CLIENT_ABORT_MARGIN_MS,
);
expect(clientAbortMs(600_000, 2, 180_000)).toBe(
2 * 600_000 + CLIENT_ABORT_MARGIN_MS,
);
});
it("reads a missing value as the provider default", () => {
expect(clientAbortMs(undefined, 1)).toBe(
PROVIDER_DEFAULT_TIMEOUT_MS + CLIENT_ABORT_MARGIN_MS,
);
});
});