Skip to content

Commit aae3cba

Browse files
authored
Merge branch 'main' into ai_gen
2 parents 8edc6cd + f5ed158 commit aae3cba

File tree

8 files changed

+148
-168
lines changed

8 files changed

+148
-168
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: Test generation fails for files outside the project"
4+
}

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ mockitoKotlin = "5.4.0"
2727
mockk = "1.13.10"
2828
nimbus-jose-jwt = "9.40"
2929
node-gradle = "7.0.2"
30-
telemetryGenerator = "1.0.291"
30+
telemetryGenerator = "1.0.293"
3131
testLogger = "4.0.0"
3232
testRetry = "1.5.10"
3333
# test-only; platform provides slf4j transitively at runtime

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,7 @@ class CodeWhispererUTGChatManager(val project: Project, private val cs: Coroutin
512512
AmazonqTelemetry.utgGenerateTests(
513513
cwsprChatProgrammingLanguage = session.programmingLanguage.languageId,
514514
hasUserPromptSupplied = session.hasUserPromptSupplied,
515+
isFileInWorkspace = true,
515516
isSupportedLanguage = true,
516517
credentialStartUrl = getStartUrl(project),
517518
jobGroup = session.testGenerationJobGroupName,

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

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import com.intellij.openapi.application.ApplicationManager
1212
import com.intellij.openapi.fileEditor.FileDocumentManager
1313
import com.intellij.openapi.fileEditor.FileEditorManager
1414
import com.intellij.openapi.project.Project
15+
import com.intellij.openapi.project.guessProjectDir
1516
import com.intellij.openapi.vfs.LocalFileSystem
1617
import com.intellij.openapi.vfs.VirtualFile
1718
import com.intellij.openapi.vfs.VirtualFileManager
@@ -22,6 +23,7 @@ import kotlinx.coroutines.future.await
2223
import kotlinx.coroutines.launch
2324
import kotlinx.coroutines.withContext
2425
import migration.software.aws.toolkits.jetbrains.services.codewhisperer.customization.CodeWhispererModelConfigurator
26+
import software.amazon.awssdk.services.codewhispererruntime.model.IdeCategory
2527
import software.amazon.awssdk.services.codewhispererruntime.model.Position
2628
import software.amazon.awssdk.services.codewhispererruntime.model.Range
2729
import software.amazon.awssdk.services.codewhispererruntime.model.Reference
@@ -89,6 +91,7 @@ import software.aws.toolkits.resources.message
8991
import software.aws.toolkits.telemetry.AmazonqTelemetry
9092
import software.aws.toolkits.telemetry.MetricResult
9193
import software.aws.toolkits.telemetry.UiTelemetry
94+
import java.io.File
9295
import java.nio.file.Files
9396
import java.nio.file.Path
9497
import java.nio.file.Paths
@@ -186,7 +189,7 @@ class CodeTestChatController(
186189
message.tabId,
187190
false
188191
)
189-
if (isLanguageSupported(fileInfo.fileLanguage.languageId)) {
192+
if (fileInfo.fileInWorkspace && isLanguageSupported(fileInfo.fileLanguage.languageId)) {
190193
// Send Capability card to chat
191194
codeTestChatHelper.addNewMessage(
192195
CodeTestChatMessageContent(informationCard = true, message = null, type = ChatMessageType.Answer, canBeVoted = false),
@@ -232,9 +235,15 @@ class CodeTestChatController(
232235
}
233236
.build()
234237

235-
val messageContent = "<span style=\"color: #EE9D28;\">&#9888;<b> ${fileInfo.fileLanguage.languageId} is not a " +
236-
"language I support specialized unit test generation for at the moment.</b><br></span>The languages " +
237-
"I support now are Python and Java. I can still provide examples, instructions and code suggestions."
238+
val messageContent = if (fileInfo.fileInWorkspace) {
239+
"<span style=\"color: #EE9D28;\">&#9888;<b> ${fileInfo.fileLanguage.languageId} is not a " +
240+
"language I support specialized unit test generation for at the moment.</b><br></span>The languages " +
241+
"I support now are Python and Java. I can still provide examples, instructions and code suggestions."
242+
} else {
243+
"<span style=\"color: #EE9D28;\">&#9888;<b> I can't generate tests for ${fileInfo.fileName}" +
244+
" because it's outside the project directory.</b><br></span> " +
245+
"I can still provide examples, instructions and code suggestions."
246+
}
238247

239248
codeTestChatHelper.addNewMessage(
240249
CodeTestChatMessageContent(
@@ -289,7 +298,8 @@ class CodeTestChatController(
289298
AmazonqTelemetry.utgGenerateTests(
290299
cwsprChatProgrammingLanguage = session.programmingLanguage.languageId,
291300
hasUserPromptSupplied = session.hasUserPromptSupplied,
292-
isSupportedLanguage = false,
301+
isFileInWorkspace = fileInfo.fileInWorkspace,
302+
isSupportedLanguage = isLanguageSupported(fileInfo.fileLanguage.languageId),
293303
credentialStartUrl = getStartUrl(project),
294304
result = MetricResult.Succeeded,
295305
perfClientLatency = (Instant.now().toEpochMilli() - session.startTimeOfTestGeneration),
@@ -573,6 +583,7 @@ class CodeTestChatController(
573583
session.testGenerationJob,
574584
session.testGenerationJobGroupName,
575585
session.programmingLanguage,
586+
IdeCategory.JETBRAINS,
576587
session.numberOfUnitTestCasesGenerated,
577588
session.numberOfUnitTestCasesGenerated,
578589
session.linesOfCodeGenerated,
@@ -590,6 +601,7 @@ class CodeTestChatController(
590601
AmazonqTelemetry.utgGenerateTests(
591602
cwsprChatProgrammingLanguage = session.programmingLanguage.languageId,
592603
hasUserPromptSupplied = session.hasUserPromptSupplied,
604+
isFileInWorkspace = true,
593605
isSupportedLanguage = true,
594606
credentialStartUrl = getStartUrl(project = context.project),
595607
jobGroup = session.testGenerationJobGroupName,
@@ -768,6 +780,7 @@ class CodeTestChatController(
768780
session.testGenerationJob,
769781
session.testGenerationJobGroupName,
770782
session.programmingLanguage,
783+
IdeCategory.JETBRAINS,
771784
session.numberOfUnitTestCasesGenerated,
772785
0,
773786
session.linesOfCodeGenerated,
@@ -784,6 +797,7 @@ class CodeTestChatController(
784797
AmazonqTelemetry.utgGenerateTests(
785798
cwsprChatProgrammingLanguage = session.programmingLanguage.languageId,
786799
hasUserPromptSupplied = session.hasUserPromptSupplied,
800+
isFileInWorkspace = true,
787801
isSupportedLanguage = true,
788802
credentialStartUrl = getStartUrl(project = context.project),
789803
jobGroup = session.testGenerationJobGroupName,
@@ -1113,6 +1127,7 @@ class CodeTestChatController(
11131127
val filePath: String,
11141128
val fileName: String,
11151129
val fileLanguage: CodeWhispererProgrammingLanguage,
1130+
val fileInWorkspace: Boolean = true,
11161131
)
11171132

11181133
private suspend fun updateUIState() {
@@ -1144,6 +1159,9 @@ class CodeTestChatController(
11441159
val fileEditorManager = FileEditorManager.getInstance(project)
11451160
val activeEditor = fileEditorManager.selectedEditor
11461161
val activeFile = fileEditorManager.selectedFiles.firstOrNull()
1162+
val projectRoot = project.basePath?.let { Path.of(it) }?.toFile()?.toVirtualFile() ?: run {
1163+
project.guessProjectDir() ?: error("Cannot guess base directory for project ${project.name}")
1164+
}
11471165

11481166
if (activeEditor == null || activeFile == null) {
11491167
handleInvalidFileState(message.tabId)
@@ -1158,6 +1176,7 @@ class CodeTestChatController(
11581176
filePath = activeFile.path,
11591177
fileName = activeFile.name,
11601178
fileLanguage = programmingLanguage,
1179+
fileInWorkspace = activeFile.path.startsWith(projectRoot.path)
11611180
)
11621181
} catch (e: Exception) {
11631182
LOG.debug { "Error checking active file: $e" }
@@ -1171,6 +1190,8 @@ class CodeTestChatController(
11711190
}
11721191
}
11731192

1193+
private fun File.toVirtualFile() = LocalFileSystem.getInstance().findFileByIoFile(this)
1194+
11741195
/* UTG Tab Chat input use cases:
11751196
* 1. If User exits the flow and want to start a new generate unit test cycle.
11761197
* 2. If User clicks on Modify build command option and can enter the build command from chat input

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/credentials/CodeWhispererClientAdaptor.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import software.amazon.awssdk.services.codewhispererruntime.model.GenerateComple
2727
import software.amazon.awssdk.services.codewhispererruntime.model.GetCodeFixJobRequest
2828
import software.amazon.awssdk.services.codewhispererruntime.model.GetCodeFixJobResponse
2929
import software.amazon.awssdk.services.codewhispererruntime.model.GetTestGenerationResponse
30+
import software.amazon.awssdk.services.codewhispererruntime.model.IdeCategory
3031
import software.amazon.awssdk.services.codewhispererruntime.model.InlineChatUserDecision
3132
import software.amazon.awssdk.services.codewhispererruntime.model.ListAvailableCustomizationsRequest
3233
import software.amazon.awssdk.services.codewhispererruntime.model.ListFeatureEvaluationsResponse
@@ -201,6 +202,7 @@ interface CodeWhispererClientAdaptor : Disposable {
201202
jobId: String,
202203
groupName: String,
203204
language: CodeWhispererProgrammingLanguage?,
205+
ideCategory: IdeCategory?,
204206
numberOfUnitTestCasesGenerated: Int?,
205207
numberOfUnitTestCasesAccepted: Int?,
206208
linesOfCodeGenerated: Int?,
@@ -674,6 +676,7 @@ open class CodeWhispererClientAdaptorImpl(override val project: Project) : CodeW
674676
jobId: String,
675677
groupName: String,
676678
language: CodeWhispererProgrammingLanguage?,
679+
ideCategory: IdeCategory?,
677680
numberOfUnitTestCasesGenerated: Int?,
678681
numberOfUnitTestCasesAccepted: Int?,
679682
linesOfCodeGenerated: Int?,
@@ -688,6 +691,7 @@ open class CodeWhispererClientAdaptorImpl(override val project: Project) : CodeW
688691
}
689692
it.jobId(jobId)
690693
it.groupName(groupName)
694+
it.ideCategory(ideCategory)
691695
it.numberOfUnitTestCasesGenerated(numberOfUnitTestCasesGenerated)
692696
it.numberOfUnitTestCasesAccepted(numberOfUnitTestCasesAccepted)
693697
it.linesOfCodeGenerated(linesOfCodeGenerated)

plugins/core/jetbrains-community/resources/telemetryOverride.json

Lines changed: 0 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
11
{
22
"types": [
3-
{
4-
"name": "acceptedCharactersCount",
5-
"type": "int",
6-
"description": "The number of accepted characters"
7-
},
8-
{
9-
"name": "acceptedCount",
10-
"type": "int",
11-
"description": "The number of accepted cases"
12-
},
13-
{
14-
"name": "acceptedLinesCount",
15-
"type": "int",
16-
"description": "The number of accepted lines of code"
17-
},
183
{
194
"name": "amazonqIndexFileSizeInMB",
205
"type": "int",
@@ -40,16 +25,6 @@
4025
"type": "string",
4126
"description": "Source triggering token refresh"
4227
},
43-
{
44-
"name": "buildPayloadBytes",
45-
"type": "int",
46-
"description": "The uncompressed payload size in bytes of the source files in customer project context"
47-
},
48-
{
49-
"name": "buildZipFileBytes",
50-
"type": "int",
51-
"description": "The compressed payload size of source files in bytes of customer project context sent"
52-
},
5328
{
5429
"name": "component",
5530
"allowedValues": [
@@ -190,46 +165,6 @@
190165
"type": "int",
191166
"description": "The number of executed operations"
192167
},
193-
{
194-
"name": "generatedCharactersCount",
195-
"type": "int",
196-
"description": "Number of characters of code generated"
197-
},
198-
{
199-
"name": "generatedCount",
200-
"type": "int",
201-
"description": "The number of generated cases"
202-
},
203-
{
204-
"name": "generatedLinesCount",
205-
"type": "int",
206-
"description": "The number of generated lines of code"
207-
},
208-
{
209-
"name": "hasUserPromptSupplied",
210-
"type": "boolean",
211-
"description": "True if user supplied prompt message as input else false"
212-
},
213-
{
214-
"name": "isCodeBlockSelected",
215-
"type": "boolean",
216-
"description": "True if user selected code snippet as input else false"
217-
},
218-
{
219-
"name": "isSupportedLanguage",
220-
"type": "boolean",
221-
"description": "Indicate if the language is supported"
222-
},
223-
{
224-
"name": "jobGroup",
225-
"type": "string",
226-
"description": "Job group name used in the operation"
227-
},
228-
{
229-
"name": "jobId",
230-
"type": "string",
231-
"description": "Job id used in the operation"
232-
},
233168
{
234169
"name": "reAuth",
235170
"type": "boolean",
@@ -519,92 +454,6 @@
519454
}
520455
]
521456
},
522-
{
523-
"name": "amazonq_utgGenerateTests",
524-
"description": "Client side invocation of the AmazonQ Unit Test Generation",
525-
"metadata": [
526-
{
527-
"type": "acceptedCharactersCount",
528-
"required": false
529-
},
530-
{
531-
"type": "acceptedCount",
532-
"required": false
533-
},
534-
{
535-
"type": "acceptedLinesCount",
536-
"required": false
537-
},
538-
{
539-
"type": "artifactsUploadDuration",
540-
"required": false
541-
},
542-
{
543-
"type": "buildPayloadBytes",
544-
"required": false
545-
},
546-
{
547-
"type": "buildZipFileBytes",
548-
"required": false
549-
},
550-
{
551-
"type": "credentialStartUrl",
552-
"required": false
553-
},
554-
{
555-
"type": "cwsprChatProgrammingLanguage"
556-
},
557-
{
558-
"type": "generatedCharactersCount",
559-
"required": false
560-
},
561-
{
562-
"type": "generatedCount",
563-
"required": false
564-
},
565-
{
566-
"type": "generatedLinesCount",
567-
"required": false
568-
},
569-
{
570-
"type": "hasUserPromptSupplied"
571-
},
572-
{
573-
"type": "isCodeBlockSelected",
574-
"required": false
575-
},
576-
{
577-
"type": "isSupportedLanguage"
578-
},
579-
{
580-
"type": "jobGroup",
581-
"required": false
582-
},
583-
{
584-
"type": "jobId",
585-
"required": false
586-
},
587-
{
588-
"type": "perfClientLatency",
589-
"required": false
590-
},
591-
{
592-
"type": "result"
593-
},
594-
{
595-
"type": "reason",
596-
"required": false
597-
},
598-
{
599-
"type": "reasonDesc",
600-
"required": false
601-
},
602-
{
603-
"type": "source",
604-
"required": false
605-
}
606-
]
607-
},
608457
{
609458
"name": "auth_modifyConnection",
610459
"description": "An auth connection was modified in some way, e.g. deleted, updated",

0 commit comments

Comments
 (0)