mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-21 10:16:44 +00:00
fix(gateway): prevent broken emoji in WebSocket log IDs (#105001)
* fix(gateway): preserve Unicode in WebSocket log IDs * test(gateway): cover UTF-16-safe log IDs --------- Co-authored-by: Peter Steinberger <steipete@gmail.com>
This commit is contained in:
co-authored by
Peter Steinberger
parent
103d9ceb5e
commit
8acbf209cd
@@ -5,6 +5,29 @@ import { describe, expect, test } from "vitest";
|
||||
import { formatForLog, summarizeAgentEventForWsLog } from "./ws-log.js";
|
||||
|
||||
describe("gateway ws log helpers", () => {
|
||||
test.each([
|
||||
{
|
||||
name: "run ID prefix boundary",
|
||||
payload: { runId: `${"a".repeat(11)}🚀${"b".repeat(20)}` },
|
||||
field: "run",
|
||||
expected: `${"a".repeat(11)}…bbbb`,
|
||||
},
|
||||
{
|
||||
name: "tool-call ID suffix boundary",
|
||||
payload: {
|
||||
stream: "tool",
|
||||
data: { toolCallId: `${"a".repeat(25)}🚀bbb` },
|
||||
},
|
||||
field: "call",
|
||||
expected: `${"a".repeat(12)}…bbb`,
|
||||
},
|
||||
])("summarizeAgentEventForWsLog keeps the $name UTF-16 safe", ({ payload, field, expected }) => {
|
||||
const value = summarizeAgentEventForWsLog(payload)[field];
|
||||
|
||||
expect(value).toBe(expected);
|
||||
expect(value).not.toMatch(/[\uD800-\uDFFF]/);
|
||||
});
|
||||
|
||||
test.each([
|
||||
{
|
||||
name: "formats Error instances",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Gateway WebSocket log formatting.
|
||||
// Redacts and compacts request/response/event metadata for console diagnostics.
|
||||
import { readStringValue } from "@openclaw/normalization-core/string-coerce";
|
||||
import { truncateUtf16Safe } from "@openclaw/normalization-core/utf16-slice";
|
||||
import { sliceUtf16Safe, truncateUtf16Safe } from "@openclaw/normalization-core/utf16-slice";
|
||||
import chalk from "chalk";
|
||||
import { resolveSendableOutboundReplyParts } from "openclaw/plugin-sdk/reply-payload";
|
||||
import { isVerbose } from "../globals.js";
|
||||
@@ -104,12 +104,12 @@ export function shouldLogWs(): boolean {
|
||||
function shortId(value: string): string {
|
||||
const s = value.trim();
|
||||
if (UUID_RE.test(s)) {
|
||||
return `${s.slice(0, 8)}…${s.slice(-4)}`;
|
||||
return `${sliceUtf16Safe(s, 0, 8)}…${sliceUtf16Safe(s, -4)}`;
|
||||
}
|
||||
if (s.length <= 24) {
|
||||
return s;
|
||||
}
|
||||
return `${s.slice(0, 12)}…${s.slice(-4)}`;
|
||||
return `${sliceUtf16Safe(s, 0, 12)}…${sliceUtf16Safe(s, -4)}`;
|
||||
}
|
||||
|
||||
/** Formats and redacts arbitrary values before they are written to gateway logs. */
|
||||
|
||||
Reference in New Issue
Block a user