Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "Bug Fix",
"description": "Amazon Q /test: Truncating user input to 4096 characters for unit test generation."
}
18 changes: 11 additions & 7 deletions packages/core/src/amazonqTest/chat/controller/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
testGenCompletedField,
testGenProgressField,
testGenSummaryMessage,
maxUserPromptLength,
} from '../../models/constants'
import MessengerUtils, { ButtonActions } from './messenger/messengerUtils'
import { getTelemetryReasonDesc, isAwsError } from '../../../shared/errors'
Expand Down Expand Up @@ -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 {
Expand All @@ -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()
Expand Down Expand Up @@ -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)
Expand All @@ -460,7 +464,7 @@ export class TestController {
this.messenger.sendMessage(unsupportedMessage, tabID, 'answer')
await this.onCodeGeneration(
session,
message.prompt,
userPrompt,
tabID,
fileName,
filePath,
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/amazonqTest/models/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Loading