@@ -40,6 +40,46 @@ describe('triggerPayloadToChatRequest', () => {
4040 userIntent : undefined ,
4141 }
4242
43+ const createLargeString = ( size : number , prefix : string = '' ) => prefix + 'x' . repeat ( size - prefix . length )
44+
45+ const createPrompt = ( size : number ) => {
46+ return {
47+ name : 'prompt' ,
48+ description : 'prompt' ,
49+ relativePath : 'path-prompt' ,
50+ type : 'prompt' ,
51+ innerContext : createLargeString ( size , 'prompt-' ) ,
52+ }
53+ }
54+
55+ const createRule = ( size : number ) => {
56+ return {
57+ name : 'rule' ,
58+ description : 'rule' ,
59+ relativePath : 'path-rule' ,
60+ type : 'rule' ,
61+ innerContext : createLargeString ( size , 'rule-' ) ,
62+ }
63+ }
64+
65+ const createFile = ( size : number ) => {
66+ return {
67+ name : 'file' ,
68+ description : 'file' ,
69+ relativePath : 'path-file' ,
70+ type : 'file' ,
71+ innerContext : createLargeString ( size , 'file-' ) ,
72+ }
73+ }
74+
75+ const createBaseTriggerPayload = ( ) : TriggerPayload => ( {
76+ ...mockBasicPayload ,
77+ message : '' ,
78+ fileText : '' ,
79+ filePath : 'test.ts' ,
80+ fileLanguage : 'typescript' ,
81+ customization : { arn : '' } ,
82+ } )
4383 it ( 'should convert basic trigger payload to chat request' , ( ) => {
4484 const result = triggerPayloadToChatRequest ( mockBasicPayload )
4585
@@ -122,47 +162,6 @@ describe('triggerPayloadToChatRequest', () => {
122162 filePathSizeLimit
123163 )
124164 } )
125- } )
126-
127- describe ( 'Context Priority Truncation Tests' , ( ) => {
128- const createLargeString = ( size : number , prefix : string = '' ) => prefix + 'x' . repeat ( size - prefix . length )
129-
130- const createBaseTriggerPayload = ( ) : TriggerPayload => ( {
131- message : '' ,
132- fileText : '' ,
133- filePath : 'test.ts' ,
134- fileLanguage : 'typescript' ,
135- trigger : ChatTriggerType . ChatMessage ,
136- customization : { arn : '' } ,
137- relevantTextDocuments : [ ] ,
138- additionalContents : [ ] ,
139- useRelevantDocuments : true ,
140- contextLengths : {
141- truncatedUserInputContextLength : 0 ,
142- truncatedFocusFileContextLength : 0 ,
143- truncatedWorkspaceContextLength : 0 ,
144- truncatedAdditionalContextLengths : {
145- promptContextLength : 0 ,
146- ruleContextLength : 0 ,
147- fileContextLength : 0 ,
148- } ,
149- additionalContextLengths : {
150- fileContextLength : 0 ,
151- promptContextLength : 0 ,
152- ruleContextLength : 0 ,
153- } ,
154- workspaceContextLength : 0 ,
155- userInputContextLength : 0 ,
156- focusFileContextLength : 0 ,
157- } ,
158- query : undefined ,
159- codeSelection : undefined ,
160- matchPolicy : undefined ,
161- codeQuery : undefined ,
162- userIntent : undefined ,
163- context : [ ] ,
164- documentReferences : [ ] ,
165- } )
166165
167166 it ( 'should preserve Type A (user input) over all other types when size exceeds limit' , ( ) => {
168167 const payload = createBaseTriggerPayload ( )
@@ -171,15 +170,7 @@ describe('Context Priority Truncation Tests', () => {
171170 const currentFileSize = 20_000
172171
173172 payload . message = createLargeString ( userInputSize , 'userInput-' )
174- payload . additionalContents = [
175- {
176- name : 'prompt1' ,
177- description : 'prompt1' ,
178- relativePath : 'path1' ,
179- type : 'prompt' ,
180- innerContext : createLargeString ( promptSize , 'prompt-' ) ,
181- } ,
182- ]
173+ payload . additionalContents = [ createPrompt ( promptSize ) ]
183174 payload . fileText = createLargeString ( currentFileSize , 'currentFile-' )
184175
185176 const result = triggerPayloadToChatRequest ( payload )
@@ -204,22 +195,7 @@ describe('Context Priority Truncation Tests', () => {
204195 const currentFileSize = 40_000
205196 const ruleSize = 30_000
206197
207- payload . additionalContents = [
208- {
209- name : 'prompt' ,
210- description : 'prompt' ,
211- relativePath : 'path1' ,
212- type : 'prompt' ,
213- innerContext : createLargeString ( promptSize , 'prompt-' ) ,
214- } ,
215- {
216- name : 'rule' ,
217- description : 'rule' ,
218- relativePath : 'path2' ,
219- type : 'rule' ,
220- innerContext : createLargeString ( ruleSize , 'rule-' ) ,
221- } ,
222- ]
198+ payload . additionalContents = [ createPrompt ( promptSize ) , createRule ( ruleSize ) ]
223199 payload . fileText = createLargeString ( currentFileSize , 'currentFile-' )
224200
225201 const result = triggerPayloadToChatRequest ( payload )
@@ -249,22 +225,7 @@ describe('Context Priority Truncation Tests', () => {
249225 const workspaceSize = 10_000
250226
251227 payload . fileText = createLargeString ( currentFileSize , 'currentFile-' )
252- payload . additionalContents = [
253- {
254- name : 'rule' ,
255- description : 'rule' ,
256- relativePath : 'path1' ,
257- type : 'rule' ,
258- innerContext : createLargeString ( ruleSize , 'rule-' ) ,
259- } ,
260- {
261- name : 'file' ,
262- description : 'file' ,
263- relativePath : 'path2' ,
264- type : 'file' ,
265- innerContext : createLargeString ( fileSize , 'file-' ) ,
266- } ,
267- ]
228+ payload . additionalContents = [ createRule ( ruleSize ) , createFile ( fileSize ) ]
268229 payload . relevantTextDocuments = [
269230 {
270231 relativeFilePath : 'workspace.ts' ,
@@ -306,29 +267,7 @@ describe('Context Priority Truncation Tests', () => {
306267 const workspaceSize = 5_000
307268
308269 payload . message = createLargeString ( userInputSize , 'userInput-' )
309- payload . additionalContents = [
310- {
311- name : 'prompt' ,
312- description : 'prompt' ,
313- relativePath : 'path1' ,
314- type : 'prompt' ,
315- innerContext : createLargeString ( promptSize , 'prompt-' ) ,
316- } ,
317- {
318- name : 'rule' ,
319- description : 'rule' ,
320- relativePath : 'path2' ,
321- type : 'rule' ,
322- innerContext : createLargeString ( ruleSize , 'rule-' ) ,
323- } ,
324- {
325- name : 'file' ,
326- description : 'file' ,
327- relativePath : 'path3' ,
328- type : 'file' ,
329- innerContext : createLargeString ( fileSize , 'file-' ) ,
330- } ,
331- ]
270+ payload . additionalContents = [ createPrompt ( promptSize ) , createRule ( ruleSize ) , createFile ( fileSize ) ]
332271 payload . fileText = createLargeString ( currentFileSize , 'currentFile-' )
333272 payload . relevantTextDocuments = [
334273 {
0 commit comments