11// Telegram tests cover bot core.raw update log plugin behavior.
22import { describe , expect , it } from "vitest" ;
3- import { stringifyTelegramRawUpdateForLog } from "./raw-update-log.js" ;
3+ import { formatTelegramRawUpdateForLog } from "./raw-update-log.js" ;
44
5- describe ( "stringifyTelegramRawUpdateForLog " , ( ) => {
5+ describe ( "formatTelegramRawUpdateForLog " , ( ) => {
66 it ( "redacts private Telegram raw update fields before verbose logging" , ( ) => {
77 const update = {
88 update_id : 98765 ,
@@ -45,7 +45,7 @@ describe("stringifyTelegramRawUpdateForLog", () => {
4545 } ,
4646 } ;
4747
48- const rawLog = stringifyTelegramRawUpdateForLog ( update ) ;
48+ const rawLog = formatTelegramRawUpdateForLog ( update ) ;
4949
5050 expect ( rawLog ) . toContain ( '"update_id":98765' ) ;
5151 expect ( rawLog ) . toContain ( '"message_id":44' ) ;
@@ -138,7 +138,7 @@ describe("stringifyTelegramRawUpdateForLog", () => {
138138 } ,
139139 } ;
140140
141- const rawLog = stringifyTelegramRawUpdateForLog ( update ) ;
141+ const rawLog = formatTelegramRawUpdateForLog ( update ) ;
142142
143143 expect ( rawLog ) . toContain ( '"update_id":45678' ) ;
144144 expect ( rawLog ) . toContain ( '"message_id":99' ) ;
@@ -176,7 +176,7 @@ describe("stringifyTelegramRawUpdateForLog", () => {
176176
177177 it ( "truncates long raw update strings without splitting UTF-16 surrogate pairs" , ( ) => {
178178 const prefix = "a" . repeat ( 499 ) ;
179- const rawLog = stringifyTelegramRawUpdateForLog ( {
179+ const rawLog = formatTelegramRawUpdateForLog ( {
180180 update_id : 123 ,
181181 diagnostic : `${ prefix } \uD83D\uDE80tail` ,
182182 } ) ;
@@ -188,4 +188,12 @@ describe("stringifyTelegramRawUpdateForLog", () => {
188188 expect ( rawLog ) . not . toContain ( "\\ud83d" ) ;
189189 expect ( rawLog ) . not . toContain ( "\\ude80" ) ;
190190 } ) ;
191+
192+ it ( "truncates the complete raw update log without splitting surrogate pairs" , ( ) => {
193+ const keyPrefix = "x" . repeat ( 7997 ) ;
194+ const rawLog = formatTelegramRawUpdateForLog ( { [ `${ keyPrefix } 😀tail` ] : 1 } ) ;
195+
196+ expect ( rawLog ) . toBe ( `{"${ keyPrefix } ...` ) ;
197+ expect ( rawLog ) . not . toMatch ( / [ \uD800 - \uDFFF ] / u) ;
198+ } ) ;
191199} ) ;
0 commit comments