Skip to content

Commit 0c88e67

Browse files
authored
fix(amazonq): Truncating user prompt for unit test generation. (#5359)
* Adding truncation logic to testGen user prompt
1 parent 18590f8 commit 0c88e67

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type" : "bugfix",
3+
"description" : "Amazon Q /test: Truncating user input to 4096 characters for unit test generation."
4+
}

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqCodeTest/controller/CodeTestChatController.kt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,11 @@ class CodeTestChatController(
201201

202202
session.isCodeBlockSelected = selectionRange !== null
203203

204-
// This check is added to remove /test if user accidentally added while doing Regenerate unit tests.
205-
val userPrompt = if (message.prompt.startsWith("/test")) {
206-
message.prompt.substringAfter("/test ").trim()
207-
} else {
208-
message.prompt
209-
}
204+
// This removes /test if user accidentally added while doing Regenerate unit tests and truncates the user response to 4096 characters.
205+
val userPrompt = message.prompt
206+
.let { if (it.startsWith("/test")) it.substringAfter("/test ").trim() else it }
207+
.take(4096)
208+
210209
CodeWhispererUTGChatManager.getInstance(project).generateTests(userPrompt, codeTestChatHelper, null, selectionRange)
211210
} else {
212211
// Not adding a progress bar to unsupported language cases

0 commit comments

Comments
 (0)