mirror of
https://github.com/moltbot/moltbot.git
synced 2026-05-13 23:56:07 +00:00
Merged via squash.
Prepared head SHA: b8b3686445
Co-authored-by: singleGanghood <156392444+singleGanghood@users.noreply.github.com>
Co-authored-by: hxy91819 <8814856+hxy91819@users.noreply.github.com>
Reviewed-by: @hxy91819
39 lines
1.7 KiB
TypeScript
39 lines
1.7 KiB
TypeScript
import type { AssistantMessage } from "@mariozechner/pi-ai";
|
|
import { describe, expect, it } from "vitest";
|
|
import { MALFORMED_STREAMING_FRAGMENT_ERROR_MESSAGE } from "../../shared/assistant-error-format.js";
|
|
import { makeAssistantMessageFixture } from "../test-helpers/assistant-message-fixtures.js";
|
|
import { formatAssistantErrorText } from "./errors.js";
|
|
|
|
describe("formatAssistantErrorText streaming JSON parse classification", () => {
|
|
const makeAssistantError = (errorMessage: string): AssistantMessage =>
|
|
makeAssistantMessageFixture({
|
|
errorMessage,
|
|
content: [{ type: "text", text: errorMessage }],
|
|
});
|
|
|
|
it("suppresses transport-classified malformed streaming fragments", () => {
|
|
const msg = makeAssistantError(MALFORMED_STREAMING_FRAGMENT_ERROR_MESSAGE);
|
|
expect(formatAssistantErrorText(msg)).toBe(
|
|
"LLM streaming response contained a malformed fragment. Please try again.",
|
|
);
|
|
});
|
|
|
|
it("does not suppress unclassified JSON.parse text", () => {
|
|
const msg = makeAssistantError(
|
|
"Expected ',' or '}' after property value in JSON at position 334 (line 1 column 335)",
|
|
);
|
|
expect(formatAssistantErrorText(msg)).toBe(
|
|
"Expected ',' or '}' after property value in JSON at position 334 (line 1 column 335)",
|
|
);
|
|
});
|
|
|
|
it("keeps non-streaming provider request-validation syntax diagnostics", () => {
|
|
const msg = makeAssistantError(
|
|
'{"type":"error","error":{"type":"invalid_request_error","message":"Expected value in JSON at position 12 for messages.0.content"}}',
|
|
);
|
|
expect(formatAssistantErrorText(msg)).toBe(
|
|
"LLM request rejected: Expected value in JSON at position 12 for messages.0.content",
|
|
);
|
|
});
|
|
});
|