mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 09:51:22 +00:00
Squash-merge #12988. Refs: #12889 #12309 #3594 #7483 #10094 #10368 #11317 #11359 #11649 #12022 #12432 #12676 #12711
44 lines
1.5 KiB
TypeScript
44 lines
1.5 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { extractAssistantText, sanitizeTextContent } from "./sessions-helpers.js";
|
|
|
|
describe("sanitizeTextContent", () => {
|
|
it("strips minimax tool call XML and downgraded markers", () => {
|
|
const input =
|
|
'Hello <invoke name="tool">payload</invoke></minimax:tool_call> ' +
|
|
"[Tool Call: foo (ID: 1)] world";
|
|
const result = sanitizeTextContent(input).trim();
|
|
expect(result).toBe("Hello world");
|
|
expect(result).not.toContain("invoke");
|
|
expect(result).not.toContain("Tool Call");
|
|
});
|
|
|
|
it("strips thinking tags", () => {
|
|
const input = "Before <think>secret</think> after";
|
|
const result = sanitizeTextContent(input).trim();
|
|
expect(result).toBe("Before after");
|
|
});
|
|
});
|
|
|
|
describe("extractAssistantText", () => {
|
|
it("sanitizes blocks without injecting newlines", () => {
|
|
const message = {
|
|
role: "assistant",
|
|
content: [
|
|
{ type: "text", text: "Hi " },
|
|
{ type: "text", text: "<think>secret</think>there" },
|
|
],
|
|
};
|
|
expect(extractAssistantText(message)).toBe("Hi there");
|
|
});
|
|
|
|
it("rewrites error-ish assistant text only when the transcript marks it as an error", () => {
|
|
const message = {
|
|
role: "assistant",
|
|
stopReason: "error",
|
|
errorMessage: "500 Internal Server Error",
|
|
content: [{ type: "text", text: "500 Internal Server Error" }],
|
|
};
|
|
expect(extractAssistantText(message)).toBe("HTTP 500: Internal Server Error");
|
|
});
|
|
});
|