test: tighten whatsapp outbound sanitizer follow-up

This commit is contained in:
Marcus Castro
2026-04-29 01:05:55 -03:00
parent 970a4a19c6
commit 3415706416
3 changed files with 19 additions and 3 deletions

View File

@@ -24,6 +24,7 @@ import { elide } from "./util.js";
export async function deliverWebReply(params: {
replyResult: ReplyPayload;
normalizedReplyResult?: ReturnType<typeof normalizeWhatsAppOutboundPayload<ReplyPayload>>;
msg: WebInboundMsg;
mediaLocalRoots?: readonly string[];
maxMediaBytes: number;
@@ -45,9 +46,11 @@ export async function deliverWebReply(params: {
}
const tableMode = params.tableMode ?? "code";
const chunkMode = params.chunkMode ?? "length";
const normalizedReply = normalizeWhatsAppOutboundPayload(replyResult, {
normalizeText: normalizeWhatsAppPayloadTextPreservingIndentation,
});
const normalizedReply =
params.normalizedReplyResult ??
normalizeWhatsAppOutboundPayload(replyResult, {
normalizeText: normalizeWhatsAppPayloadTextPreservingIndentation,
});
const convertedText = markdownToWhatsApp(convertMarkdownTables(normalizedReply.text, tableMode));
const textChunks = chunkMarkdownTextWithMode(convertedText, textLimit, chunkMode);
const mediaList = normalizedReply.mediaUrls ?? [];

View File

@@ -327,6 +327,7 @@ export async function dispatchWhatsAppBufferedReply(params: {
}
await params.deliverReply({
replyResult: normalizedDeliveryPayload,
normalizedReplyResult: normalizedDeliveryPayload,
msg: params.msg,
mediaLocalRoots,
maxMediaBytes: params.maxMediaBytes,

View File

@@ -2,6 +2,7 @@ import { describe, expect, it } from "vitest";
import {
sanitizeAssistantVisibleText,
sanitizeAssistantVisibleTextWithProfile,
stripToolCallXmlTags,
stripAssistantInternalScaffolding,
} from "./assistant-visible-text.js";
import { stripModelSpecialTokens } from "./model-special-tokens.js";
@@ -504,6 +505,17 @@ describe("stripAssistantInternalScaffolding", () => {
});
});
describe("stripToolCallXmlTags", () => {
it("strips plural function/tool wrapper XML only when the opt-in flag is enabled", () => {
const input =
'prefix <function_calls><invoke name="find">secret</invoke></function_calls> suffix';
expect(stripToolCallXmlTags(input)).toBe(input);
expect(stripToolCallXmlTags(input, { stripFunctionCallsXmlPayloads: true })).toBe(
"prefix suffix",
);
});
});
describe("sanitizeAssistantVisibleText", () => {
it("strips minimax, tool XML, downgraded tool markers, and think tags in one pass", () => {
const input = [