|
1 | 1 | import { beforeEach, describe, expect, it, vi } from "vitest"; |
2 | | -import { truncateUtf16Safe } from "openclaw/plugin-sdk/text-utility-runtime"; |
3 | 2 |
|
4 | 3 | const { openLocalFileMock, resolveLocalPathFromRootsSyncMock, sendMediaMock, sendTextMock } = |
5 | 4 | vi.hoisted(() => ({ |
@@ -431,47 +430,3 @@ describe("handleStructuredPayload", () => { |
431 | 430 | }, |
432 | 431 | ); |
433 | 432 | }); |
434 | | - |
435 | | -// Pin the same UTF-16 boundary behavior that the production debugLog sites |
436 | | -// in reply-dispatcher.ts / streaming-c2c.ts / streaming-media-send.ts / |
437 | | -// sender.ts rely on. |
438 | | -describe("reply-dispatcher UTF-16-safe truncation helper", () => { |
439 | | - const hasLoneSurrogate = (value: string): boolean => { |
440 | | - for (let i = 0; i < value.length; i++) { |
441 | | - const code = value.charCodeAt(i); |
442 | | - if (code >= 0xd800 && code <= 0xdbff) { |
443 | | - const next = value.charCodeAt(i + 1); |
444 | | - if (!(next >= 0xdc00 && next <= 0xdfff)) { |
445 | | - return true; |
446 | | - } |
447 | | - i++; |
448 | | - } else if (code >= 0xdc00 && code <= 0xdfff) { |
449 | | - return true; |
450 | | - } |
451 | | - } |
452 | | - return false; |
453 | | - }; |
454 | | - |
455 | | - it("truncates TTS preview on UTF-16 boundary without splitting emoji", () => { |
456 | | - // Mirrors the call shape at reply-dispatcher.ts:516 |
457 | | - // log?.debug?.(`TTS: "${truncateUtf16Safe(ttsText, 50)}..."`); |
458 | | - const ttsText = "你好世界🎉🎉🎉这是TTS预览文本的剩余部分"; |
459 | | - const truncated = truncateUtf16Safe(ttsText, 50); |
460 | | - expect(truncated.length).toBeLessThanOrEqual(50); |
461 | | - expect(hasLoneSurrogate(truncated)).toBe(false); |
462 | | - }); |
463 | | - |
464 | | - it("truncates streaming-c2c preview on UTF-16 boundary", () => { |
465 | | - // Mirrors the call shape at streaming-c2c.ts:546 |
466 | | - // const preview = truncateUtf16Safe(payload.text ?? "", 60).replace(/\n/g, "\\n"); |
467 | | - const payloadText = "测试消息🎉🎉剩余内容在60字符内被截断的边界emoji字符串"; |
468 | | - const truncated = truncateUtf16Safe(payloadText, 60); |
469 | | - expect(truncated.length).toBeLessThanOrEqual(60); |
470 | | - expect(hasLoneSurrogate(truncated)).toBe(false); |
471 | | - }); |
472 | | - |
473 | | - it("passes plain ASCII through unchanged (negative control)", () => { |
474 | | - const ascii = "plain ASCII text without any emoji or CJK content"; |
475 | | - expect(truncateUtf16Safe(ascii, 60)).toBe(ascii); |
476 | | - }); |
477 | | -}); |
0 commit comments