Files
HealthLog/src/lib/ai/__tests__/json-dialect.test.ts
T
Marc-André Bombeck a0fa4783c0 fix(ai): keep JSON mode when an endpoint rejects only reasoning_effort
An endpoint that does not know reasoning_effort answers with an unknown
parameter error, which the JSON-mode probe read as a refusal of
response_format and switched that base URL to plain prompts.
2026-10-04 10:48:35 +02:00

38 lines
1.1 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { isResponseFormatRejection } from "../json-dialect";
describe("isResponseFormatRejection", () => {
it("reads a complaint about response_format as a JSON-mode rejection", () => {
expect(
isResponseFormatRejection(400, "Unsupported value: 'response_format'"),
).toBe(true);
expect(isResponseFormatRejection(422, "unknown parameter")).toBe(true);
});
it("does not read a complaint about reasoning_effort as one", () => {
expect(
isResponseFormatRejection(
400,
"Unrecognized request argument supplied: reasoning_effort",
),
).toBe(false);
expect(
isResponseFormatRejection(400, "unknown field `reasoning effort`"),
).toBe(false);
});
it("still flips when both fields are named", () => {
expect(
isResponseFormatRejection(
400,
"unknown parameters: response_format, reasoning_effort",
),
).toBe(true);
});
it("ignores server errors", () => {
expect(isResponseFormatRejection(500, "response_format")).toBe(false);
});
});