diff --git a/packages/amazonq/.changes/next-release/Bug Fix-aff621e4-1c1a-450e-91a7-8fd63fe90a5d.json b/packages/amazonq/.changes/next-release/Bug Fix-aff621e4-1c1a-450e-91a7-8fd63fe90a5d.json new file mode 100644 index 00000000000..46f4036fac7 --- /dev/null +++ b/packages/amazonq/.changes/next-release/Bug Fix-aff621e4-1c1a-450e-91a7-8fd63fe90a5d.json @@ -0,0 +1,4 @@ +{ + "type": "Bug Fix", + "description": "Amazon Q /test: Truncating user input to 4096 characters for unit test generation." +} diff --git a/packages/core/src/amazonqTest/chat/controller/controller.ts b/packages/core/src/amazonqTest/chat/controller/controller.ts index 10b84dba2b7..fa7774bb27d 100644 --- a/packages/core/src/amazonqTest/chat/controller/controller.ts +++ b/packages/core/src/amazonqTest/chat/controller/controller.ts @@ -21,6 +21,7 @@ import { testGenCompletedField, testGenProgressField, testGenSummaryMessage, + maxUserPromptLength, } from '../../models/constants' import MessengerUtils, { ButtonActions } from './messenger/messengerUtils' import { getTelemetryReasonDesc, isAwsError } from '../../../shared/errors' @@ -365,7 +366,8 @@ export class TestController { getLogger().debug('startTestGen tabId: %O', message.tabID) let fileName = '' let filePath = '' - let userMessage = '' + let userFacingMessage = '' + let userPrompt = '' session.testGenerationStartTime = performance.now() try { @@ -381,6 +383,8 @@ export class TestController { ) return } + // Truncating the user prompt if the prompt is more than 4096. + userPrompt = message.prompt.slice(0, maxUserPromptLength) // check that the session is authenticated const authState = await AuthUtil.instance.getChatAuthState() @@ -425,16 +429,16 @@ export class TestController { getLogger().debug(`File path: ${fileEditorToTest.document.uri.fsPath}`) filePath = fileEditorToTest.document.uri.fsPath fileName = path.basename(filePath) - userMessage = message.prompt + userFacingMessage = userPrompt ? regenerateTests - ? `${message.prompt}` - : `/test ${message.prompt}` + ? `${userPrompt}` + : `/test ${userPrompt}` : `/test Generate unit tests for \`${fileName}\`` - session.hasUserPromptSupplied = message.prompt.length > 0 + session.hasUserPromptSupplied = userPrompt.length > 0 // displaying user message prompt in Test tab - this.messenger.sendMessage(userMessage, tabID, 'prompt') + this.messenger.sendMessage(userFacingMessage, tabID, 'prompt') this.messenger.sendChatInputEnabled(tabID, false) this.sessionStorage.getSession().conversationState = ConversationState.IN_PROGRESS this.messenger.sendUpdatePromptProgress(message.tabID, testGenProgressField) @@ -460,7 +464,7 @@ export class TestController { this.messenger.sendMessage(unsupportedMessage, tabID, 'answer') await this.onCodeGeneration( session, - message.prompt, + userPrompt, tabID, fileName, filePath, diff --git a/packages/core/src/amazonqTest/models/constants.ts b/packages/core/src/amazonqTest/models/constants.ts index f836991643b..547cbdb3663 100644 --- a/packages/core/src/amazonqTest/models/constants.ts +++ b/packages/core/src/amazonqTest/models/constants.ts @@ -11,6 +11,8 @@ import { BuildStatus } from '../chat/session/session' // For uniquely identifiying which chat messages should be routed to Test export const testChat = 'testChat' +export const maxUserPromptLength = 4096 // user prompt character limit from MPS and API model. + export const cancelTestGenButton: ChatItemButton = { id: ButtonActions.STOP_TEST_GEN, text: 'Cancel',