@@ -37,6 +37,7 @@ let estimateToolResultReductionPotential: typeof import("./tool-result-truncatio
3737let DEFAULT_MAX_LIVE_TOOL_RESULT_CHARS : typeof import ( "./tool-result-truncation.js" ) . DEFAULT_MAX_LIVE_TOOL_RESULT_CHARS ;
3838let resolveLiveToolResultMaxChars : typeof import ( "./tool-result-truncation.js" ) . resolveLiveToolResultMaxChars ;
3939let resolveLiveToolResultAggregateMaxChars : typeof import ( "./tool-result-truncation.js" ) . resolveLiveToolResultAggregateMaxChars ;
40+ let toolResultWarningDedupe : typeof import ( "./tool-result-truncation.js" ) . toolResultWarningDedupe ;
4041let tmpDir : string | undefined ;
4142
4243async function loadFreshToolResultTruncationModuleForTest ( ) {
@@ -53,6 +54,7 @@ async function loadFreshToolResultTruncationModuleForTest() {
5354 DEFAULT_MAX_LIVE_TOOL_RESULT_CHARS ,
5455 resolveLiveToolResultMaxChars,
5556 resolveLiveToolResultAggregateMaxChars,
57+ toolResultWarningDedupe,
5658 } = await import ( "./tool-result-truncation.js" ) ) ;
5759}
5860
@@ -74,6 +76,8 @@ beforeEach(async () => {
7476} ) ;
7577
7678afterEach ( async ( ) => {
79+ toolResultWarningDedupe . promptPressure . clear ( ) ;
80+ toolResultWarningDedupe . sessionRecovery . clear ( ) ;
7781 clearEmbeddedSessionPromptStates ( [ "session-99495" , "session-99495-shrink" ] ) ;
7882 if ( tmpDir ) {
7983 await fs . rm ( tmpDir , { recursive : true , force : true } ) . catch ( ( ) => { } ) ;
@@ -95,6 +99,28 @@ function makeToolResult(text: string, toolCallId = "call_1", details?: unknown):
9599 } ;
96100}
97101
102+ describe ( "tool-result warning dedupe" , ( ) => {
103+ const warningDedupeLimit = 1_024 ;
104+
105+ it . each ( [
106+ [ "prompt pressure" , ( ) => toolResultWarningDedupe . promptPressure ] ,
107+ [ "session recovery" , ( ) => toolResultWarningDedupe . sessionRecovery ] ,
108+ ] ) ( "bounds and evicts the oldest %s warning keys" , ( _name , getCache ) => {
109+ const cache = getCache ( ) ;
110+
111+ for ( let index = 0 ; index <= warningDedupeLimit ; index += 1 ) {
112+ expect ( cache . check ( `session-${ index } ` ) ) . toBe ( false ) ;
113+ }
114+
115+ expect ( cache . size ( ) ) . toBe ( warningDedupeLimit ) ;
116+ expect ( cache . peek ( "session-0" ) ) . toBe ( false ) ;
117+ expect ( cache . peek ( "session-1" ) ) . toBe ( true ) ;
118+ expect ( cache . peek ( `session-${ warningDedupeLimit } ` ) ) . toBe ( true ) ;
119+ expect ( cache . check ( "session-0" ) ) . toBe ( false ) ;
120+ expect ( cache . check ( `session-${ warningDedupeLimit } ` ) ) . toBe ( true ) ;
121+ } ) ;
122+ } ) ;
123+
98124function textWithFullOutputFooter ( text : string , fullOutputPath : string ) : string {
99125 return `${ text } \n\n[Showing truncated output. ${ formatFullOutputFooter ( fullOutputPath ) } ]` ;
100126}
0 commit comments