fix(whatsapp): keep echo tracker log truncation UTF-16 safe (#102603)

* fix(whatsapp): keep echo tracker log truncation UTF-16 safe

Replace `.slice(0, 50)` with `truncateUtf16Safe(text, 50)` in
echo tracker verbose log message to prevent surrogate pair corruption.

Ref. lsr911 pattern — mechanical substitution, no behavior change.

* test(whatsapp): cover UTF-16-safe echo previews

---------

Co-authored-by: Peter Steinberger <steipete@gmail.com>
This commit is contained in:
huangjianxiong 2026-07-09 18:46:52 +08:00 committed by GitHub
parent 5154fe08fa
commit 0a8677ec99
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 1 deletions

View file

@ -0,0 +1,18 @@
import { describe, expect, it, vi } from "vitest";
import { createEchoTracker } from "./echo.js";
describe("createEchoTracker", () => {
it("keeps verbose previews UTF-16 safe without changing the tracked text", () => {
const logVerbose = vi.fn();
const tracker = createEchoTracker({ logVerbose });
const prefix = "x".repeat(49);
const text = `${prefix}😀tail`;
tracker.rememberText(text, { logVerboseMessage: true });
expect(logVerbose).toHaveBeenCalledExactlyOnceWith(
`Added to echo detection set (size now: 1): ${prefix}...`,
);
expect(tracker.has(text)).toBe(true);
});
});

View file

@ -1,4 +1,5 @@
// Whatsapp plugin module implements echo behavior.
import { truncateUtf16Safe } from "openclaw/plugin-sdk/text-utility-runtime";
export type EchoTracker = {
rememberText: (
text: string | undefined,
@ -48,7 +49,7 @@ export function createEchoTracker(params: {
}
if (opts.logVerboseMessage) {
params.logVerbose?.(
`Added to echo detection set (size now: ${recentlySent.size}): ${text.slice(0, 50)}...`,
`Added to echo detection set (size now: ${recentlySent.size}): ${truncateUtf16Safe(text, 50)}...`,
);
}
trim();