@@ -21,6 +21,7 @@ import {
2121 testGenCompletedField ,
2222 testGenProgressField ,
2323 testGenSummaryMessage ,
24+ maxUserPromptLength ,
2425} from '../../models/constants'
2526import MessengerUtils , { ButtonActions } from './messenger/messengerUtils'
2627import { getTelemetryReasonDesc , isAwsError } from '../../../shared/errors'
@@ -365,7 +366,8 @@ export class TestController {
365366 getLogger ( ) . debug ( 'startTestGen tabId: %O' , message . tabID )
366367 let fileName = ''
367368 let filePath = ''
368- let userMessage = ''
369+ let userFacingMessage = ''
370+ let userPrompt = ''
369371 session . testGenerationStartTime = performance . now ( )
370372
371373 try {
@@ -381,6 +383,8 @@ export class TestController {
381383 )
382384 return
383385 }
386+ // Truncating the user prompt if the prompt is more than 4096.
387+ userPrompt = message . prompt . slice ( 0 , maxUserPromptLength )
384388
385389 // check that the session is authenticated
386390 const authState = await AuthUtil . instance . getChatAuthState ( )
@@ -425,16 +429,16 @@ export class TestController {
425429 getLogger ( ) . debug ( `File path: ${ fileEditorToTest . document . uri . fsPath } ` )
426430 filePath = fileEditorToTest . document . uri . fsPath
427431 fileName = path . basename ( filePath )
428- userMessage = message . prompt
432+ userFacingMessage = userPrompt
429433 ? regenerateTests
430- ? `${ message . prompt } `
431- : `/test ${ message . prompt } `
434+ ? `${ userPrompt } `
435+ : `/test ${ userPrompt } `
432436 : `/test Generate unit tests for \`${ fileName } \``
433437
434- session . hasUserPromptSupplied = message . prompt . length > 0
438+ session . hasUserPromptSupplied = userPrompt . length > 0
435439
436440 // displaying user message prompt in Test tab
437- this . messenger . sendMessage ( userMessage , tabID , 'prompt' )
441+ this . messenger . sendMessage ( userFacingMessage , tabID , 'prompt' )
438442 this . messenger . sendChatInputEnabled ( tabID , false )
439443 this . sessionStorage . getSession ( ) . conversationState = ConversationState . IN_PROGRESS
440444 this . messenger . sendUpdatePromptProgress ( message . tabID , testGenProgressField )
@@ -460,7 +464,7 @@ export class TestController {
460464 this . messenger . sendMessage ( unsupportedMessage , tabID , 'answer' )
461465 await this . onCodeGeneration (
462466 session ,
463- message . prompt ,
467+ userPrompt ,
464468 tabID ,
465469 fileName ,
466470 filePath ,
0 commit comments