@@ -163,108 +163,31 @@ describe('triggerPayloadToChatRequest', () => {
163163 )
164164 } )
165165
166- it ( 'should preserve Type A (user input) over all other types when size exceeds limit' , ( ) => {
167- const payload = createBaseTriggerPayload ( )
168- const userInputSize = 60_000
169- const promptSize = 30_000
170- const currentFileSize = 20_000
171-
172- payload . message = createLargeString ( userInputSize , 'userInput-' )
173- payload . additionalContents = [ createPrompt ( promptSize ) ]
174- payload . fileText = createLargeString ( currentFileSize , 'currentFile-' )
175-
176- const result = triggerPayloadToChatRequest ( payload )
177-
178- // User input should be preserved completely
179- assert . strictEqual ( result . conversationState . currentMessage ?. userInputMessage ?. content ?. length , userInputSize )
180-
181- // Other contexts should be truncated
182- assert . ok (
183- result . conversationState . currentMessage ?. userInputMessage ?. userInputMessageContext ?. additionalContext ?. [ 0 ]
184- . innerContext ?. length ! < promptSize
185- )
186- assert . ok (
187- result . conversationState . currentMessage ?. userInputMessage ?. userInputMessageContext ?. editorState ?. document
188- ?. text ?. length ! < currentFileSize
189- )
166+ it ( 'should preserve priority order' , ( ) => {
167+ const before1 = [ 5000 , 30000 , 40000 , 20000 , 15000 , 25000 ] // Total: 135,000
168+ const after1 = [ 5000 , 30000 , 40000 , 15000 , 10000 , 0 ] // Total: 100,000
169+ checkContextTruncationHelper ( before1 , after1 )
170+
171+ const before2 = [ 1000 , 2000 , 3000 , 4000 , 5000 , 90000 ] // Total: 105,000
172+ const after2 = [ 1000 , 2000 , 3000 , 4000 , 5000 , 85000 ] // Total: 100,000
173+ checkContextTruncationHelper ( before2 , after2 )
174+
175+ const before3 = [ 10000 , 40000 , 80000 , 30000 , 20000 , 50000 ] // Total: 230,000
176+ const after3 = [ 10000 , 40000 , 50000 , 0 , 0 , 0 ] // Total: 100,000
177+ checkContextTruncationHelper ( before3 , after3 )
178+
179+ const before4 = [ 5000 , 5000 , 150000 , 5000 , 5000 , 5000 ] // Total: 175,000
180+ const after4 = [ 5000 , 5000 , 80000 , 5000 , 5000 , 0 ] // Total: 100,000
181+ checkContextTruncationHelper ( before4 , after4 )
182+
183+ const before5 = [ 50000 , 80000 , 20000 , 10000 , 10000 , 10000 ] // Total: 180,000
184+ const after5 = [ 50000 , 50000 , 0 , 0 , 0 , 0 ] // Total: 100,000
185+ checkContextTruncationHelper ( before5 , after5 )
190186 } )
191187
192- it ( 'should preserve Type B1(prompts) over lower priority contexts when size exceeds limit' , ( ) => {
188+ function checkContextTruncationHelper ( before : number [ ] , after : number [ ] ) {
193189 const payload = createBaseTriggerPayload ( )
194- const promptSize = 50_000
195- const currentFileSize = 40_000
196- const ruleSize = 30_000
197-
198- payload . additionalContents = [ createPrompt ( promptSize ) , createRule ( ruleSize ) ]
199- payload . fileText = createLargeString ( currentFileSize , 'currentFile-' )
200-
201- const result = triggerPayloadToChatRequest ( payload )
202-
203- // Prompt context should be preserved more than others
204- const promptContext =
205- result . conversationState . currentMessage ?. userInputMessage ?. userInputMessageContext ?. additionalContext ?. find (
206- ( c ) => c ?. name === 'prompt'
207- ) ?. innerContext
208- const ruleContext =
209- result . conversationState . currentMessage ?. userInputMessage ?. userInputMessageContext ?. additionalContext ?. find (
210- ( c ) => c ?. name === 'rule'
211- ) ?. innerContext
212-
213- assert . ok ( promptContext ! . length > ruleContext ! . length )
214- assert . ok (
215- result . conversationState . currentMessage ?. userInputMessage ?. userInputMessageContext ?. editorState ?. document
216- ?. text ?. length ! < currentFileSize
217- )
218- } )
219-
220- it ( 'should preserve Type C (current file) over B1(rules), B2(files), and B3(workspace)' , ( ) => {
221- const payload = createBaseTriggerPayload ( )
222- const currentFileSize = 40_000
223- const ruleSize = 30_000
224- const fileSize = 20_000
225- const workspaceSize = 10_000
226-
227- payload . fileText = createLargeString ( currentFileSize , 'currentFile-' )
228- payload . additionalContents = [ createRule ( ruleSize ) , createFile ( fileSize ) ]
229- payload . relevantTextDocuments = [
230- {
231- relativeFilePath : 'workspace.ts' ,
232- text : createLargeString ( workspaceSize , 'workspace-' ) ,
233- startLine : - 1 ,
234- endLine : - 1 ,
235- } ,
236- ]
237-
238- const result = triggerPayloadToChatRequest ( payload )
239-
240- const currentFileLength =
241- result . conversationState . currentMessage ?. userInputMessage ?. userInputMessageContext ?. editorState ?. document
242- ?. text ?. length !
243- const ruleContext =
244- result . conversationState . currentMessage ?. userInputMessage ?. userInputMessageContext ?. additionalContext ?. find (
245- ( c ) => c . name === 'rule'
246- ) ?. innerContext
247- const fileContext =
248- result . conversationState . currentMessage ?. userInputMessage ?. userInputMessageContext ?. additionalContext ?. find (
249- ( c ) => c . name === 'file'
250- ) ?. innerContext
251- const workspaceContext =
252- result . conversationState . currentMessage ?. userInputMessage ?. userInputMessageContext ?. editorState
253- ?. relevantDocuments ?. [ 0 ] . text
254-
255- assert . ok ( currentFileLength > ruleContext ! . length )
256- assert . ok ( ruleContext ! . length > fileContext ! . length )
257- assert . ok ( fileContext ! . length > workspaceContext ! . length )
258- } )
259-
260- it ( 'should preserve priority order when all context types are present' , ( ) => {
261- const payload = createBaseTriggerPayload ( )
262- const userInputSize = 30_000
263- const promptSize = 25_000
264- const currentFileSize = 20_000
265- const ruleSize = 15_000
266- const fileSize = 10_000
267- const workspaceSize = 5_000
190+ const [ userInputSize , promptSize , currentFileSize , ruleSize , fileSize , workspaceSize ] = before
268191
269192 payload . message = createLargeString ( userInputSize , 'userInput-' )
270193 payload . additionalContents = [ createPrompt ( promptSize ) , createRule ( ruleSize ) , createFile ( fileSize ) ]
@@ -301,10 +224,11 @@ describe('triggerPayloadToChatRequest', () => {
301224 ?. relevantDocuments ?. [ 0 ] . text
302225
303226 // Verify priority ordering
304- assert . ok ( userInputLength >= promptContext ! . length )
305- assert . ok ( promptContext ! . length >= currentFileLength )
306- assert . ok ( currentFileLength >= ruleContext ! . length )
307- assert . ok ( ruleContext ! . length >= fileContext ! . length )
308- assert . ok ( fileContext ! . length >= workspaceContext ! . length )
309- } )
227+ assert . strictEqual ( userInputLength , after [ 0 ] )
228+ assert . strictEqual ( promptContext ?. length , after [ 1 ] )
229+ assert . strictEqual ( currentFileLength , after [ 2 ] )
230+ assert . strictEqual ( ruleContext ?. length , after [ 3 ] )
231+ assert . strictEqual ( fileContext ?. length , after [ 4 ] )
232+ assert . strictEqual ( workspaceContext ?. length , after [ 5 ] )
233+ }
310234} )
0 commit comments